Expand description
§anyllm_client
Async HTTP client for Anthropic-to-OpenAI API translation.
Accepts Anthropic Messages API requests, translates them to OpenAI Chat Completions format, sends them to an OpenAI-compatible backend, and translates the response back. Supports non-streaming and streaming (SSE) modes, retry with exponential backoff, SSRF-safe DNS resolution, and mTLS.
§Quick start
use anyllm_client::{Client, ClientConfig, Auth};
use anyllm_translate::TranslationConfig;
use anyllm_translate::anthropic::MessageCreateRequest;
let config = ClientConfig::builder()
.backend_url("https://api.openai.com/v1/chat/completions")
.auth(Auth::Bearer("sk-...".into()))
.translation(
TranslationConfig::builder()
.model_map("haiku", "gpt-4o-mini")
.model_map("sonnet", "gpt-4o")
.build()
)
.build();
let client = Client::new(config);
let req: MessageCreateRequest = serde_json::from_str(r#"{
"model": "claude-sonnet-4-6",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Hello"}]
}"#).unwrap();
let response = client.messages(&req).await?;
println!("{:?}", response);§Modules
client– High-levelClientandClientBuilderfor Anthropic-in, Anthropic-out API callstools– Builder helpers forTooldefinitions andToolChoicehttp– HTTP client builder with TLS and SSRF protectionretry– Generic retry logic with exponential backoffrate_limit– Rate limit header extraction and format conversionsse– Framework-agnostic SSE frame parsererror– Error types
Re-exports§
pub use client::Auth;pub use client::Client;pub use client::ClientBuilder;pub use client::ClientConfig;pub use client::ClientConfigBuilder;pub use error::ClientError;pub use http::build_http_client;pub use http::HttpClientConfig;pub use rate_limit::RateLimitHeaders;pub use retry::backoff_delay;pub use retry::is_retryable;pub use retry::parse_retry_after;pub use retry::send_with_retry;pub use retry::RetryableError;pub use sse::find_double_newline;pub use sse::SseError;pub use tools::ToolBuilder;pub use tools::ToolChoiceBuilder;
Modules§
- client
- High-level async client: Anthropic request in, Anthropic response out.
- error
- Error types for the client crate.
- http
- HTTP client builder with optional mTLS, custom CA, and SSRF-safe DNS resolution.
- rate_
limit - Rate limit header extraction, format conversion, and duration parsing.
- retry
- Generic retry logic with exponential backoff and jitter.
- sse
- Framework-agnostic SSE frame parser.
- tools
- Builder helpers for Anthropic tool definitions and tool choice.
Structs§
- Tool
- Tool definition with name, description, and JSON schema.
Enums§
- Stream
Event - Top-level SSE event, internally tagged on
"type". - Tool
Choice - How the model should use tools: auto, any, none, or specific tool.