The error taxonomy
The Anthropic API uses standard HTTP error codes with structured JSON bodies. 400 is your bug (bad request shape). 401/403 is auth. 429 is rate limit. 500/503 is the server side; retry. 529 is overloaded; retry with backoff. The SDK raises typed exceptions matching these so you do not parse the body manually.
Retries that are safe vs retries that double-bill you
Non-streaming POSTs are safe to retry on 429/5xx — the SDK does this automatically up to max_retries (default 2). Streaming requests are NOT safely retryable mid-stream — partial output is already consumed. For long, expensive completions, design for resume rather than retry.
Idempotency keys
The Messages API supports idempotency keys via the Idempotency-Key request header. If a network blip makes you unsure whether a call landed, retry with the same key — the API will return the original response instead of charging you twice. Use idempotency keys for any expensive call where retry semantics matter.