Expand description
Claudius: A Rust client for the Anthropic API.
This crate provides a comprehensive client implementation for interacting with Anthropic’s Claude AI models, including support for streaming responses, tool use, and agent-based interactions.
Modules§
- chat
- Chat application module for interactive conversations with Claude.
Structs§
- Accumulating
Stream - A stream wrapper that accumulates
MessageStreamEvents into a completeMessage. - Agent
Stream Context - Context for streaming agent output, including display label and nesting depth.
- Anthropic
- Client for the Anthropic API with performance optimizations.
- Base64
Image Source - Represents a base64-encoded image source.
- Base64
PdfSource - Represents a base64-encoded PDF source.
- Bash
PtyConfig - Configuration for spawning a new bash PTY session.
- Bash
PtyResult - The result of running a single command in a
BashPtySession. - Bash
PtySession - A persistent, PTY-backed bash session.
- Budget
- Budget Management System
- Cache
Control Ephemeral - CacheControlEphemeral specifies that content should be ephemeral, meaning it should not be cached or persisted beyond the immediate request.
- Citation
Char Location - Represents a character-based location citation.
- Citation
Content Block Location - Represents a content block-based location citation.
- Citation
Page Location - Represents a page-based location citation.
- Citation
WebSearch Result Location - Represents a web search result location citation.
- Citations
Config - Configuration for enabling or disabling citations in the response.
- Citations
Delta - A delta representing a new citation in a streaming response
- Content
Block Delta Event - An event that represents a delta update to a content block in a streaming response.
- Content
Block Source Param - Parameter for a content block source.
- Content
Block Start Event - An event that represents the start of a content block in a streaming response.
- Content
Block Stop Event - An event that represents the end of a content block in a streaming response.
- Document
Block - Parameters for a document block.
- Image
Block - Parameters for an image block.
- Input
Json Delta - A JSON delta, representing a piece of JSON in a streaming response.
- Logging
Stream - A stream wrapper that logs events and the final message through a
ClientLogger. - Message
- A message generated by the assistant.
- Message
Count Tokens Params - Parameters for counting tokens in messages.
- Message
Create Params - Parameters for creating messages.
- Message
Create Template - A template for creating message parameters.
- Message
Delta - The delta information for a message delta event.
- Message
Delta Event - An event that represents a delta update to a message in a streaming response.
- Message
Delta Usage - Message delta usage information.
- Message
Param - Parameters for a message.
- Message
Start Event - An event that represents the start of a message in a streaming response.
- Message
Stop Event - An event that represents the end of a message in a streaming response.
- Message
Tokens Count - Count of tokens in a message.
- Metadata
- Metadata that can be included with requests.
- Model
Info - Information about a specific model.
- Model
List Params - Parameters for listing models.
- Model
List Response - Response from the list models API endpoint.
- Mount
- A filesystem mount point with associated permissions.
- Mount
Hierarchy - Manages a hierarchy of filesystem mount points.
- Plain
Text Renderer - Plain text renderer with optional ANSI styling.
- Plain
Text Source - A plain text source parameter for content blocks.
- Prompt
Test Config - Configuration for a prompt test with support for inheritance and file references.
- Prompt
Test Result - Result of running a prompt test.
- Redacted
Thinking Block - A redacted thinking block that contains encoded/obscured thinking data.
- Server
Tool Usage - Information about server tool usage for a message.
- Server
Tool UseBlock - A block representing a server-side tool use request from the model.
- Signature
Delta - A signature delta, representing a piece of a signature in a streaming response.
- SseEvent
- A raw server-sent event frame.
- Text
Block - A block of text content in a message.
- Text
Delta - A text delta, representing a piece of text in a streaming response.
- Thinking
Block - A block containing model thinking details.
- Thinking
Delta - A thinking delta, representing a piece of thinking in a streaming response.
- Tool
Bash20241022 - Parameters for the Bash tool type, version 20241022.
- Tool
Bash20250124 - Parameters for the Bash tool type, version 20250124.
- Tool
Param - Common parameters for a custom tool.
- Tool
Result Block - A block containing the result of a tool execution.
- Tool
Search File System - Tool for searching the local filesystem.
- Tool
Text Editor20250124 - Parameters for the Text Editor tool type, version 20250124.
- Tool
Text Editor20250429 - Parameters for the Text Editor tool type, version 20250429.
- Tool
Text Editor20250728 - Parameters for the Text Editor tool type, version 20250728.
- Tool
UseBlock - A block representing a tool use request from the model.
- Turn
Outcome - Aggregated results from an agent turn.
- Turn
Step - Usage and request counts accumulated for a single step in a turn.
- UrlImage
Source - A source for an image from a URL.
- UrlPdf
Source - A source for a PDF from a URL.
- Usage
- Usage information for API calls.
- User
Location - Parameters for the user’s location.
- WebSearch
Result Block - A block containing a web search result.
- WebSearch
Tool20250305 - Parameters for the web search tool.
- WebSearch
Tool Result Block - A block containing the results of a web search tool operation.
- WebSearch
Tool Result Error - An error that occurred when using the web search tool.
Enums§
- 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.
- Content
Block - A block of content in a message.
- Content
Block Delta - A raw content block delta, representing a streaming update to a content block.
- Content
Block Source Content - The content of a content block source, which can be either a string or an array of content items.
- Document
Source - The source type for a document block, which can be one of several types.
- Error
- The main error type for the Claudius SDK.
- Image
Media Type - Supported image media types
- Image
Source - The source type for an image block, which can be either Base64 encoded or a URL.
- Known
Model - Known Anthropic model versions
- Message
Param Content - The content of a message, which can be either a string or an array of content blocks.
- Message
Role - Role type for a message parameter.
- Message
Stream Event - An event in a message stream.
- Model
- Represents an Anthropic model identifier.
- Model
Type - Type of the model object.
- Output
Format - Output format configuration for structured outputs.
- Permissions
- Permissions for filesystem mount points.
- Stop
Reason - Reasons why the model stopped generating a response.
- System
Prompt - Represents either a string or an array of TextBlockParam for system prompts.
- Text
Citation - A citation reference in a TextBlock.
- Thinking
Config - Configuration for enabling Claude’s extended thinking capabilities.
- Token
Kind - Token categories used for cost accounting.
- Tool
Choice - Configuration for Claude’s tool choice behavior.
- Tool
Result Block Content - The content of a tool result block, which can be either a string or an array of content items.
- Tool
Union Param - Union type for different tool parameter types.
- WebSearch
Error Code - Error codes that can be returned when a web search tool operation fails.
- WebSearch
Tool Result Block Content - Content of a web search tool result.
Traits§
- Agent
- Trait for implementing agents that interact with the Anthropic API.
- Client
Logger - A trait for logging Anthropic client operations.
- File
System - Trait for implementing filesystem operations.
- Intermediate
Tool Result - Trait for intermediate tool results that can be passed between compute and apply phases.
- Json
Schema - Implement JsonSchema to derive the schema for GenerateRequest automatically.
- Renderer
- Trait for rendering streaming output.
- Stream
Context - Stream context information for renderer output.
- Tool
- Trait for tools that can be used by agents.
- Tool
Callback - Callback trait for implementing tool execution logic.
Functions§
- assert_
contains - Assert that a prompt test result contains specific text.
- assert_
max_ length - Assert that a prompt test result has a maximum length.
- assert_
min_ length - Assert that a prompt test result has a minimum length.
- assert_
not_ contains - Assert that a prompt test result does not contain specific text.
- assert_
test_ passed - Assert that all built-in assertions in the test config passed.
- merge_
message_ content - Merges new message content into existing message content.
- parse_
message_ stream_ event - Decode a raw
SseEventinto a ClaudiusMessageStreamEvent. - process_
message_ stream_ sse - Process a stream of bytes into decoded Claudius
MessageStreamEventvalues. - process_
sse - Process a stream of bytes into a stream of raw server-sent events with production hardening.
- push_
or_ merge_ message - Pushes a message to the messages vector, or merges it with the last message if they have the same role.
- register_
biometrics - Register this crate’s biometrics with the provided collector.
- test_
prompt - Helper function for unit tests - runs a prompt test and returns the result.
Type Aliases§
- Result
- A specialized Result type for Claudius operations.
- Tool
Result - Result type for tool execution, using ControlFlow for early returns.