For Amazon Bedrock support changedcli-sdks-libraries/sdks/python
Nearest release: v2.1.307, published an hour after 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+20added
Lines−20removed
From line
69
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits10to this page, all time
### Handling null versus missing fields #### Undocumented request parameters ### Handling null vs missing fields #### Undocumented request params
The whole hunk
from line 69, old and new numbered
/
from line 69
6969 Consider using [python-dotenv](https://pypi.org/project/python-dotenv/) to add `ANTHROPIC_API_KEY="my-anthropic-api-key"` to your `.env` file so that your API key isn't stored in source control.
7070</Tip>
7171
72For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) with access to multiple workspaces, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
72For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) that isn't scoped to a workspace, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
7373
7474## Async usage
7575
from line 202
202202
203203Streaming with `client.messages.stream(...)` exposes various helpers including accumulation and SDK-specific events.
204204
205Alternatively, you can use `client.messages.create(..., stream=True)` which only returns an iterable of the events in the stream and uses less memory (it doesn't build up a final message object for you).
205Alternatively, you can use `client.messages.create(..., stream=True)`, which only returns an iterable of the events in the stream and uses less memory (it doesn't build up a final message object for you).
206206
207207## Token counting
208208
from line 347
347347
348348## Handling errors
349349
350When the library is unable to connect to the API, or if the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `APIError` is raised:
350When the library is unable to connect to the API, or if the API returns a non-success status code (that is, a 4xx or 5xx response), a subclass of `APIError` is raised:
351351
352352```python
353353import anthropic
from line 392
392392
393393> For more information on debugging requests, see [Request ID](https://platform.claude.com/docs/en/api/errors#request-id).
394394
395All object responses in the SDK provide a `_request_id` property which is added from the `request-id` response header so that you can quickly log failing requests and report them back to Anthropic.
395All object responses in the SDK provide a `_request_id` property, which is added from the `request-id` response header so that you can log failing requests and report them back to Anthropic.
396396
397397```python
398398message = client.messages.create(
from line 400
400400 messages=[{"role": "user", "content": "Hello, Claude"}],
401401 model="claude-opus-5-5",
402402)
403print(message._request_id) # e.g., req_018EeWyXxfu5pfWkrYcMdjWG
403print(message._request_id) # for example, req_018EeWyXxfu5pfWkrYcMdjWG
404404```
405405
406406<Note>
from line 460
460460## Long requests
461461
462462<Warning>
463 Consider using the streaming [Messages API](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#streaming-responses) for longer running requests.
463 Consider using the [streaming Messages API](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#streaming-responses) for longer-running requests.
464464</Warning>
465465
466Avoid setting a large `max_tokens` value without using streaming. Some networks may drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#timeouts) without receiving a response from Anthropic.
466Avoid setting a large `max_tokens` value without using streaming. Some networks might drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#timeouts) without receiving a response from Anthropic.
467467
468468The SDK will throw a `ValueError` if a non-streaming request is expected to take longer than approximately 10 minutes. Passing `stream=True` or overriding the `timeout` option at the client or request level disables this error.
469469
470An expected request latency longer than the [timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#timeouts) for a non-streaming request will result in the client terminating the connection and retrying without receiving a response.
470An expected request latency longer than the [timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#timeouts) for a non-streaming request will result in the client ending the connection and retrying without receiving a response.
471471
472472The SDK sets a [TCP socket keep-alive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) option to reduce the impact of idle connection timeouts on some networks. This can be overridden by passing a custom `http_client` option to the client.
473473
from line 530
530530If you need to, you can override it by setting default headers on the client object or per-request.
531531
532532<Warning>
533 Overriding default headers may result in incorrect types and other unexpected or undefined behavior in the SDK.
533 Overriding default headers might result in incorrect types and other unexpected or undefined behavior in the SDK.
534534</Warning>
535535
536536```python
from line 552
552552
553553### Request parameters
554554
555Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also have helper methods for things like serializing back into JSON ([`v1`](https://docs.pydantic.dev/1.10/usage/models/), [`v2`](https://docs.pydantic.dev/latest/concepts/serialization/)).
555Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev), which also have helper methods for things such as serializing back into JSON ([Pydantic `v1`](https://docs.pydantic.dev/1.10/usage/models/), [Pydantic `v2`](https://docs.pydantic.dev/latest/concepts/serialization/)).
556556
557Typed requests and responses provide autocomplete and documentation within your editor. If you'd like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
557Typed requests and responses provide auto-complete and documentation within your editor. If you'd like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
558558
559559### Response models
560560
from line 570
570570data = message.to_dict()
571571```
572572
573### Handling null vs missing fields
573### Handling null versus missing fields
574574
575575In responses, you can distinguish between fields that are explicitly `null` versus fields that were not returned (missing):
576576
from line 627
627627 print(line)
628628```
629629
630The context manager is required so that the response will reliably be closed.
630The context manager is required so that the response is reliably closed.
631631
632632### Logging
633633
from line 641
641641
642642### Making custom/undocumented requests
643643
644This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.
644This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, parameters, or response properties, the library can still be used.
645645
646646#### Undocumented endpoints
647647
from line 659
659659print(response.json())
660660```
661661
662#### Undocumented request params
662#### Undocumented request parameters
663663
664664If you want to explicitly send an extra parameter, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request options.
665665
666666<Warning>
667 The `extra_` parameters override documented parameters of the same name. For security reasons, ensure these methods are only used with trusted input data.
667 The `extra_` parameters override documented parameters of the same name. For security reasons, use these methods only with trusted input data.
668668</Warning>
669669
670670#### Undocumented response properties
671671
672To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You can also get all extra fields on the Pydantic model as a dict with `response.model_extra`.
672To access undocumented response properties, you can access the extra fields such as `response.unknown_prop`. You can also get all extra fields on the Pydantic model as a dict with `response.model_extra`.
673673
674674### Configuring the HTTP client
675675
from line 703
703703
704704### Managing HTTP resources
705705
706By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
706By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if you want to, or with a context manager that closes when exiting.
707707
708708```python
709709with Anthropic() as client:
from line 764
764764This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backward-incompatible changes may be released as minor versions:
765765
7667661. Changes that only affect static types, without breaking runtime behavior.
7672. Changes to library internals which are technically public but not intended or documented for external use.
7672. Changes to library internals that are technically public but not intended or documented for external use.
7687683. Changes that aren't expected to impact the vast majority of users in practice.
769769
770770### Determining the installed version
No line in this hunk matches that.