openrouter2
openrouter2 is a typed Rust client for the OpenRouter API. Version 0.2
targets the full current non-deprecated route set from the OpenRouter OpenAPI
spec snapshot dated 2026-06-28.
The crate keeps API keys out of client state. Pass the key per authenticated call; the client stores only the injected HTTP client and normalized base URL.
Install
[]
= "0.2"
= { = "0.13", = false, = ["json", "rustls"] }
= { = "1", = ["macros", "rt-multi-thread"] }
Async support is enabled by default. For a blocking client:
= { = "0.2", = ["blocking"] }
For blocking-only builds:
= { = "0.2", = false, = ["blocking"] }
Async Usage
use ;
async
Blocking Usage
use ;
API Surface
- Async client:
AsyncOpenRouterClientbehind default featureasync. - Blocking client:
BlockingOpenRouterClientbehind featureblocking. - Route-complete flat methods for all non-deprecated OpenRouter routes.
- Typed request/response shells with builder helpers for common fields.
- Unknown-preserving string enums and flattened raw
serde_json::Valueextras. - Typed SSE streaming for chat, responses, and messages.
- Raw JSON, binary, and multipart escape hatches for new API fields/routes.
RequestOptionsfor per-call headers such asHTTP-Referer,X-Title,X-Session-Id, and custom headers.
Deprecated OpenRouter operations are intentionally skipped. The deprecated Coinbase credits endpoint is not modeled.
MSRV
The minimum supported Rust version is 1.88.