Skip to content

PyAI reference / Errors

Error codes

Inference and data-plane errors use the OpenAI shape. Branch on the stable error.code - never on the human-readable message, which can change.
error envelope
{
  "error": {
    "message": "Rate limit exceeded. Retry after 30s.",
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded",
    "param": null
  }
}

Quick scan

codeHTTPMeaning
unauthorized401Missing or invalid API key.
forbidden403The key is valid but lacks the required scope.
origin_not_allowed403A publishable token was used from an origin that isn't allow-listed.
invalid_agent_id400session_label on an Omni URL is malformed (control characters or too long for a header value).
credit_exhausted402The org is out of prepaid credit.
key_budget_exceeded402The per-key monthly budget has been hit.
insufficient_quota402The plan quota is exhausted.
rate_limit_exceeded429The per-key or per-IP rate limit was exceeded.
concurrency_limit_exceeded429Too many concurrent realtime sessions.
daily_cap_exceeded429A sandbox or publishable-token daily cap was reached.

Every code

unauthorized

HTTP 401#unauthorized

Missing or invalid API key.

What to do: Stop and surface to the user - the key is missing or wrong.

forbidden

HTTP 403#forbidden

The key is valid but lacks the required scope.

What to do: Add the scope to the key in the console; don't retry.

origin_not_allowed

HTTP 403#origin_not_allowed

A publishable token was used from an origin that isn't allow-listed.

What to do: Add the origin to the allow-list; don't retry.

invalid_agent_id

HTTP 400#invalid_agent_id

session_label on an Omni URL is malformed (control characters or too long for a header value).

What to do: Fix the label; don't retry.

credit_exhausted

HTTP 402#credit_exhausted

The org is out of prepaid credit.

What to do: Add credit (or use a pyai_test_ key); don't retry.

key_budget_exceeded

HTTP 402#key_budget_exceeded

The per-key monthly budget has been hit.

What to do: Raise the key budget; don't retry.

insufficient_quota

HTTP 402#insufficient_quota

The plan quota is exhausted.

What to do: Upgrade the plan.

rate_limit_exceeded

HTTP 429#rate_limit_exceeded

The per-key or per-IP rate limit was exceeded.

What to do: Back off and honor the Retry-After header.

concurrency_limit_exceeded

HTTP 429#concurrency_limit_exceeded

Too many concurrent realtime sessions.

What to do: Wait and retry.

daily_cap_exceeded

HTTP 429#daily_cap_exceeded

A sandbox or publishable-token daily cap was reached.

What to do: Wait until the cap resets.

Console and management routes (under the dashboard origin) instead use RFC 7807 application/problem+json with a request_id - a different shape from the inference envelope above.

QUESTIONS, ANSWERED

A few useful answers.

How should I use the error-code table?

Use the documented stable code to select the appropriate handling path. The table explains what each code means and which action the application or operator should take.

Should I retry every failed request?

No. Follow the guidance for the specific error. Correct request, permission or account problems before retrying, and use the documented retry guidance for transient conditions.

Where is the complete API contract?

The canonical documentation and live OpenAPI specification describe endpoints, authentication and response contracts. This page provides searchable error-code details for integration work.

Handle errors once, ship with confidence.

Start free with $50 in free credits - stable codes mean your retry logic won't drift.