错误使用 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.