Skip to main content

Crate adk_anthropic

Crate adk_anthropic 

Source
Expand description

§adk-anthropic

Dedicated Anthropic API client for ADK-Rust.

This crate provides the HTTP client, type system, SSE streaming, error handling, and backoff logic for interacting with the Anthropic API. Agent framework, CLI tools, chat session management, and observability are handled by other ADK crates.

Modules§

pricing
Token pricing for Anthropic models.

Structs§

AccumulatingStream
A stream wrapper that accumulates MessageStreamEvents into a complete Message.
Anthropic
Client for the Anthropic API with performance optimizations.
ApiError
An API error object for stream error events.
AutoCacheControl
Automatic cache control configuration.
Base64ImageSource
Represents a base64-encoded image source.
Base64PdfSource
Represents a base64-encoded PDF source.
BatchError
An error object returned in batch results.
BatchRequest
A batch request to be submitted.
BatchRequestCounts
Counts of batch requests in each processing state.
BatchResultItem
A single result item from a completed batch.
CacheControlEphemeral
CacheControlEphemeral specifies that content should be cached ephemerally.
CacheTtl
TTL configuration for cache control.
CitationCharLocation
Represents a character-based location citation.
CitationContentBlockLocation
Represents a content block-based location citation.
CitationPageLocation
Represents a page-based location citation.
CitationWebSearchResultLocation
Represents a web search result location citation.
CitationsConfig
Configuration for enabling or disabling citations in the response.
CitationsDelta
A delta representing a new citation in a streaming response
CodeExecutionResultBlock
Code execution tool output block.
CompactionMetadata
Metadata about a compaction event (emitted during SSE streaming).
ContainerInfo
Container information returned in message responses.
ContentBlockDeltaEvent
An event that represents a delta update to a content block in a streaming response.
ContentBlockSourceParam
Parameter for a content block source.
ContentBlockStartEvent
An event that represents the start of a content block in a streaming response.
ContentBlockStopEvent
An event that represents the end of a content block in a streaming response.
ContextManagement
Server-side context management configuration.
ContextManagementResponse
Response field showing which edits were applied.
DocumentBlock
Parameters for a document block.
ExponentialBackoff
FileObject
A file object returned by the Files API.
FileSource
A file source referencing a server-side file by ID.
ImageBlock
Parameters for an image block.
InputJsonDelta
A JSON delta, representing a piece of JSON in a streaming response.
LoggingStream
A stream wrapper that logs events and the final message through a ClientLogger.
Message
A message generated by the assistant.
MessageBatch
A message batch object returned by the Batches API.
MessageCountTokensParams
Parameters for counting tokens in messages.
MessageCreateParams
Parameters for creating messages.
MessageCreateTemplate
A template for creating message parameters.
MessageDelta
The delta information for a message delta event.
MessageDeltaEvent
An event that represents a delta update to a message in a streaming response.
MessageDeltaUsage
Message delta usage information.
MessageParam
Parameters for a message.
MessageStartEvent
An event that represents the start of a message in a streaming response.
MessageStopEvent
An event that represents the end of a message in a streaming response.
MessageTokensCount
Count of tokens in a message.
Metadata
Metadata that can be included with requests.
ModelCapabilities
Per-model capability flags.
ModelInfo
Information about a specific model.
ModelListParams
Parameters for listing models.
ModelListResponse
Response from the list models API endpoint.
OutputConfig
Wrapper for structured output configuration.
PaginatedList
A generic paginated list response.
PlainTextSource
A plain text source parameter for content blocks.
ProgrammaticToolUseBlock
Programmatic tool invocation from code execution.
RedactedThinkingBlock
A redacted thinking block that contains encoded/obscured thinking data.
ServerToolUsage
Information about server tool usage for a message.
ServerToolUseBlock
A block representing a server-side tool use request from the model.
SignatureDelta
A signature delta, representing a piece of a signature in a streaming response.
SkillObject
A skill object returned by the Skills API.
SkillRef
A reference to a skill for use in message requests.
TextBlock
A block of text content in a message.
TextDelta
A text delta, representing a piece of text in a streaming response.
ThinkingBlock
A block containing model thinking details.
ThinkingDelta
A thinking delta, representing a piece of thinking in a streaming response.
TokenThreshold
Threshold specification used in trigger / keep / clear_at_least.
ToolBash20241022
Parameters for the Bash tool type, version 20241022.
ToolBash20250124
Parameters for the Bash tool type, version 20250124.
ToolParam
Common parameters for a custom tool.
ToolResultBlock
A block containing the result of a tool execution.
ToolSearchConfig
Provider-level configuration for regex-based dynamic tool discovery.
ToolTextEditor20250124
Parameters for the Text Editor tool type, version 20250124.
ToolTextEditor20250429
Parameters for the Text Editor tool type, version 20250429.
ToolTextEditor20250728
Parameters for the Text Editor tool type, version 20250728.
ToolUseBlock
A block representing a tool use request from the model.
UrlImageSource
A source for an image from a URL.
UrlPdfSource
A source for a PDF from a URL.
Usage
Usage information for API calls.
UserLocation
Parameters for the user’s location.
WebSearchResultBlock
A block containing a web search result.
WebSearchTool20250305
Parameters for the web search tool.
WebSearchToolResultBlock
A block containing the results of a web search tool operation.
WebSearchToolResultError
An error that occurred when using the web search tool.

Enums§

AppliedEdit
A single applied edit in the response.
BatchResult
The result of a single batch request.
Citation
Represents a citation object that could be any of the supported citation types
Content
A content type that can be either a text block or an image block.
ContentBlock
A block of content in a message.
ContentBlockDelta
A raw content block delta, representing a streaming update to a content block.
ContentBlockSourceContent
The content of a content block source, which can be either a string or an array of content items.
ContextEdit
A single context editing strategy.
DocumentSource
The source type for a document block, which can be one of several types.
EffortLevel
Effort parameter controlling response thoroughness. Passed via output_config.effort. GA, no beta header required.
Error
The main error type for the adk-anthropic client.
ImageMediaType
Supported image media types
ImageSource
The source type for an image block, which can be either Base64 encoded, a URL, or a file reference.
KnownModel
Known Anthropic model versions.
MessageParamContent
The content of a message, which can be either a string or an array of content blocks.
MessageRole
Role type for a message parameter.
MessageStreamEvent
An event in a message stream.
Model
Represents an Anthropic model identifier.
ModelType
Type of the model object.
OutputFormat
Output format configuration for structured outputs.
ServerTool
Built-in server tool types with forward-compatible Unknown catch-all.
SpeedMode
Speed mode for latency-critical workloads (research preview).
StopReason
Reasons why the model stopped generating a response.
SystemPrompt
Represents either a string or an array of TextBlockParam for system prompts.
TextCitation
A citation reference in a TextBlock.
ThinkingConfig
Unified thinking configuration covering all modes.
ThinkingDisplay
Controls whether thinking content appears in the response.
ThinkingKeep
How many thinking turns to keep.
ToolChoice
Configuration for Claude’s tool choice behavior.
ToolResultBlockContent
The content of a tool result block, which can be either a string or an array of content items.
ToolUnionParam
Union type for different tool parameter types.
WebSearchErrorCode
Error codes that can be returned when a web search tool operation fails.
WebSearchToolResultBlockContent
Content of a web search tool result.

Constants§

MAX_CACHE_BREAKPOINTS
Maximum number of cache control breakpoints allowed by the API.

Traits§

ClientLogger
A trait for logging Anthropic client operations.
JsonSchema
Implement JsonSchema to derive the schema for GenerateRequest automatically.

Functions§

apply_cache_control_to_messages
Applies cache_control markers to the last content block of up to N user messages.
count_system_cache_controls
Count cache_control markers present in the system prompt.
merge_message_content
Merges new message content into existing message content.
prune_cache_controls_in_messages
Remove cache_control markers so the latest N remain in the request.
push_or_merge_message
Pushes a message to the messages vector, or merges it with the last message if they have the same role.

Type Aliases§

Result
A specialized Result type for adk-anthropic operations.