Skip to main content

Crate claudius

Crate claudius 

Source
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§

AccumulatingStream
A stream wrapper that accumulates MessageStreamEvents into a complete Message.
AgentStreamContext
Context for streaming agent output, including display label and nesting depth.
Anthropic
Client for the Anthropic API with performance optimizations.
Base64ImageSource
Represents a base64-encoded image source.
Base64PdfSource
Represents a base64-encoded PDF source.
BashPtyConfig
Configuration for spawning a new bash PTY session.
BashPtyResult
The result of running a single command in a BashPtySession.
BashPtySession
A persistent, PTY-backed bash session.
Budget
Budget Management System
CacheControlEphemeral
CacheControlEphemeral specifies that content should be ephemeral, meaning it should not be cached or persisted beyond the immediate request.
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
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.
DocumentBlock
Parameters for a document block.
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.
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.
ModelInfo
Information about a specific model.
ModelListParams
Parameters for listing models.
ModelListResponse
Response from the list models API endpoint.
Mount
A filesystem mount point with associated permissions.
MountHierarchy
Manages a hierarchy of filesystem mount points.
PlainTextRenderer
Plain text renderer with optional ANSI styling.
PlainTextSource
A plain text source parameter for content blocks.
PromptTestConfig
Configuration for a prompt test with support for inheritance and file references.
PromptTestResult
Result of running a prompt test.
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.
SseEvent
A raw server-sent event frame.
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.
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.
ToolSearchFileSystem
Tool for searching the local filesystem.
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.
TurnOutcome
Aggregated results from an agent turn.
TurnStep
Usage and request counts accumulated for a single step in a turn.
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§

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.
DocumentSource
The source type for a document block, which can be one of several types.
Error
The main error type for the Claudius SDK.
ImageMediaType
Supported image media types
ImageSource
The source type for an image block, which can be either Base64 encoded or a URL.
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.
Permissions
Permissions for filesystem mount points.
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
Configuration for enabling Claude’s extended thinking capabilities.
TokenKind
Token categories used for cost accounting.
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.

Traits§

Agent
Trait for implementing agents that interact with the Anthropic API.
ClientLogger
A trait for logging Anthropic client operations.
FileSystem
Trait for implementing filesystem operations.
IntermediateToolResult
Trait for intermediate tool results that can be passed between compute and apply phases.
JsonSchema
Implement JsonSchema to derive the schema for GenerateRequest automatically.
Renderer
Trait for rendering streaming output.
StreamContext
Stream context information for renderer output.
Tool
Trait for tools that can be used by agents.
ToolCallback
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 SseEvent into a Claudius MessageStreamEvent.
process_message_stream_sse
Process a stream of bytes into decoded Claudius MessageStreamEvent values.
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.
ToolResult
Result type for tool execution, using ControlFlow for early returns.