Errors and retries

Handle the stable error envelope, rate limits, and idempotent retries.

Most API errors use a consistent envelope:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "The request body is invalid."
  },
  "request_id": "req_example"
}

Log request_id with your own request trace. Do not expose credentials or complete request bodies in client-facing logs.

An application-instruction rejection returns 422 with a public review object instead of a request ID. Use its summary and findings to revise the proposed instructions.

Common status codes

StatusMeaningAction
400Invalid requestCorrect the request before retrying.
401Authentication failedReplace or rotate the key.
402A configured spend limit was reachedReview limits in the console.
404The resource is unavailable to this keyVerify the ID and project boundary.
409State or idempotency conflictReconcile the existing operation before retrying.
422Application instructions were rejectedRevise them before trying again.
429Rate limit exceededWait for Retry-After and use backoff with jitter.
503Retryable processing or provider availability issueFollow Retry-After; poll request status when a request ID is present.

Idempotency

For non-streaming message calls, send one stable idempotency_key per logical operation. If a timeout makes the outcome uncertain, retry with the same key instead of creating a second operation.