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

# 错误处理

> APIAny.AI 标准错误分类。

每个对话接口都返回与其兼容的 **API 标准（OpenAI / Anthropic / Gemini）一致的错误结构**。
所有错误响应都带 `X-Request-Id` 响应头，只返回你排查请求所需的信息。

## OpenAI — `/v1/chat/completions`（以及图片/视频接口）

```json theme={null}
{
  "error": {
    "message": "Insufficient credits",
    "type": "insufficient_quota",
    "code": "insufficient_credits",
    "param": null
  }
}
```

## Anthropic — `/v1/messages`

```json theme={null}
{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Invalid API key"
  }
}
```

## Gemini — `/v1beta/models/{model}:generateContent`

```json theme={null}
{
  "error": {
    "code": 400,
    "message": "model is required",
    "status": "INVALID_ARGUMENT"
  }
}
```

## 状态码映射

错误的 `type` / `status` 由 HTTP 状态码推导：

| HTTP | OpenAI `type`           | Anthropic `type`               | Gemini `status`             |
| ---- | ----------------------- | ------------------------------ | --------------------------- |
| 400  | invalid\_request\_error | invalid\_request\_error        | INVALID\_ARGUMENT           |
| 401  | authentication\_error   | authentication\_error          | UNAUTHENTICATED             |
| 403  | permission\_error       | permission\_error              | PERMISSION\_DENIED          |
| 404  | not\_found\_error       | not\_found\_error              | NOT\_FOUND                  |
| 402  | insufficient\_quota     | invalid\_request\_error        | RESOURCE\_EXHAUSTED         |
| 429  | rate\_limit\_error      | rate\_limit\_error             | RESOURCE\_EXHAUSTED         |
| 5xx  | api\_error              | api\_error / overloaded\_error | SERVER\_ERROR / UNAVAILABLE |
