> For the complete documentation index, see [llms.txt](https://docs.avis.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avis.xyz/api-reference/introduction/errors.md).

# Errors

### Status codes

| Status        | Meaning                                                                                                      |
| ------------- | ------------------------------------------------------------------------------------------------------------ |
| `400`         | Bad request — missing/invalid parameters, unsupported model, or the model has no pricing configured          |
| `401`         | Unauthorized — missing, invalid, or inactive API key (see Authentication)                                    |
| `403`         | Forbidden — credit balance is zero or negative                                                               |
| `404`         | Not found — e.g. polling a video job ID that doesn't exist                                                   |
| `429`         | Too many requests — the API key's owner-configured spend limit (daily/weekly/monthly/total) has been reached |
| `500`         | Internal server error on the Avis side                                                                       |
| `502` / `503` | The upstream model provider errored or is unavailable                                                        |

### Two response shapes

Errors come from one of two places, and they are **not** shaped the same way — this matters when you write error-handling code.

#### 1. Errors raised before the upstream call

Auth failures, an unsupported/unpriced model, and insufficient balance are all rejected by Avis itself, before any request reaches the model provider. These always come back in one shape, the same across all three surfaces:

```json
{
  "errors": ["Insufficient credit balance"],
  "status": 403,
  "success": false,
  "path": "/api/openai/v1/chat/completions",
  "timestamp": 1751270603123
}
```

`errors` is always an array (even for a single message). This is the generic error envelope used app-wide, not an OpenAI/Anthropic/Gemini-specific format.

#### 2. Errors returned by the model provider

Once a request passes auth/balance checks and is sent upstream, any error the provider itself returns (invalid parameter value, provider-side outage, content policy rejection, etc.) is passed back to you **unmodified**, with that provider's native status code and error shape — because at that point Avis is just proxying the response through.

**OpenAI surface:**

```json
{
  "error": {
    "message": "The model 'openai/does-not-exist' does not exist",
    "type": "invalid_request_error",
    "code": "model_not_found"
  }
}
```

**Anthropic surface:**

```json
{
  "type": "error",
  "error": { "type": "invalid_request_error", "message": "max_tokens: field required" }
}
```

**Gemini surface:**

```json
{
  "error": { "code": 400, "message": "Invalid value at 'generation_config'", "status": "INVALID_ARGUMENT" }
}
```

Since this second category is whatever the underlying provider returns, treat the exact `type`/`code` enum values as that provider's, not a fixed Avis-defined list.

### Errors while streaming

**OpenAI `chat/completions`** streams an in-band error event if the generation fails partway through, instead of a normal HTTP error (since the `200` + SSE headers were already sent):

```
data: {"error":"upstream request failed"}
```

No `data: [DONE]` follows an in-band error event.

**Anthropic, Gemini, and `/responses`** streams are raw-piped from the upstream provider — if the provider's own stream carries an error event, it arrives in that provider's native format; if the upstream connection drops unexpectedly, the client simply sees the stream end.

### Triggering examples

| To see...                 | Do this                                                                                        |
| ------------------------- | ---------------------------------------------------------------------------------------------- |
| `401`                     | Omit the `x-api-key` header, or send a revoked key                                             |
| `403`                     | Call any generation endpoint with a zero/negative credit balance                               |
| `400` (unsupported model) | Send a `model` value that isn't in the Avis catalog                                            |
| `429`                     | Configure a low spend limit on your key (`PATCH /api-keys/:keyId/usage-limit`), then exceed it |
| `404`                     | `GET /api/openai/v1/videos/:id` with a made-up job ID                                          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.avis.xyz/api-reference/introduction/errors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
