> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prismgateway.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Handle Prism API status codes and stable error fields

# Errors

Most API failures return an `error` object:

```json theme={null}
{
  "error": {
    "type": "invalid_request_error",
    "code": "model_not_in_key_scope",
    "message": "This model is not in the allowlist for this API key."
  }
}
```

Not every authentication failure includes `type` and `code`. Always branch on
the HTTP status first, then use `error.code` when present.

| Status | Meaning                                            | Client action                               |
| ------ | -------------------------------------------------- | ------------------------------------------- |
| `400`  | Invalid request body or parameter                  | Correct the request; do not retry unchanged |
| `401`  | Missing, invalid, or revoked API key               | Replace or correct the key                  |
| `402`  | Credits, reservation, or budget prevents admission | Follow `error.action` and `help_url`        |
| `403`  | Trial, scope, model, or organization policy denial | Choose an allowed model or contact an admin |
| `404`  | Resource or usage record is not visible            | Verify the ID and caller identity           |
| `429`  | Rate limit exceeded                                | Back off and retry                          |
| `5xx`  | Prism or an upstream service is unavailable        | Retry with exponential backoff and jitter   |

## Stable policy codes

* `trial_model_denied`
* `trial_scope_denied`
* `scope_denied`
* `model_not_in_key_scope`
* `model_disabled_for_org`
* `insufficient_credits`
* `reservation_failed`
* `budget_cap_exceeded`

## Retry guidance

Retry only idempotent reads and requests that your application can safely
deduplicate. Use exponential backoff with jitter for `429` and transient `5xx`
responses. Do not automatically retry `401`, `402`, or `403`.

Log the request ID and error code, but never log the API key, request
authorization header, or signed media URLs.

[อ่านภาษาไทย](/th/errors)
