Follow Discord
Sweep 24 Nov 2026 · 22:58Z Build v2.1.332 549 read Stable v2.1.326 Latest v2.1.332 Next v2.1.332 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

errors changedapi/errors

Nearest release: v2.1.332, published 6 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+249added
Lines−8removed
From line 4 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits43to this page, all time

### Retries ### Error codes

The whole hunk

from line 4, old and new numbered
/
lines
from line 4
44description: Understand the HTTP status codes, error response shape, and request IDs the Claude API returns, and handle errors with the SDK's typed exceptions.
55---
66 
7To find the SDK error that an API error becomes, see [SDK error types](https://platform.claude.com/docs/en/api/errors#sdk-error-types). To catch it in your code, see [Handle errors](https://platform.claude.com/docs/en/api/handle-errors).
8 
79## HTTP errors
810 
911The API follows a predictable HTTP error code format:
from line 36
3436 
3537* 429 - `rate_limit_error`: Your organization has hit a [rate limit](https://platform.claude.com/docs/en/api/rate-limits), reached its usage tier’s monthly spend cap, or reached a spend limit on the Claude Code workspace. A tier spend-cap 429 has no `retry-after` header and keeps failing until access resumes; see [Reaching your spend cap](https://platform.claude.com/docs/en/api/rate-limits#reaching-your-spend-cap) for how to recognize it. A sharp increase in usage can also cause a 429 even while you’re under your rate limits; see [Ramp limits](https://platform.claude.com/docs/en/api/rate-limits#ramp-limits).
3638 
37* 500 - `api_error`: An unexpected error has occurred internal to Anthropic’s systems. Retry the request with exponential backoff; if the error persists, contact support with the [request ID](https://platform.claude.com/docs/en/api/errors#request-id). If the error type is `timeout_error` instead, see the 504 entry.
39 To tell the spend cap from a rate limit in code, check the [error code](https://platform.claude.com/docs/en/api/errors#error-codes).
3840 
41* 500 - `api_error`: An unexpected error has occurred internal to Anthropic’s systems. Retry only if the response’s `x-should-retry` header isn’t `false` (see [Retries](https://platform.claude.com/docs/en/api/errors#retries)). If the error persists, contact support with the [request ID](https://platform.claude.com/docs/en/api/errors#request-id). If the error type is `timeout_error` instead, see the 504 entry.
42 
3943* 504 - `timeout_error`: The request timed out while processing. The API also returns `timeout_error` with other status codes, such as a 500 when a request reaches the server’s time limit before the response starts. For long-running Messages API requests, use the [streaming Messages API](https://platform.claude.com/docs/en/build-with-claude/streaming). See [Long requests](https://platform.claude.com/docs/en/api/errors#long-requests) for more options.
4044 
4145* 529 - `overloaded_error`: The API is temporarily overloaded.
from line 48
4448 A 529 error can occur when the API experiences high traffic across all users.
4549 </Warning>
4650 
47The official SDK automatically retries transient failures (such as connection errors, rate limits, and 5xx server errors) with exponential backoff, twice by default, honoring the `retry-after` header when present. The SDK client accepts `max_retries` (typescript, php: `maxRetries`; java: `.maxRetries()`; csharp: `MaxRetries`; go: `option.WithMaxRetries()`) to configure or disable this behavior.
48 
4951When receiving a [streaming](https://platform.claude.com/docs/en/build-with-claude/streaming) response over server-sent events (SSE), an error can occur after the API returns a 200 response. In that case, error handling doesn’t follow these standard mechanisms. See [Error events](https://platform.claude.com/docs/en/build-with-claude/streaming#error-events) for the shape of mid-stream errors.
5052 
53The SDK doesn’t retry an error in a stream. To catch one, see [Handle an error in a stream](https://platform.claude.com/docs/en/api/handle-errors#handle-an-error-in-a-stream).
54 
55### Retries
56 
57By default, the SDK retries a failed request up to two times (three attempts in all). To change the number of retries, set `max_retries` (typescript, php: `maxRetries`; java: `.maxRetries()`; csharp: `MaxRetries`; go: `option.WithMaxRetries()`) on the client. A value of `0` turns retries off.
58 
59For each failed attempt, the SDK determines two things:
60 
61* **Whether the SDK retries:** If the response has an `x-should-retry` header (`true` or `false`), the SDK follows it. Otherwise, the SDK retries connection errors, timeouts, and the statuses 408, 409, 429, and 500 and above.
62* **How long the SDK waits:** If the response has a `retry-after` header, the SDK waits as long as the header says. Otherwise, it uses exponential backoff from 0.5 to 8 seconds.
63 
64The Go SDK retries some create methods in fewer cases. See [Retries for create methods in the Go SDK](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#retries-for-create-methods).
65 
66Without the SDK, follow `x-should-retry` and `retry-after` in your own code and use backoff and a retry limit.
67 
5168## Request size limits
5269 
5370The first-party Claude API enforces these request size limits. For other platforms, see the [API overview](https://platform.claude.com/docs/en/api/overview#request-size-limits).
from line 95
7895 
7996Under the [API versioning policy](https://platform.claude.com/docs/en/api/versioning), the values within these objects can expand, and new `type` values can appear.
8097 
98### Error codes
99 
100Some errors also have an error code in `error.details.error_code`. One `type` can cover several causes, and a code names one of them.
101 
102For example, hitting a rate limit and reaching your [monthly spend cap](https://platform.claude.com/docs/en/api/rate-limits#reaching-your-spend-cap) both cause a 429 `rate_limit_error`. On the Messages API, the spend-cap response adds a code:
103 
104```json JSON
105{
106 "type": "error",
107 "error": {
108 "type": "rate_limit_error",
109 "message": "You have reached your API usage limits: ...",
110 "details": { "error_code": "enforced_spend_limit_reached" }
111 },
112 "request_id": "req_018EeWyXxfu5pfWkrYcMdjWG"
113}
114```
115 
116Other APIs that return this 429, such as Claude Managed Agents, don’t add the code. There, only the `message` tells the two causes apart, and you shouldn’t match it in code. A spend-cap 429 keeps failing until access resumes, so limit your retries after a 429.
117 
118The set of codes can grow. If an error has no code or has a code that you don’t recognize, handle it by its `type` or HTTP status.
119 
120For the full list of codes, see [`ErrorDetails`](https://platform.claude.com/docs/en/api/$shared#error_details) in the API reference. To find the codes that a method can return, see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code).
121 
81122## SDK error types
82123 
83The official SDK raises typed exceptions for these errors instead of returning raw JSON. For example, a 404 surfaces as `anthropic.NotFoundError` (typescript: `Anthropic.NotFoundError`; ruby: `Anthropic::Errors::NotFoundError`; java: `com.anthropic.errors.NotFoundException`; csharp: `AnthropicNotFoundException`; php: `Anthropic\Core\Exceptions\NotFoundException`; go: `*anthropic.Error`). The Go SDK has one error type for every status, `*anthropic.Error`: branch on `StatusCode`. Catch the SDK’s typed classes rather than string-matching error messages, handling the most specific classes first. Your SDK’s page documents the full exception hierarchy:
124This section lists what to catch or check in the SDK for each kind of error. To write a handler, see [Handle errors](https://platform.claude.com/docs/en/api/handle-errors).
84125 
85* [Python](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#handling-errors) · [TypeScript](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#handling-errors) · [C#](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/csharp#error-handling) · [Go](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#error-handling) · [Java](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#error-handling) · [PHP](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/php#error-handling) · [Ruby](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/ruby#handling-errors)
126<Tabs>
127 <Tab title="Python">
128 These classes are in the `anthropic` package unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, `RateLimitError` also catches `EnforcedSpendLimitReachedError`.
86129 
130 | To handle | Catch |
131 | ----- | ----- |
132 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `anthropic.EnforcedSpendLimitReachedError` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
133 | 400 | `BadRequestError` |
134 | 401 | `AuthenticationError` |
135 | 403 | `PermissionDeniedError` |
136 | 404 | `NotFoundError` |
137 | 409 | `ConflictError` |
138 | 413 | `ContentTooLargeError` |
139 | 422 | `UnprocessableEntityError` |
140 | 429 | `RateLimitError` |
141 | 504 | `GatewayTimeoutError` |
142 | 529 | `OverloadedError` |
143 | Every 5xx, such as 500, 504, and 529 | `InternalServerError` |
144 | Every error response | `APIStatusError` |
145 | An error event in a stream | `APIStatusError` |
146 | A client timeout (the SDK stopped waiting) | `APITimeoutError` |
147 | Every connection failure before a response arrives (including a client timeout) | `APIConnectionError` |
148 | A connection that drops or stalls in mid-stream | `httpx2.TransportError` (`httpx2` is the SDK’s HTTP library) |
149 | Every error in this table except a dropped stream | `APIError` |
150 
151 For a status that has no row, such as 402, catch `APIStatusError` and compare its `status_code`.
152 
153 To reach the underlying exception or the raw response, see [Handling errors in Python](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#handling-errors).
154 </Tab>
155 
156 <Tab title="TypeScript">
157 These classes are properties of `Anthropic` unless a row says otherwise. A class also catches its subclasses, so put the narrower class first. For example, `RateLimitError` also catches `EnforcedSpendLimitReachedError`.
158 
159 | To handle | Catch |
160 | ----- | ----- |
161 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `Anthropic.EnforcedSpendLimitReachedError` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
162 | 400 | `BadRequestError` |
163 | 401 | `AuthenticationError` |
164 | 403 | `PermissionDeniedError` |
165 | 404 | `NotFoundError` |
166 | 409 | `ConflictError` |
167 | 413 | `ContentTooLargeError` |
168 | 422 | `UnprocessableEntityError` |
169 | 429 | `RateLimitError` |
170 | 504 | `GatewayTimeoutError` |
171 | 529 | `OverloadedError` |
172 | Every 5xx, such as 500, 504, and 529 | `InternalServerError` |
173 | A client timeout (the SDK stopped waiting) | `APIConnectionTimeoutError` |
174 | Every connection failure before a response arrives (including a client timeout) | `APIConnectionError` |
175 | A connection that drops in mid-stream | `AnthropicError` from `client.messages.stream()`. With `stream: true`, catch the runtime’s own error, such as `TypeError`. |
176 | An error event in a stream | `APIError` |
177 | Every error in this table except a dropped stream | `APIError` |
178 
179 For a status that has no row, such as 402, catch `APIError` and compare its `status`.
180 
181 To read the response headers, see [Handling errors in TypeScript](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#handling-errors).
182 </Tab>
183 
184 <Tab title="C#">
185 These classes are in the `Anthropic.Exceptions` namespace unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, `AnthropicRateLimitException` also catches `AnthropicEnforcedSpendLimitReachedException`.
186 
187 | To handle | Catch |
188 | ----- | ----- |
189 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `Anthropic.Models.AnthropicEnforcedSpendLimitReachedException` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
190 | 400 | `AnthropicBadRequestException` |
191 | 401 | `AnthropicUnauthorizedException` |
192 | 403 | `AnthropicForbiddenException` |
193 | 404 | `AnthropicNotFoundException` |
194 | 409 | `AnthropicConflictException` |
195 | 413 | `AnthropicContentTooLargeException` |
196 | 422 | `AnthropicUnprocessableEntityException` |
197 | 429 | `AnthropicRateLimitException` |
198 | 504 | `AnthropicGatewayTimeoutException` |
199 | 529 | `AnthropicOverloadedException` |
200 | Every 4xx | `Anthropic4xxException` |
201 | Every 5xx, such as 500, 504, and 529 | `Anthropic5xxException` |
202 | Every error response | `AnthropicApiException` |
203 | An error event in a stream | `AnthropicSseException` |
204 | Every error response and every error event in a stream | `AnthropicServiceException` |
205 | A connection failure before a response arrives | `AnthropicIOException` |
206 | A connection that drops in mid-stream | .NET’s own `IOException` in `System.IO` |
207 | A client timeout (the SDK stopped waiting) | .NET’s own `TaskCanceledException` in `System.Threading.Tasks` |
208 | Every error in this table except a client timeout and a dropped stream | `AnthropicException` |
209 
210 For a status that has no row of its own, such as 402, catch `Anthropic4xxException` and compare its `StatusCode`.
211 </Tab>
212 
213 <Tab title="Go">
214 The Go SDK has one error type, `*anthropic.Error`. You compare its fields instead of catching a class. In this table, `apierr` is a `*anthropic.Error` variable that `errors.As()` fills.
215 
216 | To handle | Check |
217 | ----- | ----- |
218 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | `apierr.ErrorCode() == anthropic.ErrorCodeEnforcedSpendLimitReached` |
219 | One HTTP status | `apierr.StatusCode == http.StatusTooManyRequests` |
220 | Every error response | `errors.As(err, &apierr)` |
221 | An error event in a stream | `errors.As(stream.Err(), &apierr)` |
222 | A connection failure, a client timeout, or a connection that drops in mid-stream | Any other `err` that isn’t `nil` |
223 
224 Each error code has its own constant (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)).
225 
226 To print the raw request and response of a `*anthropic.Error`, see [Error handling in Go](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/go#error-handling).
227 </Tab>
228 
229 <Tab title="Java">
230 These classes are in the `com.anthropic.errors` package unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, `RateLimitException` also catches `EnforcedSpendLimitReachedException`.
231 
232 | To handle | Catch |
233 | ----- | ----- |
234 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `com.anthropic.models.EnforcedSpendLimitReachedException` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
235 | 400 | `BadRequestException` |
236 | 401 | `UnauthorizedException` |
237 | 403 | `PermissionDeniedException` |
238 | 404 | `NotFoundException` |
239 | 409 | `ConflictException` |
240 | 413 | `ContentTooLargeException` |
241 | 422 | `UnprocessableEntityException` |
242 | 429 | `RateLimitException` |
243 | 504 | `GatewayTimeoutException` |
244 | 529 | `OverloadedException` |
245 | Every 5xx, such as 500, 504, and 529 | `InternalServerException` |
246 | An error event in a stream | `SseException` |
247 | Every error response and every error event in a stream | `AnthropicServiceException` |
248 | A connection failure, a client timeout, or a connection that drops in mid-stream | `AnthropicIoException` |
249 | Every error in this table | `AnthropicException` |
250 
251 For a status that has no row, such as 402, catch `AnthropicServiceException` and compare its `statusCode()`.
252 
253 The error’s `errorCode()` and `type()` each return an `Optional`.
254 
255 To read the response headers, see [Error handling in Java](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#error-handling).
256 </Tab>
257 
258 <Tab title="PHP">
259 These classes are in the `Anthropic\Core\Exceptions` namespace unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, `RateLimitException` also catches `EnforcedSpendLimitReachedException`.
260 
261 | To handle | Catch |
262 | ----- | ----- |
263 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `Anthropic\EnforcedSpendLimitReachedException` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
264 | 400 | `BadRequestException` |
265 | 401 | `AuthenticationException` |
266 | 403 | `PermissionDeniedException` |
267 | 404 | `NotFoundException` |
268 | 409 | `ConflictException` |
269 | 413 | `ContentTooLargeException` |
270 | 422 | `UnprocessableEntityException` |
271 | 429 | `RateLimitException` |
272 | 504 | `GatewayTimeoutException` |
273 | 529 | `OverloadedException` |
274 | Every 5xx, such as 500, 504, and 529 | `InternalServerException` |
275 | Every error response | `APIStatusException` |
276 | An error event in a stream | `APIStatusException` |
277 | A connection failure before a response arrives or a client timeout | `APIConnectionException` |
278 | A connection that drops in mid-stream | The HTTP client’s own exception or none (see the paragraph after this table). With Guzzle 7, a connection reset raises PHP’s `\RuntimeException`. |
279 | Every error in this table except a dropped stream | `APIException` |
280 
281 If the server closes the connection in mid-stream, the stream ends with no error. Check that a `message_stop` event arrived.
282 
283 For a status that has no row, such as 402, catch `APIStatusException` and compare its `status`.
284 
285 To reach the underlying exception, see [Error handling in PHP](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/php#error-handling).
286 </Tab>
287 
288 <Tab title="Ruby">
289 These classes are in the `Anthropic::Errors` module unless a row names another. A class also catches its subclasses, so put the narrower class first. For example, `RateLimitError` also catches `EnforcedSpendLimitReachedError`.
290 
291 | To handle | Catch |
292 | ----- | ----- |
293 | One [error code](https://platform.claude.com/docs/en/api/errors#error-codes) | Its own class, such as `Anthropic::EnforcedSpendLimitReachedError` (see [Handle a specific error code](https://platform.claude.com/docs/en/api/handle-errors#handle-a-specific-error-code)) |
294 | 400 | `BadRequestError` |
295 | 401 | `AuthenticationError` |
296 | 403 | `PermissionDeniedError` |
297 | 404 | `NotFoundError` |
298 | 409 | `ConflictError` |
299 | 413 | `ContentTooLargeError` |
300 | 422 | `UnprocessableEntityError` |
301 | 429 | `RateLimitError` |
302 | 504 | `GatewayTimeoutError` |
303 | 529 | `OverloadedError` |
304 | Every 5xx, such as 500, 504, and 529 | `InternalServerError` |
305 | Every error response | `APIStatusError` |
306 | An error event in a stream | `APIStatusError` |
307 | A client timeout (the SDK stopped waiting) | `APITimeoutError` |
308 | Every connection failure (including a client timeout and a connection that drops in mid-stream) | `APIConnectionError` |
309 | Every error in this table | `APIError` |
310 
311 For a status that has no row, such as 402, catch `APIStatusError` and compare its `status`.
312 
313 The error’s `error_code` and `type` are symbols.
314 
315 To reach the underlying exception, see [Handling errors in Ruby](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/ruby#handling-errors).
316 </Tab>
317</Tabs>
318 
319The table goes by HTTP status and error code, not by `error.type`:
320 
321* A 503 with `overloaded_error` counts as a 5xx, not as a 529.
322* An error event in a stream never matches a status row or a code’s class. Its HTTP status is the stream’s 200 or is missing.
323 
324To go by `error.type` instead, check the error’s `type` (csharp: `Type`; go: `Type()`; java: `type()`; php: `getType()`) as in [Handle an error in a stream](https://platform.claude.com/docs/en/api/handle-errors#handle-an-error-in-a-stream).
325 
87326## Request ID
88327 
89328Every API response includes a unique `request-id` header. This header contains a value such as `req_018EeWyXxfu5pfWkrYcMdjWG`. The same identifier appears as the `request_id` field in [error response bodies](https://platform.claude.com/docs/en/api/errors#error-shapes). When contacting support about a specific request, include this ID to help quickly resolve your issue.
from line 329
90329 
91330On [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), responses include two request IDs: the AWS request ID (`x-amzn-requestid`, primary, indexed in CloudTrail) and the Anthropic request ID (`request-id`, secondary). Use the AWS request ID for CloudTrail lookups and the Anthropic request ID for Anthropic support tickets.
92331 
332When the API returns an error response, read the ID from the SDK error in `request_id` (typescript: `requestID`; csharp, go: `RequestID`; java: `requestId()`; php: `getRequestID()`). For a sample, see [Catch errors by kind](https://platform.claude.com/docs/en/api/handle-errors#catch-errors-by-kind). When a request succeeds, read the ID from the response.
333 
93334The Python and TypeScript SDKs expose the request ID as a `_request_id` property on top-level response objects. The C#, Go, Java, and PHP SDKs expose it through their raw-response accessors, and the Ruby SDK through [middleware](https://platform.claude.com/docs/en/cli-sdks-libraries/middleware). In every SDK except Ruby, use `with_raw_response` (typescript: `.withResponse()`; java: `.withRawResponse()`; csharp: `WithRawResponse`; go: `option.WithResponseInto()`; php: `->raw`) to read any other [response header](https://platform.claude.com/docs/en/api/overview#response-headers), such as `anthropic-organization-id` and [`anthropic-workspace-id`](https://platform.claude.com/docs/en/manage-claude/workspaces#identify-the-workspace-behind-an-api-response). In Ruby, use the same middleware. On Claude Platform on AWS, use the raw-response accessor to read the AWS request ID (`x-amzn-requestid`) as well:
94335 
95336<CodeGroup>
from line 827
586827 To mitigate misuse and manage capacity on the API, limits are in place on how much an organization can use the Claude API.
587828 </Card>
588829 
589 <Card title="Streaming messages" icon="lightning" href="https://platform.claude.com/docs/en/build-with-claude/streaming">
590 Stream Messages API responses incrementally with server-sent events, including text, tool use, and extended thinking deltas.
830 <Card title="Handle errors" icon="code" href="https://platform.claude.com/docs/en/api/handle-errors">
831 Use the SDK to catch Claude API errors by error code, HTTP status, or connection failure and to handle an error that arrives in a stream.
591832 </Card>
592833</CardGroup>
593834 
Feedback