Error Handling - MyTokenGate
1. Read Two Things
An error response carries both an HTTP status and a business error code. The code is what actually explains the failure.
HTTP/1.1 403 Forbidden
{
"error": {
"message": "This API key is not allowed to use model gpt-6-astra",
"type": "invalid_request_error",
"code": "model_not_allowed"
}
}Branch on error.code in your program — it is stable. Show error.message to humans, since its wording may change between releases. Log both.
2. HTTP Status Codes
| Status | Meaning | Usual cause |
|---|---|---|
400 | Bad request | Missing or mistyped fields, context too long, content not matching the chosen mode |
401 | Unauthenticated | No Authorization header, or the key is invalid, expired, or revoked |
403 | Forbidden | The key may not use this model, or the account is restricted |
402 | Insufficient balance | Prepaid balance cannot cover this request’s pre-authorisation |
404 | Not found | Wrong model ID, or the task ID does not exist or was deleted |
409 | Conflict | For example, deleting a video task that has not settled |
429 | Rate limited | RPM/TPM exceeded, or an account or per-model quota ran out |
500 | Internal error | The gateway itself failed. Retry once; contact us if it persists |
502 / 503 | Upstream failure | Supplier error, channel unavailable, model not configured. Retry later |
504 | Upstream timeout | The supplier was too slow. For text, use streaming ("stream": true) to avoid long-held connections |
3. Business Error Codes
Authentication
code | Meaning | Action |
|---|---|---|
missing_api_key | No key on the request | Add Authorization: Bearer <key> |
invalid_api_key | Key is invalid, expired, or revoked | Check it in the console and create a new one if needed |
Request Parameters
code | Meaning |
|---|---|
invalid_request_error | Generic parameter error; see message for detail |
missing_field / missing_input | A required field is absent |
invalid_content | Malformed content. For video this usually means a bad role combination, such as sending a first frame together with reference images |
context_length_exceeded | Input exceeds the model’s context window; trim it or pick a longer-context model |
Quota and Billing
code | Meaning |
|---|---|
insufficient_balance | Balance cannot cover the pre-authorisation |
rate_limit_exceeded | RPM/TPM limit hit |
account_quota_exceeded | Account-level quota exhausted |
model_quota_exceeded | This model’s own quota exhausted (per-model limits may differ) |
Model Permission
code | Meaning |
|---|---|
model_not_allowed | The account behind this key is not authorised for the model. An administrator has to grant it |
“Model does not exist” and “model not permitted” are different failures. The first is
404or400; the second is403withmodel_not_allowed.
Upstream and Conversion
code | Meaning | Retryable |
|---|---|---|
upstream_error | The supplier returned an error | Usually yes; switch models if it persists |
supplier_missing | The supplier channel for this model is gone | No; switch models |
not_configured | No usable channel configured for the model | No; contact an administrator |
conversion_failed | Protocol conversion failed (e.g. chat to Anthropic) | No |
bad_gateway | Link between gateway and supplier broke | Yes |
stream_error | A streamed response was interrupted | Yes |
Video Tasks
code / message | Meaning |
|---|---|
video_timeout | Still incomplete after 30 minutes; the task is failed and the pre-authorisation released |
TASK_NOT_SETTLED | The task has not settled and cannot be deleted yet |
Responses API
code | Meaning |
|---|---|
previous_response_not_supported | previous_response_id was sent. This service is stateless; send the full history in input |
4. Troubleshooting Steps
- Read
error.codeagainst the tables above.messageusually adds one concrete sentence - Rule out a wrong model ID by comparing with
GET /v1/models - Try another model. If that works, the problem is upstream or in that model’s configuration, not in your request
- Reproduce with curl, bypassing SDK wrapping. Plenty of issues come from fields an SDK adds silently
- Check your proxy. Local or corporate proxies sometimes rewrite headers
5. Reproduce with curl
curl https://gateway.mytokengate.com/v1/chat/completions \
-H "Authorization: Bearer $MYTOKENGATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro",
"messages": [{ "role": "user", "content": "Hello" }],
"max_tokens": 128
}' -i-i prints the response headers, including the status on the first line.
6. Still Stuck
Send us three things: the curl you used (key redacted), the full response body, and the time it happened. A traceId helps most — it appears in the response headers and identifies that exact call.
Last updated on