Documentation · API errors · updated 15 November 2026

Error codes: diagnosis and retry strategy

The API returns OpenAI-format errors. The HTTP status tells who should act: the client (4xx except 429), the rate limit (429) or the service (5xx). Full table, useful headers and when to retry.

Error response format

One format, whatever the endpoint.

{
  "error": {
    "message": "Credits exhausted. Top up your account on /portal.",
    "type": "insufficient_quota",
    "code": "insufficient_credits",
    "param": null
  }
}

code is stable and meant for client code; message is readable but may change. The x-ef-request-id header lets support find the request.

Code table

CodeHTTPMeaningAction
missing_api_key / invalid_api_key401Missing or unknown keyCheck the Authorization header
key_disabled403Revoked keyCreate a new key
insufficient_credits402Balance exhaustedTop up before retrying
model_not_found404Model not in the served catalogueList models with /v1/models
illegal_content400Prohibited content (legal lock)Do not retry
rate_limit_exceeded429RPM or TPM exceededWait for Retry-After, then retry
upstream_unavailable503Backend unavailable or startingRetry with backoff
upstream_stream_error200 (SSE)Stream interrupted on the backendDetect the error event and restart
bad_upstream_response502Unreadable backend responseRetry once, then contact support

Retry or fix?

Simple rule: 4xx = your code, 429/5xx = timing.

Retry strategy

The only retry pattern that does not double the bill.

Requests rejected before generation (401, 402, 404, 429) cost nothing. A blind retry of a generation that already started can double the cost: only retry on statuses where no generation began.

import random, time
import httpx

RETRY_STATUS = {429, 502, 503}

def post_with_retry(url, payload, headers, attempts=4):
    for attempt in range(attempts):
        resp = httpx.post(url, json=payload, headers=headers, timeout=120)
        if resp.status_code not in RETRY_STATUS:
            return resp
        retry_after = resp.headers.get("Retry-After")
        delay = int(retry_after) if retry_after and retry_after.isdigit() \
            else min(60, 2 ** attempt) + random.random()
        time.sleep(delay)
    return resp

This stops after four attempts and returns the last response: a persistent 429 is an alarm signal (quota, sizing), not something to loop on forever.

Useful headers

HeaderContent
x-ef-request-idRequest identifier, quote it to support
x-ratelimit-remaining-requestsRequests left in the current window
x-ratelimit-remaining-tokensTokens left in the current window
Retry-AfterMinimum delay in seconds (429, 503)
x-ef-requested-model / x-ef-served-byRequested model and actual fallback model
x-ef-cost-micro / x-ef-balance-microCost and balance after the request (not streaming)

Quick diagnosis

  1. 401: does the key start with sk-ef-? Is it sent as Authorization: Bearer?
  2. 402: is the balance positive? The portal and /v1/me give the exact amount.
  3. 404: is the model listed by /v1/models?
  4. 429: which limit header is at zero? Reduce concurrency or wait for the next window.
  5. 503: is the model starting cold? The status page and console logs show the state.

FAQ

Is a failed request billed?

A request rejected before generation (401, 402, 404, 429) is not billed. An interrupted stream is billed for the tokens actually produced.

Why a 200 status on a stream error?

HTTP headers are sent with the first token. An error after that point is delivered inside the SSE flow as an error event, which is standard SSE behaviour.

Need help with an error?

Open a ticket with the request's x-ef-request-id.

View status