Expand description
One client interface for OpenAI-compatible APIs and the Anthropic Messages API.
The same code (ChatRequest -> ChatResponse) runs against any provider; switching
providers means switching the constructor:
let provider: Box<dyn LlmProvider> = Box::new(AnthropicProvider::new("sk-ant-..."));
// or: Box::new(OpenAiProvider::new("sk-...")),
// or: Box::new(OpenAiProvider::new("").with_base_url("http://localhost:11434/v1")),
let req = ChatRequest::new("claude-opus-5-5")
.system("Be concise.")
.max_tokens(512)
.message(Message::user("Hello!"));
let resp = provider.chat(&req).await?;
println!("{}", resp.text());Structs§
- Anthropic
Provider - Client for the Anthropic Messages API (
POST {base_url}/v1/messages). - ApiError
- A response with a non-2xx status (
APIStatusErrorin the SDKs). - Chat
Request - Provider-neutral chat request.
- Chat
Response - Cohere
Provider - Client for the Cohere Chat API v2 (
POST {base_url}/chat). - Gemini
Provider - Client for the Google Gemini API
(
POST {base_url}/models/{model}:generateContent, key inx-goog-api-key). - Message
- Open
AiProvider - Client for the OpenAI Chat Completions API (
POST {base_url}/chat/completions). - Tool
- A function the model may call.
parametersis a JSON Schema with"type": "object". - Usage
Enums§
- ApiError
Kind - Error class by HTTP status, matching the
APIErrorsubclasses in the official SDKs. - LlmError
- Every error this crate returns.
- Part
- One piece of a message.
- Role
- Author of a message.
- Stop
Reason - Why generation stopped, normalized across providers.
Constants§
- DEFAULT_
MAX_ TOKENS max_tokenssent to Anthropic when the request does not set one.
Traits§
- LlmProvider
- Common contract implemented by every provider.