# 錯誤碼

所有錯誤都回傳 `{ "error": { "code", "message" } }`。請以 `code` 做程式化判斷；`message` 僅供顯示。

| HTTP | `code`                | 意義             | 可重試                 |
| ---- | --------------------- | -------------- | ------------------- |
| 400  | `bad_request`         | 參數或格式錯誤        | 否（先修正）              |
| 401  | `unauthorized`        | 缺少或無效的 API key | 否（先修正）              |
| 402  | `insufficient_credit` | credit 餘額不足    | 加值後可                |
| 403  | `forbidden`           | 無權限（如 key 已停用） | 否                   |
| 404  | `not_found`           | 資源不存在          | 否                   |
| 429  | `rate_limited`        | 觸發限流           | 是，依 `Retry-After`   |
| 500  | `internal_error`      | 內部錯誤           | 是，附 `request_id` 回報 |
| 502  | `upstream_error`      | 後端服務異常         | 是，退避重試              |
| 503  | `service_unavailable` | 暫時無法處理（如佇列已滿）  | 是，退避重試              |

## 附帶 header

| 錯誤                 | header        | 意義      |
| ------------------ | ------------- | ------- |
| `429 rate_limited` | `Retry-After` | 建議幾秒後重試 |

## 範例

```json
{
  "error": {
    "code": "rate_limited",
    "message": "rate limited, retry after 3s"
  }
}
```

延伸閱讀：[錯誤處理](/documentation/he-xin-gai-nian/errors.md)。


---

# Agent Instructions: 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:

```
GET https://docs.blockchainsecurity.asia/documentation/api-can-kao/error-codes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
