Expand description
OpenRouter provider for chat-rs.
OpenRouter is a unified gateway in front of hundreds of models from
many vendors; the model slug selects which one (e.g.
anthropic/claude-sonnet-4, openai/gpt-4o, google/gemini-2.5-pro).
It exposes two OpenAI-compatible wires, and the builder picks one upstream and hands off to the matching wire crate — no wrapper type:
- Responses API (Beta) (default) — wraps
chat_responsesand builds aResponsesClient. Stateless (noprevious_response_idround-trip), so response-id reuse is disabled and the full conversation is sent each turn. - Chat Completions — opt in with
OpenRouterBuilder::with_completions; wrapschat_completionsand builds aCompletionsClient.
Both wire clients already implement CompletionProvider (and
StreamProvider under the stream feature), so streaming is free
on either path. OpenRouter has no WebSocket endpoint — streaming is
SSE over HTTP — but the builder stays generic over Transport.
use chat_openrouter::OpenRouterBuilder;
// OPENROUTER_API_KEY env var is read automatically.
// Default: Responses API.
let responses = OpenRouterBuilder::new()
.with_model("anthropic/claude-sonnet-4")
.build();
// Opt in to the Chat Completions API.
let completions = OpenRouterBuilder::new()
.with_completions()
.with_model("openai/gpt-4o")
.build();Structs§
- Completions
- Wire type-state: target the Chat Completions API.
- Completions
Client - Open
Router Builder - Reqwest
Transport - HTTP transport backed by
reqwest. - Responses
- Wire type-state: target the Responses API (default).
- Responses
Client - Generic client over the OpenAI Responses API wire format
(
POST {base_url}/responses). Provider wrappers like [chat_openai] hold one of these as their inner state. - With
Model - Without
Model
Constants§
- DEFAULT_
OPENROUTER_ BASE_ URL - Default OpenRouter base URL. The Responses API lives at
{base_url}/responses, Chat Completions at{base_url}/chat/completions.