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

For Amazon Bedrock support changedcli-sdks-libraries/sdks/python

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+13added
Lines−43removed
From line 349 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits21to this page, all time

The whole hunk

from line 349, old and new numbered
/
lines
from line 349
349349 
350350## Handling errors
351351 
352The SDK raises a subclass of `APIError` when it can’t connect to the API or when the API returns a 4xx or 5xx status code:
352The SDK raises a subclass of `anthropic.APIError` when it can’t connect to the API or when the API returns an error response (4xx or 5xx). [SDK error types](https://platform.claude.com/docs/en/api/errors#sdk-error-types) lists the classes, and [Handle errors](https://platform.claude.com/docs/en/api/handle-errors) shows how to catch them.
353353 
354```python
355import anthropic
356# ...
357try:
358 message = client.messages.create(
359 max_tokens=1024,
360 messages=[
361 {
362 "role": "user",
363 "content": "Hello, Claude",
364 }
365 ],
366 model="claude-opus-5-5",
367 )
368except anthropic.APIConnectionError as e:
369 print("The server could not be reached")
370 print(e.__cause__) # an underlying Exception, likely raised within httpx2
371except anthropic.RateLimitError as e:
372 print("A 429 status code was received; wait before retrying.")
373except anthropic.APIStatusError as e:
374 print("Another non-200-range status code was received")
375 print(e.status_code)
376 print(e.response)
377```
354Two of the classes hold more detail on a failure:
378355 
379Error codes are as follows:
356| Class | Raised when | Where the detail is |
357| ----- | ----- | ----- |
358| `APIConnectionError` | The SDK can’t reach the API, or the request times out (the subclass `APITimeoutError`) | `__cause__` holds the underlying exception |
359| `APIStatusError` | The API returns an error response | `status_code` holds the status, and `response` holds the raw `httpx2.Response` with its headers |
380360 
381| Status code | Error type |
382| ----- | ----- |
383| 400 | `BadRequestError` |
384| 401 | `AuthenticationError` |
385| 403 | `PermissionDeniedError` |
386| 404 | `NotFoundError` |
387| 409 | `ConflictError` |
388| 422 | `UnprocessableEntityError` |
389| 429 | `RateLimitError` |
390| >=500 | `InternalServerError` |
391| N/A | `APIConnectionError` |
392 
393361## Request IDs
394362 
395363> For more information on debugging requests, see [Request ID](https://platform.claude.com/docs/en/api/errors#request-id).
from line 379
411379 
412380## Retries
413381 
414By default, the SDK retries certain errors twice, with a short exponential backoff. It retries connection errors (for example, a network problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.
382By default, the SDK retries certain errors up to two times (three attempts in all). It retries connection errors, timeouts, 408 Request Timeout, 409 Conflict, 429 Too Many Requests, and 5xx server errors.
415383 
416You can use the `max_retries` option to configure or disable this:
384If a response has an `x-should-retry` header (`true` or `false`), the SDK follows it instead of the status. Between attempts, the SDK waits as long as the `retry-after` header says, or it uses a short exponential backoff.
385 
386Use the `max_retries` option to configure or disable retries:
417387 
418388```python
419389# Configure the default for all requests:
Feedback