The first wall you hit when building a real service on the Claude API is error handling and rate limits. The first call is easy, but as traffic grows you need code that reliably handles responses like 429 (rate limit) and 529 (overloaded). This article summarizes the official error code system and retry strategy.
HTTP error codes at a glance
The Claude API follows a predictable HTTP error format. The body is always JSON, with a top-level error object holding type and message, plus a request_id for tracking. The main codes per the official docs:
400 invalid_request_error— problem with request format/content (also used for other unlisted 4XX).401 authentication_error— issue with your API key.402 billing_error— billing/payment issue. Check payment details in the Console.403 permission_error— key lacks permission for the resource.404 not_found_error— requested resource not found.413 request_too_large— request exceeds max bytes (on the direct API, returned by Cloudflare before reaching API servers).429 rate_limit_error— account hit a rate limit.500 api_error— unexpected error internal to Anthropic.504 timeout_error— timed out while processing; use streaming for long requests.529 overloaded_error— API temporarily overloaded.
Errors to retry vs. errors to fix
The key is distinguishing which errors to retry and which not to.
- Retry recommended:
429,500,504,529— transient or server-side. Retrying with backoff can succeed. - Pointless to retry (fix code/config):
400,401,402,403,404,413— repeating the same request yields the same error. Fix the request, key, permission, billing, or size.
Notably, 529 overloaded_error can occur during high traffic across all users, and a sharp spike in your org's usage can trigger 429 due to acceleration limits. The official docs advise ramping traffic gradually and keeping consistent usage patterns.
Exponential backoff + jitter
The standard pattern for retryable errors is exponential backoff with jitter.
- Prefer the retry-after header: a
429response includes aretry-afterheader telling you how long to wait. When present, waiting that long is most accurate. - No header → exponential growth: increase the wait like 1s → 2s → 4s → 8s.
- Add jitter: if many clients retry at identical intervals, load spikes. Add random delay (jitter) to spread it out.
- Cap retries: avoid infinite retries; set an upper bound (e.g., 5).
Note that the official Anthropic SDKs (Python, TypeScript, etc.) include built-in automatic retry logic for some errors by default. Check the SDK's default behavior before rolling your own to avoid duplicate work.
SDKs use typed exceptions
Official SDKs throw typed exceptions instead of raw JSON. For example, a 404 surfaces as anthropic.NotFoundError in Python, with different class names per language (TypeScript, Go, Java, etc.). The docs advise catching the SDK's typed classes rather than string-matching messages, handling the most specific classes first.
Request size limits (preventing 413)
To avoid 413 request_too_large, know the per-endpoint max request size. Per the official docs:
- Messages API — 32 MB
- Token Counting API — 32 MB
- Batch API — 256 MB
- Files API — 500 MB
Long requests → streaming/batch
Dragging out a non-streaming request with a large max_tokens can cause timeouts as some networks drop idle connections. The docs recommend the streaming Messages API or Message Batches API for long requests that may exceed 10 minutes. The SDKs validate non-streaming requests against a 10-minute timeout and set a TCP keep-alive socket option.
Summary
Reliable Claude API integration comes down to (1) classifying errors as retryable/not, (2) retry-after first + exponential backoff & jitter for 429/5xx, (3) fixing code/config for 4xx, (4) using SDK typed exceptions, and (5) streaming/batch for large requests. To learn more, see Getting Started with the Claude API and Getting Started with the Claude SDK.
This article is based on public information from the official Anthropic documentation (platform.claude.com/docs). API policies, limits, and error codes may change, so verify against the official docs when implementing. This site is not an official Anthropic site.