Errors & retries

Every error code the API returns, what it means, and whether to retry.

On this page

Errors use the OpenAI error shape, so the OpenAI SDKs raise them as normal exceptions. Branch on error.code (and error.type), never on the message text.

402 Payment Required
{
  "error": {
    "message": "Insufficient balance. Top up to continue.",
    "type": "insufficient_quota",
    "code": "insufficient_credit",
    "param": null
  }
}

The message is in English by default. Send Accept-Language: id to receive it in Bahasa Indonesia. code and type are the same in every language.

Error codes

StatusCodeTypeMeaningWhat to do
400invalid_requestinvalid_request_errorThe body is not valid JSON or names no model.Fix the request. Don't retry.
400max_tokens_exceededinvalid_request_errormax_tokens or max_completion_tokens is above 384,000.Lower it. Don't retry.
400unsupported_contentinvalid_request_errorThe model does not accept this input or feature: an image sent to a model without vision, or reasoning (reasoning_effort, thinking), tools, or JSON output asked of a model without it.Check the model's capabilities in GET /v1/models, then remove the image or parameter or choose another model. Don't retry.
400unsupported_image_urlinvalid_request_errorAn image was sent as a URL instead of inline base64 data.Send it as a data URL (data:image/png;base64,...). Don't retry.
401invalid_api_keyinvalid_request_errorThe key is missing, malformed, revoked, or unknown.Check the header and the key. Don't retry.
402insufficient_creditinsufficient_quotaYour available balance is $0.00 or below, or what is left is held by your requests still running (the message says which).Top up, then retry. If your balance is held, retry once your running requests finish.
402key_budget_exceededinsufficient_quotaThe key has used its monthly budget. The message names the budget.Raise or clear the budget in the console, or wait for the next month (WIB).
403insufficient_scopeinsufficient_permissionsThe key lacks the chat:write scope.Use a key with the right scope. Don't retry.
404model_not_foundinvalid_request_errorThe model ID is not served.Use deepseek-v4.1-flash. Don't retry.
404not_foundinvalid_request_errorUnknown endpoint.Check the path; the base URL ends in /v1.
405method_not_allowedinvalid_request_errorWrong HTTP method for the endpoint.Use POST for chat completions, GET for models.
408request_timeoutinvalid_request_errorThe request body stopped arriving for 30 seconds, uploaded slower than 16 KB/s on average, or took longer than 2 minutes. Nothing was charged.Retry. If it repeats, check the connection.
413request_too_largeinvalid_request_errorThe body is over the 16 MB request size limit. Base64 images count toward it.Compact the conversation or send fewer images. Don't retry unchanged.
429rate_limit_exceededrate_limit_exceededMore than 300 requests in a minute on this key.Wait for Retry-After, then retry.
429concurrency_limit_exceededrate_limit_exceededMore than 16 requests in flight on this key.Wait for Retry-After or for a request to finish.
429ip_rate_limitedrate_limit_exceededToo many requests from one IP address.Wait for Retry-After, then retry.
500internal_errorapi_errorUnexpected server error.Retry with backoff.
502provider_unavailableapi_errorThe model provider failed after your request was sent, and the request could not be moved to another provider (for example, it reached its generation time limit).Retry with backoff.
503provider_unavailableapi_errorNo model provider can serve the request right now: every provider for the model failed or is temporarily unavailable. Retry-After is the seconds until a supplier is expected back, at most 60.Retry after Retry-After. You were not charged.
503provider_unavailableapi_errorThe model provider could not be reached before your request was sent. Retry-After is 1 second.Retry after Retry-After. You were not charged.
503billing_unavailableapi_errorBilling is temporarily unavailable; the request was not run.Retry with backoff. You were not charged.
503overloadedapi_errorToo many large requests (for example, image-heavy agent turns) are running at once. The request was not run.Retry after Retry-After. You were not charged.
503service_unavailableapi_errorThe service is temporarily unavailable.Retry with backoff.

Other errors returned by the model provider — for example a 400 for a parameter combination it does not support — are forwarded with the provider's own error body.

When to retry

Retry only 408, 429, 500, 502, and 503. Everything else needs a change to the request, the key, or your balance first.

  • 408: the upload did not finish. Retry it; if it keeps failing, the connection is too slow for the request's size.
  • 429: wait for the number of seconds in the Retry-After header before trying again.
  • 5xx: use exponential backoff with jitter, for example 1 s, 2 s, 4 s, and give up after a few attempts.
  • Each retry is a new request. It is held, metered, and billed on its own.

The official OpenAI SDKs already retry 408, 429, and 5xx responses a couple of times with backoff, and honour Retry-After. You can raise the limit:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.larasrouter.com/v1",
    api_key=os.environ["LARAS_API_KEY"],
    max_retries=4,
)

Handle errors by code

Python
import openai

try:
    response = client.chat.completions.create(
        model="deepseek-v4.1-flash",
        messages=[{"role": "user", "content": "Hello"}],
    )
except openai.APIStatusError as e:
    # The SDK exposes error.code from the response body as e.code.
    if e.code == "insufficient_credit":
        notify_owner("Laras Router balance is empty — top up to resume.")
    elif e.code == "key_budget_exceeded":
        notify_owner("This key reached its monthly budget.")
    else:
        raise

Failed requests and charges

  • A request rejected before it reaches the model — any 400, 401, 402, 403, 404, 408, 413, 429 from Laras Router — is never charged.
  • A request the model provider rejects with a 4xx is not charged; its hold is released.
  • A request that fails before any of the answer reaches you — a 5xx, a timeout, or a provider that cannot be reached — is not charged; its hold is released at once.
  • A stream interrupted after part of the answer reached you keeps its hold while we reconcile it. You may be charged for usage the provider reports for it; otherwise the hold is released without a charge.

Request ID

Responses to requests that reached billing carry an X-Laras-Request-ID header. It identifies the charge and the hold for that request. Include it when you contact support about a charge. Requests rejected before a hold is placed — for example a 401 — may not carry it.

Updated Nov 2026