| Crates.io | anthropic-types |
| lib.rs | anthropic-types |
| version | 0.1.42 |
| created_at | 2025-05-01 21:04:30.752157+00 |
| updated_at | 2025-05-16 02:28:16.054011+00 |
| description | Type definitions for Anthropic API communication |
| homepage | |
| repository | https://github.com/colinrozzi/anthropic-types |
| max_upload_size | |
| id | 1656913 |
| size | 21,749 |
A Rust library containing type definitions for communicating with the Anthropic API.
This library provides a standardized set of types for working with the Anthropic API in Theater actors. It defines the structures needed for:
use anthropic_types::{
AnthropicRequest, CompletionRequest, Message, OperationType,
};
// Create a simple chat message
let message = Message::new_text("user", "Hello, Claude!");
// Build a completion request
let request = AnthropicRequest {
version: "1.0".to_string(),
operation_type: OperationType::ChatCompletion,
request_id: "req-12345".to_string(),
completion_request: Some(CompletionRequest {
model: "claude-3-7-sonnet-20250219".to_string(),
messages: vec![message],
max_tokens: Some(1024),
temperature: Some(0.7),
system: Some("You are a helpful assistant.".to_string()),
top_p: None,
anthropic_version: None,
tools: None,
tool_choice: None,
disable_parallel_tool_use: None,
additional_params: None,
}),
params: None,
};
// Serialize to JSON
let json = serde_json::to_string(&request).unwrap();
In your claude-chat actor, you can now use these types to communicate with the anthropic-proxy:
fn send_to_anthropic(
proxy_id: &str,
conversation_id: &str,
messages: &[ChatMessage],
system: Option<String>,
) -> Result<ChatMessage, String> {
// Convert our ChatMessage format to the AnthropicMessage format
let anthropic_messages: Vec<anthropic_types::Message> = messages
.iter()
.map(|msg| anthropic_types::Message::new_text(
&msg.role,
&msg.content
))
.collect();
// Build a properly structured request
let req = anthropic_types::AnthropicRequest {
version: "1.0".to_string(),
operation_type: anthropic_types::OperationType::ChatCompletion,
request_id: format!("req-{}", conversation_id),
completion_request: Some(anthropic_types::CompletionRequest {
model: "claude-3-7-sonnet-20250219".to_string(),
messages: anthropic_messages,
max_tokens: Some(1024),
temperature: Some(0.7),
system: system,
top_p: None,
anthropic_version: None,
tools: None,
tool_choice: None,
disable_parallel_tool_use: None,
additional_params: None,
}),
params: None,
};
// Serialize and send the request
// ...
}
messages.rs: Message types, requests, and responsesmodels.rs: Model information and pricingtools.rs: Tool definitions and parameterserrors.rs: Error types for Anthropic API operationsMIT