openrouter-rust
An idiomatic, async Rust SDK for the OpenRouter API. A Rust port of openrouter-go; behavior and defaults are kept in sync with the Go SDK on purpose.
Install
The crate is published as openrouter-client on crates.io (openrouter,
openrouter-rust, and openrouter-rs were all already taken), but it
imports as openrouter — your code writes use openrouter::....
MSRV is 1.75. Optional beta feature gates the Responses API:
[]
= { = "0.1", = ["beta"] }
Quickstart
use ;
async
Streaming:
use StreamExt;
use ;
# async
Features
| Surface | Status |
|---|---|
| Chat completions + legacy completions (blocking + streaming) | ✅ |
| Tool / function calling (incl. streaming tool-call deltas) | ✅ |
| Structured outputs (JSON Schema + JSON mode) | ✅ |
| MCP tool conversion | ✅ |
Message transforms (middle-out) |
✅ |
| Web-search plugin | ✅ |
| Provider routing (order, sort, only/ignore, quantization, max price, ZDR) | ✅ |
| Reasoning tokens (effort + max-tokens) | ✅ |
| Multimodal (images, PDFs with parsing engines, audio, text files) | ✅ |
Discovery (/models, /models/{author}/{slug}/endpoints, /providers) |
✅ |
| Account (credits, activity, current key, ZDR endpoint listing) | ✅ |
| Provisioning key CRUD | ✅ |
| Workspaces + organization members | ✅ |
| Guardrails (spend caps, allowlists, key/member assignments) | ✅ |
Rerank (/rerank) |
✅ |
Text-to-speech (/audio/speech) |
✅ |
| Async video generation (submit / poll / download) | ✅ |
| Broadcast webhook parser (OTLP JSON) | ✅ |
| OAuth PKCE helpers | ✅ |
[beta] Responses API (gated behind the beta cargo feature) |
✅ |
Recipes
In-tree recipes are embedded in rustdoc and viewable on docs.rs:
End-to-end smoke tests
The e2e example is a single binary that mirrors the Go SDK's
cmd/openrouter-test/ layout. Every subcommand hits the live OpenRouter
API using google/gemini-3.1-flash-lite by default.
OPENROUTER_API_KEY=sk-...
OPENROUTER_API_KEY=sk-...
OPENROUTER_API_KEY=sk-...
OPENROUTER_API_KEY=sk-...
Subcommands: chat, stream, completion, tools, transforms,
websearch, models, endpoints, providers, credits, activity,
key, listkeys, createkey, updatekey, deletekey. The *key
provisioning subcommands require a provisioning key, not a runtime key.
Roadmap
| # | Phase | Status |
|---|---|---|
| 1 | Foundation — client builder, error model, retry/backoff, core types | ✅ |
| 2 | Core Endpoints & Streaming — chat, legacy completions, SSE | ✅ |
| 3 | Advanced Inference — tools, structured outputs, MCP, transforms, web search, provider routing, reasoning | ✅ |
| 4 | Multimodal Inputs — images, PDFs, audio, text files, ContentBuilder |
✅ |
| 5 | Discovery & Account — models, endpoints, providers, credits, activity, key CRUD | ✅ |
| 6 | Org & Beta Surfaces — workspaces, members, guardrails, ZDR, rerank, TTS, video, webhooks, OAuth, [beta] Responses API | ✅ |
| 7 | Testing, Docs & Release — unit + E2E test coverage, docs site, crates.io publish | ✅ |
Reference
- Go SDK this port is based on: https://github.com/hra42/openrouter-go
- OpenRouter API docs: https://openrouter.ai/docs
- Changelog: CHANGELOG.md
- AI agent guide: AGENTS.md
License
Released into the public domain under The Unlicense. Same license as the Go SDK.