1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! # OpenRouter API Endpoints
//!
//! This module contains the typed request/response implementations behind the
//! domain clients exposed from [`crate::client::OpenRouterClient`].
//!
//! Canonical domain mapping:
//!
//! - `client.chat()` -> [`chat`]
//! - `client.responses()` -> [`responses`]
//! - `client.messages()` -> [`messages`]
//! - `client.rerank()` -> [`rerank`]
//! - `client.audio().speech()` / `client.audio().transcriptions()` -> [`audio`]
//! - `client.images()` -> [`images`]
//! - `client.videos()` -> [`videos`]
//! - `client.models()` -> [`models`], [`embeddings`], [`discovery`]
//! - `client.management()` -> [`api_keys`], [`auth`], [`byok`], [`credits`], [`generation`], [`guardrails`], [`observability`], [`organization`], [`presets`], [`workspaces`]
//! - `client.legacy()` -> [`legacy`] (feature `legacy-completions`)
//!
//! Endpoint families currently implemented here:
//!
//! - chat completions and multimodal content
//! - Responses API
//! - Anthropic-compatible Messages API
//! - rerank
//! - audio speech generation and transcription
//! - image generation and streaming
//! - image generation and streaming
//! - video generation and polling
//! - model discovery, providers, user model filters, model counts, rankings, and ZDR endpoints
//! - embeddings
//! - API-key and auth-code flows
//! - credits, Coinbase charge creation, generation lookup/content, and activity
//! - BYOK provider credential management
//! - observability destination management
//! - preset creation from inference request bodies
//! - guardrails and guardrail assignments
//! - organization member listing
//! - workspace CRUD and membership management
//! - structured API error payloads
//!
//! ## Quick Examples
//!
//! ### Chat
//! ```no_run
//! use openrouter_rs::{
//! OpenRouterClient,
//! api::chat::{ChatCompletionRequest, Message},
//! types::Role,
//! };
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = OpenRouterClient::builder().api_key("your_key").build()?;
//! let request = ChatCompletionRequest::builder()
//! .model("google/gemini-2.5-flash")
//! .messages(vec![Message::new(Role::User, "Hello!")])
//! .build()?;
//! let response = client.chat().create(&request).await?;
//! println!("{:?}", response.choices[0].content());
//! # Ok(())
//! # }
//! ```
//!
//! ### Responses
//! ```no_run
//! use openrouter_rs::{OpenRouterClient, api::responses::ResponsesRequest};
//! use serde_json::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = OpenRouterClient::builder().api_key("your_key").build()?;
//! let request = ResponsesRequest::builder()
//! .model("openai/gpt-5")
//! .input(json!([{ "role": "user", "content": "Say hello." }]))
//! .build()?;
//! let response = client.responses().create(&request).await?;
//! println!("{:?}", response.id);
//! # Ok(())
//! # }
//! ```
//!
//! ### Discovery
//! ```no_run
//! use openrouter_rs::{OpenRouterClient, types::ModelCategory};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = OpenRouterClient::builder().api_key("your_key").build()?;
//! let models = client.models().list_by_category(ModelCategory::Programming).await?;
//! println!("Found {} models", models.len());
//! # Ok(())
//! # }
//! ```
//!
//! ## Error Handling
//!
//! All endpoint methods return `Result<_, OpenRouterError>`:
//!
//! ```no_run
//! use openrouter_rs::{
//! OpenRouterClient,
//! api::chat::{ChatCompletionRequest, Message},
//! error::OpenRouterError,
//! types::Role,
//! };
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = OpenRouterClient::builder().api_key("your_key").build()?;
//! let request = ChatCompletionRequest::builder()
//! .model("google/gemini-2.5-flash")
//! .messages(vec![Message::new(Role::User, "Hello!")])
//! .build()?;
//!
//! match client.chat().create(&request).await {
//! Ok(response) => println!("Success: {:?}", response),
//! Err(OpenRouterError::Api(api_error)) if api_error.is_retryable() => {
//! println!("Retryable API error: {}", api_error.message);
//! }
//! Err(err) => println!("Other error: {}", err),
//! }
//! # Ok(())
//! # }
//! ```