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
| Status | code | What to do |
|---|---|---|
| 400 | invalid_request, invalid_parameter, missing_required_parameter, unsupported_parameter, unsupported_content, unsupported_endpoint, context_length_exceeded, content_policy_violation | Fix or remove the parameter, content or endpoint the message names, then send again. |
| 401 | invalid_api_key, api_key_expired, api_key_disabled | Use a valid key from the API keys page. |
| 402 | insufficient_credits, api_key_spend_limit_exceeded | Top up on the Billing page, or raise the key's spending limit. |
| 403 | model_not_allowed, provider_not_allowed, permission_denied, account_suspended | Change the key setting the message names (allowed models, allowed providers, or admin key) on the API keys page, or contact support. |
| 401, 402, 403 | provider_key_rejected | The provider refused your own key. Fix the key in the provider's console. |
| 404 | model_not_found, not_found | Copy the model ID from GET /v1/models, or check the ID or URL the message names. |
| 408 | invalid_request | The request body stopped arriving for 30 seconds before it was complete. Send again; the OpenAI and Anthropic SDKs retry this on their own. |
| 409 | conflict | The previous response or the request with the same Idempotency-Key is still running. Wait for it to finish, then send again. |
| 413 | request_too_large | Send a smaller request body. |
| 415 | invalid_request | Send the body as JSON with Content-Type: application/json. |
| 429 | rate_limit_exceeded | Wait Retry-After seconds, then send again. |
| 500, 502, 503, 504 | model_error, model_overloaded, model_unavailable, model_timeout, service_unavailable, internal_error | Retry 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-f5c95e0169e4Errors 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:
APIErrorwithout a status. Branch one.code. - Anthropic SDK: in Python,
APIStatusErrorwithstatus_code200; branch one.body["error"]["type"]. In TypeScript,APIErrorwithout a status; branch one.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-Afterheader: the same request can succeed after you wait that many seconds. - 429: wait
Retry-Afterseconds, then send again. - 500, 502, 503, 504: retry a few times with exponential backoff, waiting
Retry-Afterseconds 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-Afterheader, so SDKs do not retry it for you. Retry with exponential backoff, unless the event'scode(on Messages,error.type) points at the request, key or balance, as in the 400–404 cases above; fix that first.
Still stuck? Live chat · [email protected] · Telegram group