aiollm_anthropic¶
aiollm_anthropic
¶
Anthropic provider: its client, API and error resolver.
Modules:
| Name | Description |
|---|---|
adapters |
Anthropic's adapters between shared types and its methods. |
api |
URLs and version of the Anthropic API. |
client |
Client of the Anthropic API. |
methods |
Anthropic's methods of the Messages and Files APIs. |
resolver |
Error mapping of the Anthropic API. |
tools |
Anthropic's built-in tools, as the shared request takes them. |
types |
Anthropic's own types and the options of a generation call. |
Classes:
| Name | Description |
|---|---|
AnthropicAPI |
Builds Anthropic request URLs. |
AnthropicClient |
Client of the Anthropic API. |
AnthropicErrorResolver |
Error resolver with Anthropic's specifics. |
Attributes:
| Name | Type | Description |
|---|---|---|
ANTHROPIC_API |
Final[AnthropicAPI]
|
The Anthropic API, version 1. |
API_VERSION |
Final
|
The |
ANTHROPIC_API
module-attribute
¶
ANTHROPIC_API: Final[AnthropicAPI] = AnthropicAPI(
base_url="https://api.anthropic.com/", version="v1"
)
The Anthropic API, version 1.
API_VERSION
module-attribute
¶
API_VERSION: Final = '2026-10-21'
The anthropic-version that the library's Anthropic types follow.
Anthropic requires the header on every request; it fixes the request and response format, so it belongs to the methods written against it.
AnthropicAPI
¶
AnthropicClient
¶
AnthropicClient(
token: str | None = None,
*,
session: ISession | None = None,
default_max_tokens: int = DEFAULT_MAX_TOKENS,
**session_kwargs: Unpack[AiohttpSessionOptions],
)
Bases: BaseProviderClient
Client of the Anthropic API.
Anthropic takes the key in Authorization or x-api-key; a
given session that sends it elsewhere, or uses the generic
BaseErrorResolver, gets a warning from warn_about_session.
Attributes:
| Name | Type | Description |
|---|---|---|
generation |
Shared text generation over the Messages API, with
|
|
files |
Shared file storage over the Files API. |
Example
async with AnthropicClient("sk-ant-...") as client: ... response = await client.generation.create( ... GenerationRequest(model="claude-opus-5-5", input="Hi") ... )
Create the client from a token or a ready session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | None
|
API key; an |
None
|
session
|
ISession | None
|
A ready session, for custom settings; it is checked
with |
None
|
default_max_tokens
|
int
|
|
DEFAULT_MAX_TOKENS
|
**session_kwargs
|
Unpack[AiohttpSessionOptions]
|
Further arguments of the
|
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
AnthropicErrorResolver
¶
Bases: BaseErrorResolver
Error resolver with Anthropic's specifics.
Anthropic's error object has a type (rate_limit_error,
overloaded_error, ...) and no code; details.error_code,
when present, is read as the code. A reached spend cap (429 with
enforced_spend_limit_reached) or spend limit (400 whose message
says so) is a QuotaExceededError and is not retried. The 529
overloaded_error is a transient ServiceUnavailableError, as
OpenAI's 503. An error event of a stream arrives with the
stream's 200 status, so its class is picked by its type; as for
every resolver, it is never transient.
Methods:
| Name | Description |
|---|---|
get_error_code |
Read |
classify_status |
Pick the error class and transience of Anthropic's statuses. |
get_error_code
¶
classify_status
¶
classify_status(
*,
status: int,
code: str | None,
error_type: str | None,
message: str | None,
retry_after: float | None,
) -> tuple[type[APIStatusError], bool]
Pick the error class and transience of Anthropic's statuses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
int
|
HTTP status the error is classified by. |
required |
code
|
str | None
|
Provider error code, if any. |
required |
error_type
|
str | None
|
Provider error type, if any. |
required |
message
|
str | None
|
Error message, if any. |
required |
retry_after
|
float | None
|
Seconds from |
required |
Returns:
| Type | Description |
|---|---|
type[APIStatusError]
|
|
bool
|
cap or limit, a transient |
tuple[type[APIStatusError], bool]
|
else the default classification. |
methods
¶
Anthropic's methods of the Messages and Files APIs.
Their request fields are the generated mixins of methods.params.
Modules:
| Name | Description |
|---|---|
files |
Methods of Anthropic's Files API. |
messages |
Methods of Anthropic's Messages API. |
params |
Generated provider component types. |
Classes:
| Name | Description |
|---|---|
CreateFile |
Upload a file, to refer to it by its |
DeleteFile |
Delete a file. |
DownloadFile |
Stream the content of a file that a tool created. |
ListFiles |
List the files of the workspace, newest first, a page at a time. |
RetrieveFile |
Get the metadata of a file. |
CreateMessage |
Create a message and wait for the whole of it. |
StreamMessage |
Create a message and stream its events. |
Attributes:
| Name | Type | Description |
|---|---|---|
VERSION_HEADERS |
Final[Mapping[str, str]]
|
|
VERSION_HEADERS
module-attribute
¶
VERSION_HEADERS: Final[Mapping[str, str]] = {
ANTHROPIC_VERSION: API_VERSION
}
__request_headers__ of every Anthropic method.
Anthropic requires anthropic-version on every request, and the
version fixes the request and response format, so a method written
against API_VERSION sends it itself. A method of your own sets
__request_headers__ = VERSION_HEADERS too.
CreateFile
¶
Bases: CreateFileParams, BaseAPIMethod[FileMetadata]
Upload a file, to refer to it by its id in later requests.
The upload is never retried: POST /files is not idempotent, and a
retry after a lost answer would store the file twice. A timeout or a
lost connection may therefore leave a file at Anthropic whose id
you never got; give the file expires_in_seconds where that
matters.
Every key of the workspace sees its files: treat a file id as a
server-side reference and never take one from an end user.
Example
file = await client.send_request( ... CreateFile(file=Path("report.pdf"), expires_in_seconds=3600) ... ) file.id
DeleteFile
¶
Bases: DeleteFileParams, BaseAPIMethod[DeletedFile]
Delete a file.
It is retried on a transient failure, as the official SDKs do; a
retry after a deletion whose answer was lost raises
NotFoundError, since the file is already gone.
Example
await client.send_request(DeleteFile(file_id="file_1"))
DownloadFile
¶
Bases: DownloadFileParams, BaseStreamMethod[bytes]
Stream the content of a file that a tool created.
Only files with downloadable set (made by code execution or a
skill) can be downloaded; any other raises BadRequestError
(file_not_downloadable), and an expired one NotFoundError.
Only opening the download is retried. Stream.save(path) writes it
to a file.
Example
method = DownloadFile(file_id="file_1") async with client.stream(method) as content: ... await content.save(Path("chart.png"))
ListFiles
¶
Bases: ListFilesParams, BaseAPIMethod[ListFilesResponse]
List the files of the workspace, newest first, a page at a time.
Pass the page's next_page as page while it is not None.
ids (up to 100) asks for those files only, in one page, and
cannot be combined with page or limit. The id of a deleted
or unknown file is left out, while one that is not a valid file id
fails the whole request with BadRequestError.
Example
page = await client.send_request(ListFiles(limit=100)) while page.next_page is not None: ... page = await client.send_request( ... ListFiles(limit=100, page=page.next_page) ... )
RetrieveFile
¶
Bases: RetrieveFileParams, BaseAPIMethod[FileMetadata]
Get the metadata of a file.
Example
file = await client.send_request(RetrieveFile(file_id="file_1"))
CreateMessage
¶
Bases: MessageLimits, CreateMessageParams, BaseAPIMethod[Message]
Create a message and wait for the whole of it.
A transient failure (a lost connection, a timeout, a 5xx, the 529
overloaded_error, a 429 with Retry-After) is retried, as the
official SDKs do. A timeout or a lost connection may hide a
generation that ran on the server, a risk the SDKs accept too.
Example
message = await client.send_request( ... CreateMessage( ... model="claude-opus-5-5", ... max_tokens=1024, ... messages=[{"role": "user", "content": "Hi"}], ... ) ... ) message.content
StreamMessage
¶
Bases: MessageLimits, StreamMessageParams, BaseStreamMethod[MessageStreamEvent]
Create a message and stream its events.
The stream is message_start, content blocks (each a
content_block_start, deltas and a content_block_stop), one or
more message_delta and message_stop, with ping events in
between; an error event is raised as an APIStatusError. Only
opening the stream is retried, on a transient failure. A body
that ends before message_stop raises
APIStreamInterruptedError.
Its stream field is always True: it asks for server-sent
events.
Example
method = StreamMessage( ... model="claude-opus-5-5", ... max_tokens=1024, ... messages=[{"role": "user", "content": "Hi"}], ... ) async with client.stream(method) as events: ... async for event in events: ... if isinstance(event, ContentBlockDeltaEvent): ... ...
params
¶
Generated provider component types.
Modules:
| Name | Description |
|---|---|
files |
Provider files types generated from OpenAPI. |
images |
Provider images types generated from OpenAPI. |
messages |
Provider messages types generated from OpenAPI. |
shared |
Provider shared types generated from OpenAPI. |
tools |
Provider tools types generated from OpenAPI. |
Classes:
| Name | Description |
|---|---|
BrowserFileUploadConfigParam |
|
ContainerUploadBlock |
Response model for a file uploaded to the container. |
CreateFileParams |
|
CreateFileRequest |
|
DeleteFileParams |
|
DownloadFileParams |
|
FileDocumentSourceParam |
|
FileImageSourceParam |
|
ListFilesParams |
|
RetrieveFileParams |
|
Base64ImageSourceParam |
|
ImageBlockParam |
|
ImageTransformationsParam |
|
URLImageSourceParam |
|
AssistantMessageParam |
|
CitationCharLocation |
|
CitationContentBlockLocation |
|
CitationContentBlockLocationParam |
|
CitationPageLocation |
|
CitationsSearchResultLocation |
|
CitationsWebSearchResultLocation |
|
ContainerParams |
Container parameters with skills to be loaded. |
ContentBlockSourceParam |
|
CreateMessageParams |
|
DiagnosticsParam |
Request-level diagnostics. |
DocumentBlockParam |
|
JSONOutputFormatParam |
|
MessagesCreateWireBody |
|
MetadataParam |
|
OutputConfigParam |
|
RedactedThinkingBlock |
|
RedactedThinkingBlockParam |
|
SearchResultBlockParam |
|
SkillParams |
Specification for a skill to be loaded in a container. |
StreamMessageParams |
|
SystemMessageParam |
|
TextBlock |
|
TextBlockParam |
|
ThinkingBlock |
|
ThinkingBlockParam |
|
ThinkingConfigAdaptiveParam |
|
ThinkingConfigDisabledParam |
|
ThinkingConfigEnabledParam |
|
ToolResultBlockParam |
|
UserMessageParam |
|
WebFetchBlockParam |
|
WebFetchToolResultBlockParam |
|
Base64PDFSourceParam |
|
CacheControlEphemeralParam |
|
CitationCharLocationParam |
|
CitationPageLocationParam |
|
CitationsConfigParam |
|
CitationSearchResultLocationParam |
|
CitationWebSearchResultLocationParam |
|
ContainerUploadBlockParam |
|
PlainTextSourceParam |
|
URLPDFSourceParam |
|
Base64PDFSource |
|
BashCodeExecutionOutputBlock |
|
BashCodeExecutionOutputBlockParam |
|
BashCodeExecutionResultBlock |
|
BashCodeExecutionResultBlockParam |
|
BashCodeExecutionToolResultBlock |
|
BashCodeExecutionToolResultBlockParam |
|
BashCodeExecutionToolResultErrorObject |
|
BashCodeExecutionToolResultErrorParam |
|
BrowserCloseTabConfigParam |
|
BrowserDoubleClickConfigParam |
|
BrowserFindConfigParam |
|
BrowserFormInputConfigParam |
|
BrowserGetPageTextConfigParam |
|
BrowserHoldKeyConfigParam |
|
BrowserHoverConfigParam |
|
BrowserJavascriptExecConfigParam |
|
BrowserKeyConfigParam |
|
BrowserLeftClickConfigParam |
|
BrowserLeftClickDragConfigParam |
|
BrowserLeftMouseDownConfigParam |
|
BrowserLeftMouseUpConfigParam |
|
BrowserListTabsConfigParam |
|
BrowserMiddleClickConfigParam |
|
BrowserMouseMoveConfigParam |
|
BrowserNavigateConfigParam |
|
BrowserNewTabConfigParam |
|
BrowserReadConsoleConfigParam |
|
BrowserReadNetworkConfigParam |
|
BrowserReadPageConfigParam |
|
BrowserRightClickConfigParam |
|
BrowserScreenshotConfigParam |
|
BrowserScrollConfigParam |
|
BrowserScrollToConfigParam |
|
BrowserStateBlockParam |
|
BrowserStateChangeDownloadCompletedParam |
|
BrowserStateChangeDownloadFailedParam |
|
BrowserStateChangeDownloadStartedParam |
A file download that started during this call. |
BrowserStateChangeTabOpenedParam |
|
BrowserStateTabEntryParam |
|
BrowserSwitchTabConfigParam |
|
BrowserToolset20260801Param |
|
BrowserToolsetConfigsParam |
|
BrowserTripleClickConfigParam |
|
BrowserTypeConfigParam |
|
BrowserWaitConfigParam |
|
BrowserZoomConfigParam |
|
CitationsConfig |
|
CodeExecutionOutputBlock |
|
CodeExecutionOutputBlockParam |
|
CodeExecutionResultBlock |
|
CodeExecutionResultBlockParam |
|
CodeExecutionTool20250522Param |
|
CodeExecutionTool20250825Param |
|
CodeExecutionTool20260120Param |
|
CodeExecutionTool20260521Param |
Code execution tool with REPL state persistence. |
CodeExecutionToolResultBlock |
|
CodeExecutionToolResultBlockParam |
|
CodeExecutionToolResultErrorObject |
|
CodeExecutionToolResultErrorParam |
|
ComputerCursorPositionConfigParam |
|
ComputerDoubleClickConfigParam |
|
ComputerHoldKeyConfigParam |
|
ComputerKeyConfigParam |
|
ComputerLeftClickConfigParam |
|
ComputerLeftClickDragConfigParam |
|
ComputerLeftMouseDownConfigParam |
|
ComputerLeftMouseUpConfigParam |
|
ComputerMiddleClickConfigParam |
|
ComputerMouseMoveConfigParam |
|
ComputerRightClickConfigParam |
|
ComputerScreenshotConfigParam |
|
ComputerScrollConfigParam |
|
ComputerToolset20260801Param |
|
ComputerToolsetConfigsParam |
|
ComputerTripleClickConfigParam |
|
ComputerTypeConfigParam |
|
ComputerWaitConfigParam |
|
ComputerZoomConfigParam |
|
DirectCaller |
Tool invocation directly from the model. |
DirectCallerParam |
Tool invocation directly from the model. |
DocumentBlock |
|
EncryptedCodeExecutionResultBlock |
|
EncryptedCodeExecutionResultBlockParam |
|
InputSchemaTyped |
|
MemoryTool20250818Param |
|
PlainTextSource |
|
ServerToolCaller |
Tool invocation generated by a server-side tool. |
ServerToolCaller20260120 |
|
ServerToolCaller20260120Param |
|
ServerToolCallerParam |
Tool invocation generated by a server-side tool. |
ServerToolUseBlock |
|
ServerToolUseBlockParam |
|
TextEditorCodeExecutionCreateResultBlock |
|
TextEditorCodeExecutionCreateResultBlockParam |
|
TextEditorCodeExecutionStrReplaceResultBlock |
|
TextEditorCodeExecutionStrReplaceResultBlockParam |
|
TextEditorCodeExecutionToolResultBlock |
|
TextEditorCodeExecutionToolResultBlockParam |
|
TextEditorCodeExecutionToolResultErrorObject |
|
TextEditorCodeExecutionToolResultErrorParam |
|
TextEditorCodeExecutionViewResultBlock |
|
TextEditorCodeExecutionViewResultBlockParam |
|
ThinkingConfigBetweenToolsParam |
|
ToolBash20250124Param |
|
ToolChoiceAnyParam |
The model will use any available tools. |
ToolChoiceAutoParam |
The model will automatically decide whether to use tools. |
ToolChoiceNoneParam |
The model will not be allowed to use tools. |
ToolChoiceToolParam |
The model will use the specified tool with |
ToolParam |
|
ToolReferenceBlock |
|
ToolReferenceBlockParam |
Tool reference block that can be included in tool_result content. |
ToolSearchToolBm2520251119Param |
|
ToolSearchToolRegex20251119Param |
|
ToolSearchToolResultBlock |
|
ToolSearchToolResultBlockParam |
|
ToolSearchToolResultErrorObject |
|
ToolSearchToolResultErrorParam |
|
ToolSearchToolSearchResultBlock |
|
ToolSearchToolSearchResultBlockParam |
|
ToolTextEditor20250124Param |
|
ToolTextEditor20250429Param |
|
ToolTextEditor20250728Param |
|
ToolUseBlock |
|
ToolUseBlockParam |
|
UserLocationParam |
|
WebFetchBlock |
|
WebFetchTool20250910Param |
|
WebFetchTool20260209Param |
|
WebFetchTool20260309Param |
|
WebFetchTool20260318Param |
|
WebFetchToolResultBlock |
|
WebFetchToolResultErrorBlock |
|
WebFetchToolResultErrorBlockParam |
|
WebFetchURLSourceAllParam |
|
WebFetchURLSourceExceptParam |
|
WebFetchURLSourceNoneParam |
|
WebFetchURLSourceOnlyParam |
|
WebFetchURLSourcesParam |
Which sources contribute to the set of URLs web fetch may fetch. |
WebFetchURLSourceToolReferenceParam |
|
WebSearchResultBlock |
|
WebSearchResultBlockParam |
|
WebSearchTool20250305Param |
|
WebSearchTool20260209Param |
|
WebSearchTool20260318Param |
|
WebSearchToolRequestErrorObjectParam |
|
WebSearchToolResultBlock |
|
WebSearchToolResultBlockParam |
|
WebSearchToolResultErrorObject |
|
BrowserFileUploadConfigParam
¶
ContainerUploadBlock
¶
CreateFileParams
¶
Bases: BaseAPIType
CreateFileParams from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
file |
Annotated[InputFile, Field(description="The file to upload. Only the final path component of the part's `filename` is kept; an absent or empty `filename` is replaced with `unnamed` plus the extension for the file's stored `mime_type`, when known.")]
|
The file to upload. Only the final path component of
the part's |
expires_in_seconds |
Annotated[int | MISSING, Field(description='Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).', ge=3600, le=7776000)]
|
Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days). |
CreateFileRequest
¶
Bases: BaseAPIType
CreateFileRequest from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
file |
Annotated[InputFile, Field(description="The file to upload. Only the final path component of the part's `filename` is kept; an absent or empty `filename` is replaced with `unnamed` plus the extension for the file's stored `mime_type`, when known.")]
|
The file to upload. Only the final path component of
the part's |
expires_in_seconds |
Annotated[int | MISSING, Field(description='Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).', ge=3600, le=7776000)]
|
Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days). |
DeleteFileParams
¶
DownloadFileParams
¶
FileDocumentSourceParam
¶
FileImageSourceParam
¶
ListFilesParams
¶
RetrieveFileParams
¶
Base64ImageSourceParam
¶
ImageBlockParam
¶
Bases: BaseAPIType
ImageBlockParam from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
transformations |
ImageTransformationsParam | None | MISSING
|
Configures the transformations the server applies to this image before the model observes it. Each key names a condition the server transforms images for; its value selects the transformation applied. Omitted keys keep their default behavior, and an empty object is equivalent to omitting the field. |
ImageTransformationsParam
¶
Bases: BaseAPIType
ImageTransformationsParam from the Anthropic Messages API.
Configures the transformations the server applies to this image before the model observes it. Each key names a condition the server transforms images for; its value selects the transformation applied. Omitted keys keep their default behavior, and an empty object is equivalent to omitting the field.
URLImageSourceParam
¶
AssistantMessageParam
¶
CitationCharLocation
¶
CitationContentBlockLocation
¶
CitationContentBlockLocationParam
¶
CitationPageLocation
¶
CitationsSearchResultLocation
¶
CitationsWebSearchResultLocation
¶
ContainerParams
¶
Bases: BaseAPIType
Container parameters with skills to be loaded.
Attributes:
| Name | Type | Description |
|---|---|---|
skills |
Annotated[list[SkillParams] | None | MISSING, Field(title='Skills')]
|
Specification for a skill to be loaded in a container. |
ContentBlockSourceParam
¶
CreateMessageParams
¶
Bases: BaseAPIType
CreateMessageParams from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
container |
Annotated[ContainerParams | str | None | MISSING, Field(title='Container')]
|
Container parameters with skills to be loaded. |
diagnostics |
DiagnosticsParam | None | MISSING
|
Request-level diagnostics. |
DiagnosticsParam
¶
Bases: BaseAPIType
Request-level diagnostics.
Currently carries the previous response id for prompt-cache divergence reporting.
DocumentBlockParam
¶
JSONOutputFormatParam
¶
MessagesCreateWireBody
¶
Bases: BaseAPIType
MessagesCreateWireBody from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
container |
Annotated[ContainerParams | str | None | MISSING, Field(title='Container')]
|
Container parameters with skills to be loaded. |
diagnostics |
DiagnosticsParam | None | MISSING
|
Request-level diagnostics. |
MetadataParam
¶
OutputConfigParam
¶
RedactedThinkingBlock
¶
RedactedThinkingBlockParam
¶
SearchResultBlockParam
¶
SkillParams
¶
StreamMessageParams
¶
Bases: BaseAPIType
StreamMessageParams from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
container |
Annotated[ContainerParams | str | None | MISSING, Field(title='Container')]
|
Container parameters with skills to be loaded. |
diagnostics |
DiagnosticsParam | None | MISSING
|
Request-level diagnostics. |
SystemMessageParam
¶
TextBlock
¶
TextBlockParam
¶
ThinkingBlock
¶
ThinkingBlockParam
¶
ThinkingConfigAdaptiveParam
¶
ThinkingConfigDisabledParam
¶
ThinkingConfigEnabledParam
¶
ToolResultBlockParam
¶
UserMessageParam
¶
WebFetchBlockParam
¶
WebFetchToolResultBlockParam
¶
Base64PDFSourceParam
¶
CacheControlEphemeralParam
¶
CitationCharLocationParam
¶
CitationPageLocationParam
¶
CitationsConfigParam
¶
CitationSearchResultLocationParam
¶
CitationWebSearchResultLocationParam
¶
ContainerUploadBlockParam
¶
Bases: BaseAPIType
ContainerUploadBlockParam from the Anthropic Messages API.
A content block that represents a file to be uploaded to the container Files uploaded via this block will be available in the container's input directory.
PlainTextSourceParam
¶
URLPDFSourceParam
¶
Base64PDFSource
¶
BashCodeExecutionOutputBlock
¶
BashCodeExecutionOutputBlockParam
¶
BashCodeExecutionResultBlock
¶
BashCodeExecutionResultBlockParam
¶
BashCodeExecutionToolResultBlock
¶
BashCodeExecutionToolResultBlockParam
¶
BashCodeExecutionToolResultErrorObject
¶
BashCodeExecutionToolResultErrorParam
¶
BrowserCloseTabConfigParam
¶
BrowserDoubleClickConfigParam
¶
BrowserFindConfigParam
¶
BrowserFormInputConfigParam
¶
BrowserGetPageTextConfigParam
¶
BrowserHoldKeyConfigParam
¶
BrowserHoverConfigParam
¶
BrowserJavascriptExecConfigParam
¶
BrowserKeyConfigParam
¶
BrowserLeftClickConfigParam
¶
BrowserLeftClickDragConfigParam
¶
BrowserLeftMouseDownConfigParam
¶
BrowserLeftMouseUpConfigParam
¶
BrowserListTabsConfigParam
¶
BrowserMiddleClickConfigParam
¶
BrowserMouseMoveConfigParam
¶
BrowserNavigateConfigParam
¶
BrowserNewTabConfigParam
¶
BrowserReadConsoleConfigParam
¶
BrowserReadNetworkConfigParam
¶
BrowserReadPageConfigParam
¶
BrowserRightClickConfigParam
¶
BrowserScreenshotConfigParam
¶
BrowserScrollConfigParam
¶
BrowserScrollToConfigParam
¶
BrowserStateBlockParam
¶
Bases: BaseAPIType
BrowserStateBlockParam from the Anthropic Messages API.
The caller's browser state after a browser toolset member call — the full inventory of open tabs, which tab is active, and any side effects (tabs opened, download state changes) the call produced.
At most one per tool_result, only on a non-error result
answering a
browser toolset member tool_use. The server renders the
model-visible
text from it; the model never sees the raw fields.
Attributes:
| Name | Type | Description |
|---|---|---|
tabs |
Annotated[list[BrowserStateTabEntryParam], Field(title='Tabs')]
|
One open browser tab reported in a |
BrowserStateChangeDownloadCompletedParam
¶
Bases: BaseAPIType
BrowserStateChangeDownloadCompletedParam.
A file download that finished during this call, reported with the
same
download_id as its download_started — or without a prior
download_started, when the download finished during the call
that
started it (at most one state change per download_id per
result).
BrowserStateChangeDownloadFailedParam
¶
Bases: BaseAPIType
BrowserStateChangeDownloadFailedParam.
A file download that failed — or was cancelled — during this call.
BrowserStateChangeDownloadStartedParam
¶
BrowserStateChangeTabOpenedParam
¶
Bases: BaseAPIType
BrowserStateChangeTabOpenedParam.
A tab this call's execution opened that remains open at its end —
the
creation delta of the tabs inventory, not an event log.
Carries only the tab_id; the tab's title and url live on
its
tabs entry, which must include the same tab_id. A tab opened
during
a failed call gets no deferred tab_opened; it simply appears in
the
next result's tabs inventory.
BrowserStateTabEntryParam
¶
Bases: BaseAPIType
BrowserStateTabEntryParam from the Anthropic Messages API.
One open browser tab reported in a browser_state block's tabs
inventory.
tab_id is the caller-assigned identifier for the tab; title
and
url describe the page the tab is currently showing and may be
empty
strings (a blank tab legitimately has both empty). active marks
the
tab that is active after this call; whenever tabs is non-empty,
exactly one entry is marked.
BrowserSwitchTabConfigParam
¶
BrowserToolset20260801Param
¶
Bases: BaseAPIType
BrowserToolset20260801Param from the Anthropic Messages API.
The browser toolset: a single tools[] entry (carrying no
name)
that declares the browser tool family. The model is served the
family's
tool with any members disabled via configs removed from its
schema.
Attributes:
| Name | Type | Description |
|---|---|---|
configs |
BrowserToolsetConfigsParam | None | MISSING
|
Per-member configuration for
|
BrowserToolsetConfigsParam
¶
Bases: BaseAPIType
BrowserToolsetConfigsParam from the Anthropic Messages API.
Per-member configuration for browser_toolset_20260801: one
optional
field per member tool, keyed by the member name — the same name
the
member's tool_use blocks carry. Every member is an accepted
key,
and a member's defaults apply wherever its key is absent. Unknown
keys
are rejected: the field set is this toolset version's complete
member
set.
Attributes:
| Name | Type | Description |
|---|---|---|
close_tab |
BrowserCloseTabConfigParam | None | MISSING
|
|
double_click |
BrowserDoubleClickConfigParam | None | MISSING
|
|
file_upload |
BrowserFileUploadConfigParam | None | MISSING
|
|
find |
BrowserFindConfigParam | None | MISSING
|
|
form_input |
BrowserFormInputConfigParam | None | MISSING
|
|
get_page_text |
BrowserGetPageTextConfigParam | None | MISSING
|
|
hold_key |
BrowserHoldKeyConfigParam | None | MISSING
|
|
hover |
BrowserHoverConfigParam | None | MISSING
|
|
javascript_exec |
BrowserJavascriptExecConfigParam | None | MISSING
|
|
key |
BrowserKeyConfigParam | None | MISSING
|
|
left_click |
BrowserLeftClickConfigParam | None | MISSING
|
|
left_click_drag |
BrowserLeftClickDragConfigParam | None | MISSING
|
|
left_mouse_down |
BrowserLeftMouseDownConfigParam | None | MISSING
|
|
left_mouse_up |
BrowserLeftMouseUpConfigParam | None | MISSING
|
|
list_tabs |
BrowserListTabsConfigParam | None | MISSING
|
|
middle_click |
BrowserMiddleClickConfigParam | None | MISSING
|
|
mouse_move |
BrowserMouseMoveConfigParam | None | MISSING
|
|
navigate |
BrowserNavigateConfigParam | None | MISSING
|
|
new_tab |
BrowserNewTabConfigParam | None | MISSING
|
|
read_console |
BrowserReadConsoleConfigParam | None | MISSING
|
|
read_network |
BrowserReadNetworkConfigParam | None | MISSING
|
|
read_page |
BrowserReadPageConfigParam | None | MISSING
|
|
right_click |
BrowserRightClickConfigParam | None | MISSING
|
|
screenshot |
BrowserScreenshotConfigParam | None | MISSING
|
|
scroll |
BrowserScrollConfigParam | None | MISSING
|
|
scroll_to |
BrowserScrollToConfigParam | None | MISSING
|
|
switch_tab |
BrowserSwitchTabConfigParam | None | MISSING
|
|
triple_click |
BrowserTripleClickConfigParam | None | MISSING
|
|
type |
BrowserTypeConfigParam | None | MISSING
|
|
wait |
BrowserWaitConfigParam | None | MISSING
|
|
zoom |
BrowserZoomConfigParam | None | MISSING
|
|
BrowserTripleClickConfigParam
¶
BrowserTypeConfigParam
¶
BrowserWaitConfigParam
¶
BrowserZoomConfigParam
¶
CitationsConfig
¶
CodeExecutionOutputBlock
¶
CodeExecutionOutputBlockParam
¶
CodeExecutionResultBlock
¶
CodeExecutionResultBlockParam
¶
CodeExecutionTool20250522Param
¶
CodeExecutionTool20250825Param
¶
CodeExecutionTool20260120Param
¶
Bases: BaseAPIType
CodeExecutionTool20260120Param from the Anthropic Messages API.
A tools entry for the code execution tool, version
code_execution_20260120.
It adds REPL state persistence to version
code_execution_20250825.
REPL state persistence applies with programmatic tool calling. With it, the Python interpreter state, such as variable bindings, persists across requests that reuse the container.
See the code execution tool guide to learn what each tool version adds.
CodeExecutionTool20260521Param
¶
CodeExecutionToolResultBlock
¶
Bases: BaseAPIType
CodeExecutionToolResultBlock from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
Annotated[CodeExecutionToolResultErrorObject | CodeExecutionResultBlock | EncryptedCodeExecutionResultBlock, Field(title='Content')]
|
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form. |
CodeExecutionToolResultBlockParam
¶
Bases: BaseAPIType
CodeExecutionToolResultBlockParam.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
Annotated[CodeExecutionToolResultErrorParam | CodeExecutionResultBlockParam | EncryptedCodeExecutionResultBlockParam, Field(title='Content')]
|
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form, sent back in a later request. |
CodeExecutionToolResultErrorObject
¶
CodeExecutionToolResultErrorParam
¶
ComputerCursorPositionConfigParam
¶
ComputerDoubleClickConfigParam
¶
ComputerHoldKeyConfigParam
¶
ComputerKeyConfigParam
¶
ComputerLeftClickConfigParam
¶
ComputerLeftClickDragConfigParam
¶
ComputerLeftMouseDownConfigParam
¶
ComputerLeftMouseUpConfigParam
¶
ComputerMiddleClickConfigParam
¶
ComputerMouseMoveConfigParam
¶
ComputerRightClickConfigParam
¶
ComputerScreenshotConfigParam
¶
ComputerScrollConfigParam
¶
ComputerToolset20260801Param
¶
Bases: BaseAPIType
ComputerToolset20260801Param from the Anthropic Messages API.
The computer toolset: a single tools[] entry (carrying no
name)
that declares the computer tool family. The model is served the
family's tool with any members disabled via configs removed
from
its schema. Every member is enabled by default, zoom included.
The
single-tool options display_number and enable_zoom are
not
fields of a toolset entry — it carries only type,
configs, and
cache_control; zoom is controlled via
configs.zoom.enabled.
Attributes:
| Name | Type | Description |
|---|---|---|
configs |
ComputerToolsetConfigsParam | None | MISSING
|
Per-member configuration for
|
ComputerToolsetConfigsParam
¶
Bases: BaseAPIType
ComputerToolsetConfigsParam from the Anthropic Messages API.
Per-member configuration for computer_toolset_20260801: one
optional field per member tool, keyed by the member name — the
same
name the member's tool_use blocks carry. Every member is an
accepted key, and a member's defaults apply wherever its key is
absent.
Unknown keys are rejected: the field set is this toolset
version's
complete member set.
Attributes:
| Name | Type | Description |
|---|---|---|
cursor_position |
ComputerCursorPositionConfigParam | None | MISSING
|
|
double_click |
ComputerDoubleClickConfigParam | None | MISSING
|
|
hold_key |
ComputerHoldKeyConfigParam | None | MISSING
|
|
key |
ComputerKeyConfigParam | None | MISSING
|
|
left_click |
ComputerLeftClickConfigParam | None | MISSING
|
|
left_click_drag |
ComputerLeftClickDragConfigParam | None | MISSING
|
|
left_mouse_down |
ComputerLeftMouseDownConfigParam | None | MISSING
|
|
left_mouse_up |
ComputerLeftMouseUpConfigParam | None | MISSING
|
|
middle_click |
ComputerMiddleClickConfigParam | None | MISSING
|
|
mouse_move |
ComputerMouseMoveConfigParam | None | MISSING
|
|
right_click |
ComputerRightClickConfigParam | None | MISSING
|
|
screenshot |
ComputerScreenshotConfigParam | None | MISSING
|
|
scroll |
ComputerScrollConfigParam | None | MISSING
|
|
triple_click |
ComputerTripleClickConfigParam | None | MISSING
|
|
type |
ComputerTypeConfigParam | None | MISSING
|
|
wait |
ComputerWaitConfigParam | None | MISSING
|
|
zoom |
ComputerZoomConfigParam | None | MISSING
|
|
ComputerTripleClickConfigParam
¶
ComputerTypeConfigParam
¶
ComputerWaitConfigParam
¶
ComputerZoomConfigParam
¶
DirectCaller
¶
DirectCallerParam
¶
DocumentBlock
¶
EncryptedCodeExecutionResultBlock
¶
Bases: BaseAPIType
EncryptedCodeExecutionResultBlock.
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form.
The API returns this block in place of code_execution_result
when the
code called the web search tool.
See the programmatic tool calling guide to learn more about programmatic tool calling.
EncryptedCodeExecutionResultBlockParam
¶
Bases: BaseAPIType
EncryptedCodeExecutionResultBlockParam.
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form, sent back in a later request.
InputSchemaTyped
¶
Bases: BaseAPIType
InputSchemaTyped from the Anthropic Messages API.
JSON schema for this tool's input.
This defines the shape of the input that your tool accepts and
that
the model will produce.
MemoryTool20250818Param
¶
PlainTextSource
¶
ServerToolCaller
¶
ServerToolCaller20260120
¶
ServerToolCaller20260120Param
¶
ServerToolCallerParam
¶
ServerToolUseBlock
¶
ServerToolUseBlockParam
¶
TextEditorCodeExecutionCreateResultBlock
¶
TextEditorCodeExecutionCreateResultBlockParam
¶
TextEditorCodeExecutionStrReplaceResultBlock
¶
TextEditorCodeExecutionStrReplaceResultBlockParam
¶
TextEditorCodeExecutionToolResultBlock
¶
TextEditorCodeExecutionToolResultBlockParam
¶
TextEditorCodeExecutionToolResultErrorObject
¶
TextEditorCodeExecutionToolResultErrorParam
¶
TextEditorCodeExecutionViewResultBlock
¶
TextEditorCodeExecutionViewResultBlockParam
¶
ThinkingConfigBetweenToolsParam
¶
ToolBash20250124Param
¶
ToolChoiceAnyParam
¶
ToolChoiceAutoParam
¶
ToolChoiceNoneParam
¶
ToolChoiceToolParam
¶
ToolParam
¶
Bases: BaseAPIType
ToolParam from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
input_schema |
Annotated[InputSchemaTyped | dict[str, Any], Field(title='Input Schema')]
|
JSON schema for this tool's input. |
ToolReferenceBlock
¶
ToolReferenceBlockParam
¶
ToolSearchToolBm2520251119Param
¶
ToolSearchToolRegex20251119Param
¶
ToolSearchToolResultBlock
¶
ToolSearchToolResultBlockParam
¶
ToolSearchToolResultErrorObject
¶
ToolSearchToolResultErrorParam
¶
ToolSearchToolSearchResultBlock
¶
ToolSearchToolSearchResultBlockParam
¶
Bases: BaseAPIType
ToolSearchToolSearchResultBlockParam.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_references |
Annotated[list[ToolReferenceBlockParam], Field(title='Tool References')]
|
Tool reference block that can be included in tool_result content. |
ToolTextEditor20250124Param
¶
ToolTextEditor20250429Param
¶
ToolTextEditor20250728Param
¶
ToolUseBlock
¶
ToolUseBlockParam
¶
UserLocationParam
¶
WebFetchBlock
¶
WebFetchTool20250910Param
¶
Bases: BaseAPIType
WebFetchTool20250910Param from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
url_sources |
WebFetchURLSourcesParam | None | MISSING
|
Which sources contribute to the set of URLs web fetch may fetch. |
WebFetchTool20260209Param
¶
Bases: BaseAPIType
WebFetchTool20260209Param from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
url_sources |
WebFetchURLSourcesParam | None | MISSING
|
Which sources contribute to the set of URLs web fetch may fetch. |
WebFetchTool20260309Param
¶
Bases: BaseAPIType
WebFetchTool20260309Param from the Anthropic Messages API.
Web fetch tool with use_cache parameter for bypassing cached content.
Attributes:
| Name | Type | Description |
|---|---|---|
url_sources |
WebFetchURLSourcesParam | None | MISSING
|
Which sources contribute to the set of URLs web fetch may fetch. |
WebFetchTool20260318Param
¶
Bases: BaseAPIType
WebFetchTool20260318Param from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
url_sources |
WebFetchURLSourcesParam | None | MISSING
|
Which sources contribute to the set of URLs web fetch may fetch. |
WebFetchToolResultBlock
¶
WebFetchToolResultErrorBlock
¶
WebFetchToolResultErrorBlockParam
¶
WebFetchURLSourceAllParam
¶
Bases: BaseAPIType
WebFetchURLSourceAllParam from the Anthropic Messages API.
The url_sources variant under which a source contributes in
full:
every result of the tool filter's source, or all user input.
WebFetchURLSourceExceptParam
¶
Bases: BaseAPIType
WebFetchURLSourceExceptParam from the Anthropic Messages API.
The tool filter variant under which every result but the named tools' contributes.
Attributes:
| Name | Type | Description |
|---|---|---|
tools |
Annotated[list[WebFetchURLSourceToolReferenceParam], Field(title='Tools')]
|
One entry of a tool filter's |
WebFetchURLSourceNoneParam
¶
Bases: BaseAPIType
WebFetchURLSourceNoneParam from the Anthropic Messages API.
The url_sources variant under which a source contributes
nothing:
no result of the tool filter's source, or no user input.
WebFetchURLSourceOnlyParam
¶
Bases: BaseAPIType
WebFetchURLSourceOnlyParam from the Anthropic Messages API.
The tool filter variant under which only the named tools' results contribute.
Attributes:
| Name | Type | Description |
|---|---|---|
tools |
Annotated[list[WebFetchURLSourceToolReferenceParam], Field(title='Tools')]
|
One entry of a tool filter's |
WebFetchURLSourcesParam
¶
Bases: BaseAPIType
Which sources contribute to the set of URLs web fetch may fetch.
Each key is a tagged variant: user_input is all or
none;
the two tool filters are all, none, only (only the
named
tools' results) or except (every result but the named
tools'). A
named tool must be declared in this request's tools[].
WebFetchURLSourceToolReferenceParam
¶
Bases: BaseAPIType
WebFetchURLSourceToolReferenceParam.
One entry of a tool filter's tools: it must name a tool
declared in
this request's tools[].
WebSearchResultBlock
¶
WebSearchResultBlockParam
¶
WebSearchTool20250305Param
¶
WebSearchTool20260209Param
¶
WebSearchTool20260318Param
¶
WebSearchToolRequestErrorObjectParam
¶
WebSearchToolResultBlock
¶
WebSearchToolResultBlockParam
¶
WebSearchToolResultErrorObject
¶
adapters
¶
Anthropic's adapters between shared types and its methods.
Modules:
| Name | Description |
|---|---|
conversions |
Conversions of Anthropic's Messages types into shared types. |
files |
Adapter of shared files to Anthropic's Files API. |
generation |
Adapter of shared generation to Anthropic's Messages API. |
Classes:
| Name | Description |
|---|---|
AnthropicFilesAdapter |
Stores files with Anthropic's |
AnthropicGenerationAdapter |
Generates text with |
Functions:
| Name | Description |
|---|---|
message_text |
Join the text of a message. |
message_thinking |
Join the thinking of a message. |
message_tool_calls |
Collect the tool calls of a message. |
AnthropicFilesAdapter
¶
AnthropicFilesAdapter(
*, page_size: int = DEFAULT_PAGE_SIZE
)
Bases: BaseFilesAdapter[FileMetadata, ListFilesResponse]
Stores files with Anthropic's /files.
expires_in_seconds is sent as it is. The list goes newest first,
page_size files a request, by the opaque next_page. Uploads
take no provider options.
Attributes:
| Name | Type | Description |
|---|---|---|
page_size |
Files asked for in one page of the list, 1 to 1000. |
Example
files = FilesResource(session, AnthropicFilesAdapter()) stored = await files.upload(Path("report.pdf"))
Store the page size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_size
|
int
|
Files asked for in one page of the list. |
DEFAULT_PAGE_SIZE
|
Methods:
| Name | Description |
|---|---|
with_options |
Check that no option is given; Anthropic's uploads take none. |
to_upload_method |
Build the method that stores a file. |
to_retrieve_method |
Build the method that reads a file's metadata. |
to_list_method |
Build the method that reads one page of the stored files. |
to_page |
Take the files of a page and where the next one starts. |
to_delete_method |
Build the method that deletes a file. |
to_download_method |
Build the method that streams a file's content. |
to_stored_file |
Convert Anthropic's file metadata into the shared metadata. |
with_options
¶
with_options(options: NoProviderOptions) -> Self
Check that no option is given; Anthropic's uploads take none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
NoProviderOptions
|
The call's provider options, which must be empty. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the adapter. |
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
A key is given. |
to_upload_method
¶
to_upload_method(request: FileUpload) -> CreateFile
Build the method that stores a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FileUpload
|
The shared upload. |
required |
Returns:
| Type | Description |
|---|---|
CreateFile
|
|
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
Anthropic cannot take the upload, such as an expiry outside 3600 to 7 776 000 seconds. |
to_retrieve_method
¶
to_retrieve_method(file_id: str) -> RetrieveFile
Build the method that reads a file's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
Anthropic's id of the file. |
required |
Returns:
| Type | Description |
|---|---|
RetrieveFile
|
|
to_list_method
¶
to_page
¶
to_page(
raw: ListFilesResponse,
) -> tuple[Sequence[FileMetadata], str | None]
Take the files of a page and where the next one starts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
ListFilesResponse
|
The page. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Sequence[FileMetadata], str | None]
|
Its files and its |
to_delete_method
¶
to_delete_method(file_id: str) -> DeleteFile
Build the method that deletes a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
Anthropic's id of the file. |
required |
Returns:
| Type | Description |
|---|---|
DeleteFile
|
|
to_download_method
¶
to_download_method(file: ProviderFile) -> DownloadFile
Build the method that streams a file's content.
Anthropic keeps the files its code makes with the stored files,
so a ProducedFile of the Messages API downloads as any other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
ProviderFile
|
The file. |
required |
Returns:
| Type | Description |
|---|---|
DownloadFile
|
|
DownloadFile
|
( |
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
The file names a container
( |
to_stored_file
¶
to_stored_file(
raw: FileMetadata,
) -> StoredFile[FileMetadata]
Convert Anthropic's file metadata into the shared metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
FileMetadata
|
Anthropic's metadata. |
required |
Returns:
| Type | Description |
|---|---|
StoredFile[FileMetadata]
|
Its id, name, |
StoredFile[FileMetadata]
|
UTC. |
AnthropicGenerationAdapter
¶
AnthropicGenerationAdapter(
*,
default_max_tokens: int = DEFAULT_MAX_TOKENS,
input_conversion: IConversion[
str | Sequence[InputItem], list[dict[str, Any]]
] = INPUT_CONVERSION,
usage_conversion: IConversion[
Usage, TokenUsage
] = USAGE_CONVERSION,
stop_conversion: IConversion[
Message | Delta, Stop
] = STOP_CONVERSION,
)
Bases: BaseCompositeAdapter[GenerationRequest, Message, GenerationResponse[Message], MessageStreamEvent, GenerationEvent[MessageStreamEvent]]
Generates text with POST /messages.
A text input becomes one user turn, a list of turns the
messages as they are, and instructions the system
prompt. Anthropic requires max_tokens, so a request without
max_output_tokens gets default_max_tokens. A request that
Anthropic would reject raises RequestValidationError before
anything is sent, such as a conversation that does not end with a
user turn. end_user_id becomes metadata.user_id.
The conversions of the input, the token counts and the stop are keyword arguments, so any of them can be swapped without a subclass; a stream goes through the same ones as a message.
Attributes:
| Name | Type | Description |
|---|---|---|
default_max_tokens |
|
|
input_conversion |
Turns the shared |
|
usage_conversion |
Turns Anthropic's |
|
stop_conversion |
Tells how a message, or a stream, stopped. |
Example
generation = GenerationResource( ... session, AnthropicGenerationAdapter(default_max_tokens=4096) ... )
Store the default token limit and the conversions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_max_tokens
|
int
|
|
DEFAULT_MAX_TOKENS
|
input_conversion
|
IConversion[str | Sequence[InputItem], list[dict[str, Any]]]
|
Turns the shared |
INPUT_CONVERSION
|
usage_conversion
|
IConversion[Usage, TokenUsage]
|
Turns Anthropic's |
USAGE_CONVERSION
|
stop_conversion
|
IConversion[Message | Delta, Stop]
|
Tells how a message, or a stream, stopped. |
STOP_CONVERSION
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
with_options |
Return a copy that sends the options with every method. |
to_method |
Build the method that creates a message at once. |
to_response |
Convert a finished message. |
to_stream_method |
Build the method that streams a message. |
to_events |
Convert the events of a message stream. |
with_options
¶
with_options(options: AnthropicGenerationOptions) -> Self
Return a copy that sends the options with every method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
AnthropicGenerationOptions
|
Fields of |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the adapter; this one is left as it is. |
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
A key is not one of the options. |
to_method
¶
to_method(request: GenerationRequest) -> CreateMessage
Build the method that creates a message at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
GenerationRequest
|
The shared request. |
required |
Returns:
| Type | Description |
|---|---|
CreateMessage
|
|
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
Anthropic cannot take the request. |
to_response
¶
to_response(
raw: Message, request: GenerationRequest
) -> GenerationResponse[Message]
Convert a finished message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Message
|
Anthropic's message. |
required |
request
|
GenerationRequest
|
The request it answers. |
required |
Returns:
| Type | Description |
|---|---|
GenerationResponse[Message]
|
The generated text with its token counts, the calls of the |
GenerationResponse[Message]
|
built-in tools Anthropic ran ( |
GenerationResponse[Message]
|
sources its text cites ( |
GenerationResponse[Message]
|
made ( |
GenerationResponse[Message]
|
early, by |
GenerationResponse[Message]
|
|
GenerationResponse[Message]
|
refusal gets |
Raises:
| Type | Description |
|---|---|
APIResponseError
|
The message has no stop reason. |
to_stream_method
¶
to_stream_method(
request: GenerationRequest,
) -> StreamMessage
Build the method that streams a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
GenerationRequest
|
The shared request. |
required |
Returns:
| Type | Description |
|---|---|
StreamMessage
|
|
Raises:
| Type | Description |
|---|---|
RequestValidationError
|
Anthropic cannot take the request. |
to_events
async
¶
to_events(
items: AsyncIterator[MessageStreamEvent],
request: GenerationRequest,
) -> AsyncGenerator[GenerationEvent[MessageStreamEvent]]
Convert the events of a message stream.
Text deltas become TextDeltaEvent and non-empty thinking
deltas ReasoningDeltaEvent; a tool_use block becomes
ToolCallStartEvent, a ToolCallDeltaEvent per
input_json_delta and ToolCallDoneEvent at its
content_block_stop; a built-in tool's server_tool_use
block becomes a ServerToolCallEvent that starts the call and
its result block one that ends it; message_stop becomes
CompletedEvent with the counts and stop reason collected from
message_start and message_delta, the built-in tool calls,
citations and files, and the content as native; every other event
(the pieces of a built-in tool's input, citations) is an
OtherEvent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
AsyncIterator[MessageStreamEvent]
|
The events Anthropic sent. |
required |
request
|
GenerationRequest
|
The request the stream answers. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[GenerationEvent[MessageStreamEvent]]
|
One shared event per Anthropic event. |
Raises:
| Type | Description |
|---|---|
APIResponseError
|
|
message_text
¶
message_thinking
¶
message_tool_calls
¶
types
¶
Anthropic's own types and the options of a generation call.
Every module but options is written by aiollm-codegen through
scripts/generate_types.py; do not edit them by hand.
Modules:
| Name | Description |
|---|---|
events |
Provider events types generated from OpenAPI. |
files |
Provider files types generated from OpenAPI. |
messages |
Provider messages types generated from OpenAPI. |
options |
Anthropic's own options of a generation call. |
shared |
Provider shared types generated from OpenAPI. |
tools |
Provider tools types generated from OpenAPI. |
usage |
Provider usage types generated from OpenAPI. |
Classes:
| Name | Description |
|---|---|
AnthropicGenerationOptions |
Fields of |
ThinkingAdaptive |
The model decides how much it thinks. |
ThinkingBetweenTools |
Thinking only between tool calls. |
ThinkingDisabled |
No thinking, on the models that allow it. |
ThinkingEnabled |
Thinking with a fixed budget, on the models that take one. |
CitationsDelta |
|
Delta |
|
InputJSONDelta |
|
RawContentBlockDeltaEvent |
|
RawContentBlockStartEvent |
|
RawContentBlockStopEvent |
|
RawMessageDeltaEvent |
|
RawMessageStartEvent |
|
RawMessageStopEvent |
|
SignatureDelta |
|
TextDelta |
|
ThinkingDelta |
|
ContainerUploadBlock |
Response model for a file uploaded to the container. |
DeletedFile |
|
FileMetadata |
|
ListFilesResponse |
|
CacheMissMessagesChanged |
|
CacheMissModelChanged |
|
CacheMissPreviousMessageNotFound |
|
CacheMissSystemChanged |
|
CacheMissUnavailable |
A |
CitationContentBlockLocation |
|
Diagnostics |
|
Message |
|
RefusalStopDetails |
Structured information about a refusal. |
TextBlock |
|
CitationCharLocation |
|
CitationPageLocation |
|
CitationsSearchResultLocation |
|
CitationsWebSearchResultLocation |
|
Container |
|
ContainerSkill |
A skill that was loaded in a container (response model). |
RedactedThinkingBlock |
|
ThinkingBlock |
|
Base64PDFSource |
|
BashCodeExecutionOutputBlock |
|
BashCodeExecutionResultBlock |
|
BashCodeExecutionToolResultBlock |
|
BashCodeExecutionToolResultErrorObject |
|
CacheMissToolsChanged |
|
CitationsConfig |
|
CodeExecutionOutputBlock |
|
CodeExecutionResultBlock |
|
CodeExecutionToolResultBlock |
|
CodeExecutionToolResultErrorObject |
|
DirectCaller |
Tool invocation directly from the model. |
DocumentBlock |
|
EncryptedCodeExecutionResultBlock |
|
PlainTextSource |
|
ServerToolCaller |
Tool invocation generated by a server-side tool. |
ServerToolCaller20260120 |
|
ServerToolUseBlock |
|
TextEditorCodeExecutionCreateResultBlock |
|
TextEditorCodeExecutionStrReplaceResultBlock |
|
TextEditorCodeExecutionToolResultBlock |
|
TextEditorCodeExecutionToolResultErrorObject |
|
TextEditorCodeExecutionViewResultBlock |
|
ToolReferenceBlock |
|
ToolSearchToolResultBlock |
|
ToolSearchToolResultErrorObject |
|
ToolSearchToolSearchResultBlock |
|
ToolUseBlock |
|
WebFetchBlock |
|
WebFetchToolResultBlock |
|
WebFetchToolResultErrorBlock |
|
WebSearchResultBlock |
|
WebSearchToolResultBlock |
|
WebSearchToolResultErrorObject |
|
CacheCreation |
|
MessageDeltaUsage |
|
OutputTokensDetails |
|
ServerToolUsage |
|
Usage |
|
AnthropicGenerationOptions
¶
Bases: TypedDict
Fields of POST /v1/messages that the shared request does not hold.
Given to client.generation.create() or stream() as
provider_options; a key left out is not sent. Each key is a field
of CreateMessage, its value of the field's type or a TypedDict
with the same keys, so a dict literal type-checks; the method checks
the value.
Attributes:
| Name | Type | Description |
|---|---|---|
stop_sequences |
list[str]
|
Texts that stop generation. |
thinking |
ThinkingEnabled | ThinkingDisabled | ThinkingBetweenTools | ThinkingAdaptive
|
How the model thinks; |
Example
await client.generation.create( ... model="claude-opus-5-5", ... input="Count to ten", ... provider_options={"stop_sequences": ["5"]}, ... )
ThinkingAdaptive
¶
Bases: TypedDict
The model decides how much it thinks.
Mirrors ThinkingConfigAdaptiveParam as a TypedDict, so a dict
literal type-checks.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['adaptive']
|
Always |
display |
NotRequired[Literal['summarized', 'omitted'] | None]
|
Whether a summary of the thinking comes back. |
ThinkingBetweenTools
¶
ThinkingDisabled
¶
ThinkingEnabled
¶
Bases: TypedDict
Thinking with a fixed budget, on the models that take one.
Mirrors ThinkingConfigEnabledParam.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['enabled']
|
Always |
budget_tokens |
int
|
Tokens the model may spend on thinking. |
display |
NotRequired[Literal['summarized', 'omitted'] | None]
|
Whether a summary of the thinking comes back. |
CitationsDelta
¶
Delta
¶
Bases: BaseAPITypeExtra
Delta from the Anthropic Messages API (upstream: Delta).
Attributes:
| Name | Type | Description |
|---|---|---|
container |
Container | None
|
Information about the container used in the request (for the code execution tool) |
stop_details |
RefusalStopDetails | None
|
Structured information about a refusal. |
InputJSONDelta
¶
RawContentBlockDeltaEvent
¶
RawContentBlockStartEvent
¶
Bases: BaseAPITypeExtra
RawContentBlockStartEvent from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
content_block |
Annotated[Annotated[Annotated[TextBlock, Tag('0')] | Annotated[ThinkingBlock, Tag('1')] | Annotated[RedactedThinkingBlock, Tag('2')] | Annotated[ToolUseBlock, Tag('3')] | Annotated[ServerToolUseBlock, Tag('4')] | Annotated[WebSearchToolResultBlock, Tag('5')] | Annotated[WebFetchToolResultBlock, Tag('6')] | Annotated[CodeExecutionToolResultBlock, Tag('7')] | Annotated[BashCodeExecutionToolResultBlock, Tag('8')] | Annotated[TextEditorCodeExecutionToolResultBlock, Tag('9')] | Annotated[ToolSearchToolResultBlock, Tag('10')] | Annotated[ContainerUploadBlock, Tag('11')] | Annotated[UnknownVariant, Tag(UNKNOWN)], Discriminator(by_type({'text': '0', 'thinking': '1', 'redacted_thinking': '2', 'tool_use': '3', 'server_tool_use': '4', 'web_search_tool_result': '5', 'web_fetch_tool_result': '6', 'code_execution_tool_result': '7', 'bash_code_execution_tool_result': '8', 'text_editor_code_execution_tool_result': '9', 'tool_search_tool_result': '10', 'container_upload': '11'}))], Field(title='Content Block')]
|
Response model for a file uploaded to the container. |
RawContentBlockStopEvent
¶
RawMessageDeltaEvent
¶
RawMessageStartEvent
¶
RawMessageStopEvent
¶
SignatureDelta
¶
TextDelta
¶
ThinkingDelta
¶
ContainerUploadBlock
¶
DeletedFile
¶
Bases: BaseAPITypeExtra
DeletedFile from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Annotated[Literal['file_deleted'], Field(description='Deleted object type. For file deletion, this is always `"file_deleted"`.')]
|
Deleted object type. For file deletion, this is always
|
id |
Annotated[str, Field(description='ID of the deleted file.')]
|
ID of the deleted file. |
FileMetadata
¶
Bases: BaseAPITypeExtra
FileMetadata from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Annotated[Literal['file'], Field(description='Object type. For files, this is always `"file"`.')]
|
Object type. For files, this is always |
id |
Annotated[str, Field(description='Unique object identifier. The format and length of IDs may change over time.')]
|
Unique object identifier. The format and length of IDs may change over time. |
created_at |
Annotated[AwareDatetime, Field(description='RFC 3339 datetime string representing when the file was created.')]
|
RFC 3339 datetime string representing when the file was created. |
filename |
Annotated[str, Field(description='Original filename of the uploaded file.', max_length=500, min_length=1)]
|
Original filename of the uploaded file. |
mime_type |
Annotated[str, Field(description='MIME type of the file.', max_length=255, min_length=1)]
|
MIME type of the file. |
size_bytes |
Annotated[int, Field(description='Size of the file in bytes.', ge=0)]
|
Size of the file in bytes. |
downloadable |
Annotated[bool, Field(description='Whether the file can be downloaded.')]
|
Whether the file can be downloaded. |
expires_at |
Annotated[AwareDatetime | None, Field(description='RFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.')]
|
RFC 3339 datetime string representing when the
file will expire and become unavailable for download.
Null if the file does not expire. For files uploaded with
|
ListFilesResponse
¶
Bases: BaseAPITypeExtra
ListFilesResponse from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Annotated[list[FileMetadata], Field(description='List of file metadata objects.')]
|
List of file metadata objects. |
next_page |
Annotated[str | None, Field(description='Opaque cursor for the next page. Supply as `?page=` to fetch the next page; null when there are no more results.')]
|
Opaque cursor for the next page. Supply as
|
CacheMissMessagesChanged
¶
Bases: BaseAPITypeExtra
CacheMissMessagesChanged from the Anthropic Messages API.
A cache_miss_reason for a request whose messages differ from
the
previous request's in an earlier entry, instead of only having
entries
appended. The model, system, and tools match.
See the cache diagnostics guide to learn what to change for each reason.
CacheMissModelChanged
¶
Bases: BaseAPITypeExtra
CacheMissModelChanged from the Anthropic Messages API.
A cache_miss_reason for a request whose model or speed
differs
from the previous request's.
See the cache diagnostics guide to learn what to change for each reason.
CacheMissPreviousMessageNotFound
¶
Bases: BaseAPITypeExtra
CacheMissPreviousMessageNotFound.
A cache_miss_reason for when the API doesn't have a stored
record of
the request that diagnostics.previous_message_id references.
This doesn't mean that this request changed.
See the cache diagnostics guide to learn what to change for each reason.
CacheMissSystemChanged
¶
Bases: BaseAPITypeExtra
CacheMissSystemChanged from the Anthropic Messages API.
A cache_miss_reason for a request whose system differs from
the
previous request's.
See the cache diagnostics guide to learn what to change for each reason.
CacheMissUnavailable
¶
Bases: BaseAPITypeExtra
A cache_miss_reason for when the API can't give a diagnosis.
The request itself was processed normally.
This includes a request whose model, system, and tools
match the
previous request's but whose other prompt-affecting parameters,
such as
thinking or tool_choice, differ.
See the cache diagnostics guide to learn what to change for each reason.
CitationContentBlockLocation
¶
Diagnostics
¶
Bases: BaseAPITypeExtra
Diagnostics from the Anthropic Messages API.
Request-level diagnostics: why the prompt cache could not fully
reuse
the prefix of the request named by
diagnostics.previous_message_id.
Message
¶
Bases: BaseAPITypeExtra
Message from the Anthropic Messages API (upstream: Message).
Attributes:
| Name | Type | Description |
|---|---|---|
container |
Container | None
|
Information about the container used in the request (for the code execution tool) |
content |
Annotated[list[Annotated[Annotated[TextBlock, Tag('0')] | Annotated[ThinkingBlock, Tag('1')] | Annotated[RedactedThinkingBlock, Tag('2')] | Annotated[ToolUseBlock, Tag('3')] | Annotated[ServerToolUseBlock, Tag('4')] | Annotated[WebSearchToolResultBlock, Tag('5')] | Annotated[WebFetchToolResultBlock, Tag('6')] | Annotated[CodeExecutionToolResultBlock, Tag('7')] | Annotated[BashCodeExecutionToolResultBlock, Tag('8')] | Annotated[TextEditorCodeExecutionToolResultBlock, Tag('9')] | Annotated[ToolSearchToolResultBlock, Tag('10')] | Annotated[ContainerUploadBlock, Tag('11')] | Annotated[UnknownVariant, Tag(UNKNOWN)], Discriminator(by_type({'text': '0', 'thinking': '1', 'redacted_thinking': '2', 'tool_use': '3', 'server_tool_use': '4', 'web_search_tool_result': '5', 'web_fetch_tool_result': '6', 'code_execution_tool_result': '7', 'bash_code_execution_tool_result': '8', 'text_editor_code_execution_tool_result': '9', 'tool_search_tool_result': '10', 'container_upload': '11'}))]], Field(title='Content')]
|
Response model for a file uploaded to the container. |
diagnostics |
Diagnostics | None
|
Request-level diagnostics: why the prompt cache
could not fully reuse the prefix of the request named by
|
stop_details |
RefusalStopDetails | None
|
Structured information about a refusal. |
RefusalStopDetails
¶
TextBlock
¶
CitationCharLocation
¶
CitationPageLocation
¶
CitationsSearchResultLocation
¶
CitationsWebSearchResultLocation
¶
Container
¶
Bases: BaseAPITypeExtra
Container from the Anthropic Messages API.
Information about the container used in the request (for the code execution tool)
Attributes:
| Name | Type | Description |
|---|---|---|
skills |
Annotated[list[ContainerSkill] | None, Field(title='Skills')]
|
A skill that was loaded in a container (response model). |
ContainerSkill
¶
RedactedThinkingBlock
¶
ThinkingBlock
¶
Base64PDFSource
¶
BashCodeExecutionOutputBlock
¶
BashCodeExecutionResultBlock
¶
BashCodeExecutionToolResultBlock
¶
BashCodeExecutionToolResultErrorObject
¶
CacheMissToolsChanged
¶
Bases: BaseAPITypeExtra
CacheMissToolsChanged from the Anthropic Messages API.
A cache_miss_reason for a request whose tools differ from the
previous request's, for example because tools were added,
removed, or
reordered.
See the cache diagnostics guide to learn what to change for each reason.
CitationsConfig
¶
CodeExecutionOutputBlock
¶
CodeExecutionResultBlock
¶
CodeExecutionToolResultBlock
¶
Bases: BaseAPITypeExtra
CodeExecutionToolResultBlock from the Anthropic Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
Annotated[Annotated[Annotated[CodeExecutionToolResultErrorObject, Tag('0')] | Annotated[CodeExecutionResultBlock, Tag('1')] | Annotated[EncryptedCodeExecutionResultBlock, Tag('2')] | Annotated[UnknownVariant, Tag(UNKNOWN)], Discriminator(by_type({'code_execution_tool_result_error': '0', 'code_execution_result': '1', 'encrypted_code_execution_result': '2'}))], Field(title='Content')]
|
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form. |
CodeExecutionToolResultErrorObject
¶
DirectCaller
¶
DocumentBlock
¶
EncryptedCodeExecutionResultBlock
¶
Bases: BaseAPITypeExtra
EncryptedCodeExecutionResultBlock.
The output and exit code of Python code that Claude ran with the code execution tool, with standard output in encrypted form.
The API returns this block in place of code_execution_result
when the
code called the web search tool.
See the programmatic tool calling guide to learn more about programmatic tool calling.