Docs

Model APIs

Errors, 429 responses and retry policy

Distinguish credential, validation, model, rate-limit and upstream errors, with bounded retries and request ids.

Updated

Diagnose by HTTP status

StatusMeaning and action
400Invalid JSON, messages or model parameters; correct the request
401Missing, invalid or wrong credential type; verify the API key
402Billing or budget refusal; check wallet and limits
403Scope, group or access policy denial; check the current key
404Unavailable endpoint, model or resource; verify path and id
413Payload too large; reduce file, image or context size
429Gateway or provider rate limiting; inspect error and Retry-After
500 / 502 / 503 / 504Service, upstream or timeout failure; record request id and retry within bounds

Keep the body and request id

Gateway errors use {"error":{"type":"ferrogate_error","code":"...","message":"...","request_id":"..."}}. Provider names, URLs, native codes and messages are never returned. Keep code, HTTP status, x-request-id and Retry-After when present; branch on code.

Illustrative error (shape varies)
{"error":{"code":"invalid_request","message":"Request validation failed"}}

Where a 429 originates

A 429 means the request was rate limited. gateway_capacity_exceeded and gateway_provider_rate_limited distinguish the source; honor Retry-After or retry-after-ms for either.

Use Retry-After or retry-after-ms when supplied and correlate the error code with usage history. Reduce concurrency, bound output and stagger loops. For persistent failures, report time, model, task id and request id.

Complete error code reference

These are the stable public gateway codes. Any provider_*, upstream_* or native provider error is converted to a gateway_* code; internal diagnostics stay in server evidence.

CodeHTTPScenario and action
gateway_provider_circuit_open503Circuit open; retry later
gateway_provider_unavailable502/503Unavailable; bounded retry
gateway_provider_timeout504Timeout; backoff and retry
gateway_provider_unreachable502Connection or transport failure; bounded retry
gateway_provider_authentication_failed502Provider credential failure; contact admin
gateway_provider_rate_limited429Provider rate limit; honor Retry-After
gateway_provider_request_rejected502Provider refusal; correct parameters
gateway_provider_invalid_response502Invalid response; report request_id
gateway_provider_protocol_error502Protocol mismatch; contact admin
gateway_provider_response_too_large502Response too large; reduce output
gateway_provider_stream_interrupted502 或流中 200Stream incomplete; mark incomplete before retry
gateway_provider_configuration_error502Gateway configuration missing; contact admin
gateway_capacity_exceeded429Gateway capacity; reduce concurrency
gateway_timeout504Gateway timeout; backoff and retry
gateway_request_rejected400Gateway validation; correct request
gateway_internal_error500Unexpected failure; report request_id

Billing behavior for every error

The gateway charges only tokens it observes and writes to the usage ledger. “Gateway charge” means the Token4AI wallet; a provider may charge after a disconnect, which the gateway cannot guarantee. Observed partial output is charged.

CategoryGateway chargeRule
Request validation/auth/model/policy/quota否No provider call before refusal
gateway_capacity_exceeded, gateway_timeout before dispatch否No provider call
gateway_provider_circuit_open否Circuit short-circuits before dispatch
Provider auth/rate-limit/refusal/invalid/protocol/oversize否(无 usage)No settled tokens from error response
Unreachable or timeout否(无 usage)Partial stream: charge observed tokens
gateway_provider_stream_interrupted按已观测 tokenZero without usage; charge observed usage/output
Successful 2xx按实际 usageProvider usage or permitted local estimate

Bounded retries

  • Retry only recoverable rate-limit, timeout or transient service failures; 400/401/403 usually require configuration changes.
  • Respect server retry hints, use exponential backoff with jitter, and set both an attempt limit and an overall deadline.
  • Choose one layer, such as the SDK or task runner, to own retries rather than multiplying them across layers.
  • After partial output or a write tool call, retries can duplicate side effects and incur additional usage.

Related guides