OhMyGPT

Errors

Status codes, error bodies, and what to do about each.

Every error message says what to do next, so you can show it to whoever can act on it and branch your code on the HTTP status. Every response, errors included, carries an X-Request-ID; include it when you contact support.

Status codes

StatuscodeWhat to do
400invalid_request, invalid_parameter, missing_required_parameter, unsupported_parameter, unsupported_content, unsupported_endpoint, context_length_exceeded, content_policy_violationFix or remove the parameter, content or endpoint the message names, then send again.
401invalid_api_key, api_key_expired, api_key_disabledUse a valid key from the API keys page.
402insufficient_credits, api_key_spend_limit_exceededTop up on the Billing page, or raise the key's spending limit.
403model_not_allowed, provider_not_allowed, permission_denied, account_suspendedChange the key setting the message names (allowed models, allowed providers, or admin key) on the API keys page, or contact support.
401, 402, 403provider_key_rejectedThe provider refused your own key. Fix the key in the provider's console.
404model_not_found, not_foundCopy the model ID from GET /v1/models, or check the ID or URL the message names.
408invalid_requestThe request body stopped arriving for 30 seconds before it was complete. Send again; the OpenAI and Anthropic SDKs retry this on their own.
409conflictThe previous response or the request with the same Idempotency-Key is still running. Wait for it to finish, then send again.
413request_too_largeSend a smaller request body.
415invalid_requestSend the body as JSON with Content-Type: application/json.
429rate_limit_exceededWait Retry-After seconds, then send again.
500, 502, 503, 504model_error, model_overloaded, model_unavailable, model_timeout, service_unavailable, internal_errorRetry with backoff, or switch to another model.

Parameter errors keep the model's own wording, so the message tells you the accepted range:

{
  "error": {
    "param": null,
    "code": "invalid_request",
    "message": "Invalid 'temperature': decimal above maximum value. Expected a value <= 2, but got 5 instead.",
    "type": "invalid_request_error"
  }
}

Wrong URL

A 404 that names your path, instead of a model, means the URL is wrong:

{
  "error": {
    "param": null,
    "code": "not_found",
    "message": "`/v1/v1/chat/completions` repeats `/v1`. Remove the trailing `/v1` from your base URL: the Anthropic SDK and Claude Code take the bare host, OpenAI SDKs take the host plus a single `/v1`.",
    "type": "not_found_error"
  }
}

The usual cause is the base URL. OpenAI SDKs take https://api.ohmygpt.com/v1; the Anthropic SDK, Claude Code and the Gemini SDK take https://api.ohmygpt.com and add /v1 themselves. See base URLs per SDK.

Error body

The body follows the protocol of the endpoint you called, so your SDK raises its usual exception types.

{
  "error": {
    "param": "model",
    "code": "model_not_found",
    "message": "The model `no/such-model` does not exist. List available models with `GET /v1/models`.",
    "type": "not_found_error"
  }
}

In the OpenAI shape, branch on code. The Anthropic shape carries the status category in error.type, and Gemini carries the code upper-cased in details[].reason.

With the OpenAI Python SDK:

import os

import openai
from openai import OpenAI

client = OpenAI(base_url="https://api.ohmygpt.com/v1", api_key=os.environ["OHMYGPT_API_KEY"])

try:
    completion = client.chat.completions.create(
        model="no/such-model",
        messages=[{"role": "user", "content": "Hi"}],
    )
except openai.RateLimitError as e:          # 429
    retry_after = int(e.response.headers.get("retry-after", "1"))
except openai.APIStatusError as e:          # any other non-2xx
    print(e.status_code, e.code, e.response.headers.get("x-request-id"))
404 model_not_found 01a19b5f-6ab6-7dc0-88ff-f5c95e0169e4

Errors during a stream

A stream that has started already has status 200. If generation stops partway, the stream ends with an error event in place of its normal final event. A request that fails after a keep-alive line but before any output ends the same way: the status is already 200, and the stream carries only the error event (on Responses, response.created and then response.failed), with the same error its HTTP response would have carried.

data: {"error":{"param":null,"code":"model_error","message":"The model `zhipu/glm-5.3-flash` stopped mid-response, so the output is incomplete. Try again.","type":"server_error"}}

On Chat Completions and Messages, the SDKs raise this while you iterate, but not as the status-specific exceptions above, because the status was 200:

  • OpenAI SDK: APIError without a status. Branch on e.code.
  • Anthropic SDK: in Python, APIStatusError with status_code 200; branch on e.body["error"]["type"]. In TypeScript, APIError without a status; branch on e.type.
try:
    for chunk in client.chat.completions.create(
        model="zhipu/glm-5.3-flash", messages=[{"role": "user", "content": "Hello"}], stream=True
    ):
        ...
except openai.APIStatusError as e:  # failed before the stream started
    print(e.status_code, e.code)
except openai.APIError as e:        # error event inside the stream
    print(e.code, e.message)

On Responses, the OpenAI SDK raises nothing: response.failed arrives as one more event, so check for it yourself.

for event in client.responses.create(model="zhipu/glm-5.3-flash", input="Hello", stream=True):
    if event.type == "response.failed":
        raise RuntimeError(event.response.error.message)

If you parse the stream yourself, treat a stream that ends without its final event (data: [DONE], message_stop or response.completed) as incomplete.

When to retry

OhMyGPT already sends the request to another provider when one fails before answering, so you don't need retry logic for that. In your code:

  • 400, 401, 402, 403, 404: change the request, key or balance first; sending it again unchanged gives the same answer. The exception is a 402 with a Retry-After header: the same request can succeed after you wait that many seconds.
  • 429: wait Retry-After seconds, then send again.
  • 500, 502, 503, 504: retry a few times with exponential backoff, waiting Retry-After seconds when the header is present. If the error continues, switch to another model.
  • An error event in a stream: the status is already 200 and there is no Retry-After header, so SDKs do not retry it for you. Retry with exponential backoff, unless the event's code (on Messages, error.type) points at the request, key or balance, as in the 400–404 cases above; fix that first.

Was this page helpful?

Still stuck? Live chat · [email protected] · Telegram group