DISCOVER THE FUTURE OF AI AGENTSarrow_forward

openrouter-rs

calendar_todayAdded Apr 23, 2026
categoryAgent & Tooling
codeOpen Source
Rust大语言模型MultimodalSDKCLIAgent & ToolingModel & Inference FrameworkDeveloper Tools & CodingProtocol, API & Integration

A type-safe, fully-covered async Rust SDK for accessing the OpenRouter AI gateway API.

openrouter-rs is a community-maintained Rust SDK at version 0.8.1, requiring Rust 1.85+ (Edition 2024). The project implements all 51 methods/paths from the OpenRouter official OpenAPI specification, exposing nine domain-oriented client entry points: chat(), responses(), messages(), rerank(), tts(), videos(), models(), management(), and optional legacy().

The core design is built on the Tokio async runtime with reqwest + rustls transport. All requests and responses use strongly-typed Builder patterns. It supports SSE streaming (Chat, Responses, Messages), tool calling (manual JSON Schema and schemars typed tools), multimodal content (image/audio/video/file), and chain-of-thought reasoning parameters. The management API covers API Key management, workspaces, organization members, Guardrails, Activity, Credits, and more.

The repository also includes the openrouter-cli companion tool for profile viewing, model discovery, key management, and usage queries. The project features OpenAPI drift detection and contract testing, with CI via GitHub Actions. Licensed under MIT.

Domain Client Architecture#

Entry PointCapability
chat()Chat Completions (create, stream)
responses()OpenRouter Responses endpoint (with streaming)
messages()Messages endpoint (with Anthropic compatibility mode)
rerank()Document reranking
tts()Text-to-speech
videos()Video generation (initiate, poll, content retrieval)
models()Model discovery, Embeddings
management()API Keys, workspaces, org members, Guardrails, Activity, Credits, Generation metadata
legacy()Legacy /completions (requires feature flag)

Installation & Quick Start#

[dependencies]
openrouter-rs = "0.8.1"
tokio = { version = "1", features = ["full"] }
use openrouter_rs::{
    OpenRouterClient,
    api::chat::{ChatCompletionRequest, Message},
    types::Role,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = OpenRouterClient::builder()
        .api_key(std::env::var("OPENROUTER_API_KEY")?)
        .http_referer("https://yourapp.example")
        .x_title("my-openrouter-app")
        .app_categories(["cli-agent"])
        .build()?;

    let request = ChatCompletionRequest::builder()
        .model("anthropic/claude-sonnet-4")
        .messages(vec![Message::new(
            Role::User,
            "Explain Rust ownership in plain English.",
        )])
        .build()?;

    let response = client.chat().create(&request).await?;
    println!("{}", response.choices[0].content().unwrap_or(""));

    Ok(())
}

Use Cases#

  • Unified multi-LLM provider access in Rust backends via OpenRouter gateway
  • Building AI Agents (tool calling loops)
  • Streaming chat gateways (includes axum proxy gateway example in repo)
  • API Key and workspace management
  • Multimodal tasks: document reranking, TTS, video generation

Caveats#

This is a community-maintained third-party SDK, explicitly stating it is not affiliated with OpenRouter. No official endorsement or recommendation from OpenRouter has been found, and no public production usage reports exist.

Related Projects

View All arrow_forward

STAY UPDATED

Get the latest AI tools and trends delivered straight to your inbox. No spam, just intelligence.

rocket_launch