pub struct ClientConfig {
pub api_key: Option<SecretString>,
pub base_url: Option<Url>,
pub default_model: Option<String>,
pub timeout: Duration,
pub retry: RetryPolicy,
pub default_headers: HeaderMap,
}Expand description
Client configuration. Explicit values win over environment, then defaults.
Fields§
§api_key: Option<SecretString>API key. Falls back to ENV_API_KEY.
base_url: Option<Url>API root. Falls back to ENV_BASE_URL, then DEFAULT_BASE_URL.
default_model: Option<String>Default model. Falls back to ENV_DEFAULT_MODEL, then DEFAULT_MODEL.
timeout: DurationPer-attempt timeout including the body. Default: 10 s.
retry: RetryPolicyRetry policy. Default matches the official SDKs.
default_headers: HeaderMapExtra headers. Cannot override Authorization, Accept, or SDK identification headers.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty config that will read the process environment in crate::Client::new.
Examples found in repository?
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_models().respond(json!({
15 "models": [{
16 "name": "jev-latest",
17 "description": "TypeSafe flagship",
18 "release_date": "2026-01-01"
19 }]
20 }));
21
22 let client = ClientConfig::new()
23 .api_key("test")
24 .base_url(mock.url())
25 .build()?;
26
27 client.warm_up().await?;
28 for model in client.models().list().await? {
29 println!("{} — {}", model.name, model.description);
30 }
31 Ok(())
32}More examples
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_system_one().respond(json!({
15 "urgent": noul(0.97),
16 "team": choice("technical", 0.82),
17 "frustration": score(1.6, 0.78),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build()?;
24
25 let response = client
26 .system_one(
27 "Help! My payouts have been failing for 3 days.",
28 questions! {
29 "urgent" => Question::noul("Does this convey urgency?")
30 .when_true("Explicitly time-sensitive")
31 .when_false("No time pressure"),
32 "team" => Question::choice("Which team should handle this?")
33 .option("billing", "Payments, invoicing, refunds")
34 .option("technical", "Bugs, outages, integrations")
35 .option("sales", "Pricing, upgrades, new accounts"),
36 "frustration" => Question::score("How frustrated is the customer?")
37 .level("Calm")
38 .level("Frustrated")
39 .level("Very angry"),
40 },
41 )
42 .await?;
43
44 println!("urgent = {:?}", response.noul("urgent"));
45 println!(
46 "team = {:?}",
47 response.choice("team").map(|c| c.choice)
48 );
49 println!(
50 "frustration = {:?}",
51 response.score("frustration").map(|s| s.score)
52 );
53 Ok(())
54}Sourcepub fn api_key(self, key: impl Into<SecretString>) -> Self
pub fn api_key(self, key: impl Into<SecretString>) -> Self
Set the API key.
Examples found in repository?
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_models().respond(json!({
15 "models": [{
16 "name": "jev-latest",
17 "description": "TypeSafe flagship",
18 "release_date": "2026-01-01"
19 }]
20 }));
21
22 let client = ClientConfig::new()
23 .api_key("test")
24 .base_url(mock.url())
25 .build()?;
26
27 client.warm_up().await?;
28 for model in client.models().list().await? {
29 println!("{} — {}", model.name, model.description);
30 }
31 Ok(())
32}More examples
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_system_one().respond(json!({
15 "urgent": noul(0.97),
16 "team": choice("technical", 0.82),
17 "frustration": score(1.6, 0.78),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build()?;
24
25 let response = client
26 .system_one(
27 "Help! My payouts have been failing for 3 days.",
28 questions! {
29 "urgent" => Question::noul("Does this convey urgency?")
30 .when_true("Explicitly time-sensitive")
31 .when_false("No time pressure"),
32 "team" => Question::choice("Which team should handle this?")
33 .option("billing", "Payments, invoicing, refunds")
34 .option("technical", "Bugs, outages, integrations")
35 .option("sales", "Pricing, upgrades, new accounts"),
36 "frustration" => Question::score("How frustrated is the customer?")
37 .level("Calm")
38 .level("Frustrated")
39 .level("Very angry"),
40 },
41 )
42 .await?;
43
44 println!("urgent = {:?}", response.noul("urgent"));
45 println!(
46 "team = {:?}",
47 response.choice("team").map(|c| c.choice)
48 );
49 println!(
50 "frustration = {:?}",
51 response.score("frustration").map(|s| s.score)
52 );
53 Ok(())
54}Sourcepub fn base_url(self, url: Url) -> Self
pub fn base_url(self, url: Url) -> Self
Set the API root.
Examples found in repository?
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_models().respond(json!({
15 "models": [{
16 "name": "jev-latest",
17 "description": "TypeSafe flagship",
18 "release_date": "2026-01-01"
19 }]
20 }));
21
22 let client = ClientConfig::new()
23 .api_key("test")
24 .base_url(mock.url())
25 .build()?;
26
27 client.warm_up().await?;
28 for model in client.models().list().await? {
29 println!("{} — {}", model.name, model.description);
30 }
31 Ok(())
32}More examples
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_system_one().respond(json!({
15 "urgent": noul(0.97),
16 "team": choice("technical", 0.82),
17 "frustration": score(1.6, 0.78),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build()?;
24
25 let response = client
26 .system_one(
27 "Help! My payouts have been failing for 3 days.",
28 questions! {
29 "urgent" => Question::noul("Does this convey urgency?")
30 .when_true("Explicitly time-sensitive")
31 .when_false("No time pressure"),
32 "team" => Question::choice("Which team should handle this?")
33 .option("billing", "Payments, invoicing, refunds")
34 .option("technical", "Bugs, outages, integrations")
35 .option("sales", "Pricing, upgrades, new accounts"),
36 "frustration" => Question::score("How frustrated is the customer?")
37 .level("Calm")
38 .level("Frustrated")
39 .level("Very angry"),
40 },
41 )
42 .await?;
43
44 println!("urgent = {:?}", response.noul("urgent"));
45 println!(
46 "team = {:?}",
47 response.choice("team").map(|c| c.choice)
48 );
49 println!(
50 "frustration = {:?}",
51 response.score("frustration").map(|s| s.score)
52 );
53 Ok(())
54}Sourcepub fn try_base_url(self, url: &str) -> Result<Self, Error>
pub fn try_base_url(self, url: &str) -> Result<Self, Error>
Parse and set the API root.
Sourcepub fn default_model(self, model: impl Into<String>) -> Self
pub fn default_model(self, model: impl Into<String>) -> Self
Set the default model.
Sourcepub fn retry(self, retry: RetryPolicy) -> Self
pub fn retry(self, retry: RetryPolicy) -> Self
Set the retry policy.
Sourcepub fn header(
self,
name: impl AsRef<str>,
value: impl AsRef<str>,
) -> Result<Self, Error>
pub fn header( self, name: impl AsRef<str>, value: impl AsRef<str>, ) -> Result<Self, Error>
Insert a default header. Protected names (Authorization, Accept,
User-Agent, SDK identification, retry-count) are ignored.
Sourcepub fn default_headers(self, headers: HeaderMap) -> Self
pub fn default_headers(self, headers: HeaderMap) -> Self
Replace extra default headers. Protected names are ignored at send time.
Sourcepub fn build(self) -> Result<Client, Error>
pub fn build(self) -> Result<Client, Error>
Examples found in repository?
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_models().respond(json!({
15 "models": [{
16 "name": "jev-latest",
17 "description": "TypeSafe flagship",
18 "release_date": "2026-01-01"
19 }]
20 }));
21
22 let client = ClientConfig::new()
23 .api_key("test")
24 .base_url(mock.url())
25 .build()?;
26
27 client.warm_up().await?;
28 for model in client.models().list().await? {
29 println!("{} — {}", model.name, model.description);
30 }
31 Ok(())
32}More examples
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let mock = MockServer::start().await;
14 mock.on_system_one().respond(json!({
15 "urgent": noul(0.97),
16 "team": choice("technical", 0.82),
17 "frustration": score(1.6, 0.78),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build()?;
24
25 let response = client
26 .system_one(
27 "Help! My payouts have been failing for 3 days.",
28 questions! {
29 "urgent" => Question::noul("Does this convey urgency?")
30 .when_true("Explicitly time-sensitive")
31 .when_false("No time pressure"),
32 "team" => Question::choice("Which team should handle this?")
33 .option("billing", "Payments, invoicing, refunds")
34 .option("technical", "Bugs, outages, integrations")
35 .option("sales", "Pricing, upgrades, new accounts"),
36 "frustration" => Question::score("How frustrated is the customer?")
37 .level("Calm")
38 .level("Frustrated")
39 .level("Very angry"),
40 },
41 )
42 .await?;
43
44 println!("urgent = {:?}", response.noul("urgent"));
45 println!(
46 "team = {:?}",
47 response.choice("team").map(|c| c.choice)
48 );
49 println!(
50 "frustration = {:?}",
51 response.score("frustration").map(|s| s.score)
52 );
53 Ok(())
54}Sourcepub fn build_blocking(self) -> Result<BlockingClient, Error>
Available on crate feature blocking only.
pub fn build_blocking(self) -> Result<BlockingClient, Error>
blocking only.Examples found in repository?
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more