錯誤使用 Anthropic 的錯誤信封:
  • error.type 決定 HTTP 狀態;一般情況按它分支。
  • error.code 是穩定的、機器可讀的原因;需要區分具體原因時按它分支。下表會持續增加:遇到不認識的錯誤碼,按其 type 的通用方式處理。
  • error.message 面向人,不要解析。
  • 聯絡支援時請附上 request_id。
  • 只有重試同一請求可能成功時(例如 Idempotency-Key 仍在處理中),409 才帶 x-should-retry: true。
標為 retry 的行表示同一請求稍後無需修改就可能成功,請指數退避重試;未標註的行在你修改請求或狀態之前會再次失敗。

invalid_request_error (HTTP 400)

請求格式錯誤或不可接受。 處理方式(除非該行另有說明): Correct the request as the message describes and send it again; the same request will keep failing.

authentication_error (HTTP 401)

憑據缺失、錯誤或已過期。 處理方式(除非該行另有說明): Send a valid credential (API key, access token or console session) and retry.

permission_error (HTTP 403)

憑據有效,但無權執行此操作。 處理方式(除非該行另有說明): Use a credential with the required role or access; retrying with the same credential will not help.

not_found_error (HTTP 404)

目標資源不存在(或對呼叫方不可見)。 處理方式(除非該行另有說明): Check the ID and the organization or workspace it belongs to; do not retry the same request.

conflict_error (HTTP 409)

請求與資源的當前狀態衝突。 處理方式(除非該行另有說明): Re-read the resource, resolve the conflicting state, then send the request again.

request_too_large (HTTP 413)

請求超過大小限制。 處理方式(除非該行另有說明): Delete older machine backups or raise the limit, then retry.

rate_limit_error (HTTP 429)

請求或嘗試次數過多。 處理方式(除非該行另有說明): Wait for the Retry-After interval (or back off exponentially) and retry.

api_error (HTTP 500)

平臺側錯誤。 處理方式(除非該行另有說明): Retry with exponential backoff; the dependency is temporarily unavailable.

timeout_error (HTTP 504)

上游或機器未在時限內響應。 處理方式(除非該行另有說明): Retry with exponential backoff; the operation may have continued, so read the resource first.

overloaded_error (HTTP 529)

平臺或其依賴暫時過載。 處理方式(除非該行另有說明): Retry with exponential backoff.