Skip to Content
WikiFAQError Handling

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

StatusMeaningUsual cause
400Bad requestMissing or mistyped fields, context too long, content not matching the chosen mode
401UnauthenticatedNo Authorization header, or the key is invalid, expired, or revoked
403ForbiddenThe key may not use this model, or the account is restricted
402Insufficient balancePrepaid balance cannot cover this request’s pre-authorisation
404Not foundWrong model ID, or the task ID does not exist or was deleted
409ConflictFor example, deleting a video task that has not settled
429Rate limitedRPM/TPM exceeded, or an account or per-model quota ran out
500Internal errorThe gateway itself failed. Retry once; contact us if it persists
502 / 503Upstream failureSupplier error, channel unavailable, model not configured. Retry later
504Upstream timeoutThe supplier was too slow. For text, use streaming ("stream": true) to avoid long-held connections

3. Business Error Codes

Authentication

codeMeaningAction
missing_api_keyNo key on the requestAdd Authorization: Bearer <key>
invalid_api_keyKey is invalid, expired, or revokedCheck it in the console and create a new one if needed

Request Parameters

codeMeaning
invalid_request_errorGeneric parameter error; see message for detail
missing_field / missing_inputA required field is absent
invalid_contentMalformed content. For video this usually means a bad role combination, such as sending a first frame together with reference images
context_length_exceededInput exceeds the model’s context window; trim it or pick a longer-context model

Quota and Billing

codeMeaning
insufficient_balanceBalance cannot cover the pre-authorisation
rate_limit_exceededRPM/TPM limit hit
account_quota_exceededAccount-level quota exhausted
model_quota_exceededThis model’s own quota exhausted (per-model limits may differ)

Model Permission

codeMeaning
model_not_allowedThe 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 404 or 400; the second is 403 with model_not_allowed.

Upstream and Conversion

codeMeaningRetryable
upstream_errorThe supplier returned an errorUsually yes; switch models if it persists
supplier_missingThe supplier channel for this model is goneNo; switch models
not_configuredNo usable channel configured for the modelNo; contact an administrator
conversion_failedProtocol conversion failed (e.g. chat to Anthropic)No
bad_gatewayLink between gateway and supplier brokeYes
stream_errorA streamed response was interruptedYes

Video Tasks

code / messageMeaning
video_timeoutStill incomplete after 30 minutes; the task is failed and the pre-authorisation released
TASK_NOT_SETTLEDThe task has not settled and cannot be deleted yet

Responses API

codeMeaning
previous_response_not_supportedprevious_response_id was sent. This service is stateless; send the full history in input

4. Troubleshooting Steps

  1. Read error.code against the tables above. message usually adds one concrete sentence
  2. Rule out a wrong model ID by comparing with GET /v1/models
  3. Try another model. If that works, the problem is upstream or in that model’s configuration, not in your request
  4. Reproduce with curl, bypassing SDK wrapping. Plenty of issues come from fields an SDK adds silently
  5. 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.

help@MyTokenGate.com

Last updated on