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
//! nRouter SDK for Rust — one API key for models across six provider clouds.
//!
//! Two entry points, deliberately:
//!
//! * [`client`] returns an [`async_openai`] client pointed at the gateway, so
//! every OpenAI-shaped call you already write keeps working unmodified.
//! * [`http::Client`] is a native client that hands back the `x-nr-*`
//! metadata — per-request cost, tokens, cache outcome — which the
//! `async-openai` surface cannot expose because it discards the raw response.
//!
//! ```no_run
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! use async_openai::types::chat::{
//! ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs,
//! };
//!
//! let client = nrouter::client()?; // reads NROUTER_API_KEY
//! let request = CreateChatCompletionRequestArgs::default()
//! .model("claude-sonnet-4-5")
//! .messages(vec![ChatCompletionRequestUserMessageArgs::default()
//! .content("Hello!")
//! .build()?
//! .into()])
//! .build()?;
//! let response = client.chat().create(request).await?;
//! println!("{}", response.choices[0].message.content.as_ref().unwrap());
//! # Ok(())
//! # }
//! ```
//!
//! Reading the cost of a call:
//!
//! ```no_run
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! use serde_json::json;
//!
//! let client = nrouter::http::Client::from_env()?;
//! let out = client
//! .chat_completions(&json!({
//! "model": "claude-sonnet-4-5",
//! "messages": [{"role": "user", "content": "Hello!"}]
//! }))
//! .await?;
//!
//! match out.meta.cost {
//! Some(usd) => println!("cost ${usd}"),
//! // Unpriced is not free — it is unknown. Never render it as 0.
//! None => println!("unpriced ({:?})", out.meta.cost_status),
//! }
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
use ;
/// The gateway's customer surface. A dynamic value: override it for stage.
pub const DEFAULT_BASE_URL: &str = "https://api.nrouter.ai/v1";
/// The one environment variable this SDK reads.
pub const ENV_KEY: &str = "NROUTER_API_KEY";
/// Every customer key carries this prefix.
pub const KEY_PREFIX: &str = "sk-nrouter-";
/// Resolve and validate a key: explicit argument first, then the environment.
///
/// Validation happens before any request so a malformed key fails locally
/// rather than as a 401 that looks like a revoked credential.
/// An `async-openai` client pointed at nRouter, keyed from `NROUTER_API_KEY`.
/// An `async-openai` client pointed at nRouter with an explicit key.