anyllm_client
Async HTTP client that accepts Anthropic Messages API requests, translates them to OpenAI Chat Completions, sends them to any OpenAI-compatible backend, and translates the response back to Anthropic format. Part of the anyllm-proxy workspace.
What this crate is
A self-contained client library, not a CLI or server. Use it when you want Anthropic-shaped requests and responses in your own Rust code without running the proxy as a sidecar.
It owns:
- A
reqwest-based HTTP client with TLS, mTLS, and (by default) SSRF-safe DNS resolution. - Retry with exponential backoff and
Retry-Afterparsing. - A framework-agnostic SSE frame parser for streaming responses.
- Anthropic-shaped tool builders (
ToolBuilder,ToolChoiceBuilder). - Rate-limit header extraction and conversion between vendor formats.
It deliberately does not own:
- The format mapping itself: that lives in
anyllm_translateand is re-exported where it makes sense. - A queue, batch engine, or admin UI: those are separate crates.
Where it fits
Five-crate workspace:
anyllm_translate- pure format mapping, no I/O.anyllm_providers- provider and model catalog.anyllm_client(this crate) - async HTTP client wrapping translate + transport.anyllm_batch_engine- batch job queue and webhook delivery.anyllm_proxy- axum HTTP server, admin UI, config parsing.
Depend on this crate directly when you need Anthropic-in / Anthropic-out from inside your own application. Depend on anyllm_proxy when you want a standalone HTTP server with config files, an admin UI, virtual keys, and metrics.
Add it
[]
= "0.9"
Default features include ssrf-protection. Disable it only for local development against 127.0.0.1 backends:
= { = "0.9", = false }
Library examples
1. Minimal: builder shorthand
The Client::builder() shorthand is the smallest path from "I have an API key" to "I have a working client". It defaults Auth to Bearer and uses the default TranslationConfig (1:1 model passthrough).
use Client;
use MessageCreateRequest;
let client = builder
.base_url
.api_key
.build?;
let req: MessageCreateRequest = from_str?;
let resp = client.messages.await?;
println!;
2. Anthropic-shaped clients on top of OpenAI-compatible providers
If your application speaks Anthropic Messages but you want to point it at Groq, OpenRouter, Together, or any local OpenAI-compatible server, use ClientConfig::builder() with a TranslationConfig that maps your Anthropic model aliases onto whatever the backend actually serves.
use ;
use TranslationConfig;
let translation = builder
.model_map
.model_map
.build;
let client = new;
The same shape works for http://localhost:11434/v1/chat/completions (Ollama) or http://localhost:1234/v1/chat/completions (LM Studio). For keyless local backends, pass Auth::Bearer("".into()).
3. Streaming SSE
messages_stream returns a stream of Anthropic-shaped StreamEvent values. Translation happens incrementally so you can render tokens as they arrive.
use StreamExt;
use ;
let = client.messages_stream.await?;
while let Some = stream.next.await
4. Tool use with the fluent builders
ToolBuilder and ToolChoiceBuilder produce Anthropic-shaped tool definitions without raw JSON.
use ;
use json;
let weather = new
.description
.input_schema
.build;
let mut req: MessageCreateRequest =
from_str?;
req.tools = Some;
req.tool_choice = Some;
let resp = client.messages.await?;
5. Custom auth header (Azure, custom gateways)
Backends that want api-key: instead of Authorization: Bearer use Auth::Header.
use ;
let client = new;
6. Tuning timeouts and retries
use Duration;
use Client;
let client = builder
.base_url
.api_key
.connect_timeout
.read_timeout
.max_retries
.build?;
Retries fire on 429 and 5xx with exponential backoff and Retry-After honoring. The retry helpers (backoff_delay, is_retryable, parse_retry_after, send_with_retry) are re-exported if you want to reuse them in your own HTTP code.
7. Sharing one reqwest::Client across many Clients
Useful when you fan out requests to multiple backends and want a single connection pool.
use ;
let http = build_http_client;
let openai = with_http_client;
let groq = with_http_client;
Modules
| Module | Purpose |
|---|---|
client |
High-level Client, ClientBuilder, ClientConfig, Auth. |
http |
HTTP client builder with TLS and SSRF protection. |
retry |
Generic retry with exponential backoff and Retry-After parsing. |
rate_limit |
Vendor rate-limit header extraction and format conversion. |
sse |
Framework-agnostic SSE frame parser. |
tools |
Builder helpers for Tool and ToolChoice. |
error |
ClientError and related types. |
Tests