@@ -7,7 +7,7 @@ Check out the [docs.rs](https://docs.rs/openai-api-rs/).
77Cargo.toml
88``` toml
99[dependencies ]
10- openai-api-rs = " 5.2.7 "
10+ openai-api-rs = " 6.0.0 "
1111```
1212
1313## Usage
@@ -23,13 +23,13 @@ $ export OPENROUTER_API_KEY=sk-xxxxxxx
2323### Create OpenAI client
2424``` rust
2525let api_key = env :: var (" OPENAI_API_KEY" ). unwrap (). to_string ();
26- let client = OpenAIClient :: builder (). with_api_key (api_key ). build ()? ;
26+ let mut client = OpenAIClient :: builder (). with_api_key (api_key ). build ()? ;
2727```
2828
2929### Create OpenRouter client
3030``` rust
3131let api_key = env :: var (" OPENROUTER_API_KEY" ). unwrap (). to_string ();
32- let client = OpenAIClient :: builder ()
32+ let mut client = OpenAIClient :: builder ()
3333 . with_endpoint (" https://openrouter.ai/api/v1" )
3434 . with_api_key (api_key )
3535 . build ()? ;
@@ -53,6 +53,10 @@ let req = ChatCompletionRequest::new(
5353``` rust
5454let result = client . chat_completion (req )? ;
5555println! (" Content: {:?}" , result . choices[0 ]. message. content);
56+
57+ for (key , value ) in client . headers. unwrap (). iter () {
58+ println! (" {}: {:?}" , key , value );
59+ }
5660```
5761
5862### Set OPENAI_API_BASE to environment variable (optional)
@@ -70,7 +74,7 @@ use std::env;
7074#[tokio:: main]
7175async fn main () -> Result <(), Box <dyn std :: error :: Error >> {
7276 let api_key = env :: var (" OPENAI_API_KEY" ). unwrap (). to_string ();
73- let client = OpenAIClient :: builder (). with_api_key (api_key ). build ()? ;
77+ let mut client = OpenAIClient :: builder (). with_api_key (api_key ). build ()? ;
7478
7579 let req = ChatCompletionRequest :: new (
7680 GPT4_O . to_string (),
@@ -85,7 +89,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8589
8690 let result = client . chat_completion (req ). await ? ;
8791 println! (" Content: {:?}" , result . choices[0 ]. message. content);
88- println! (" Response Headers: {:?}" , result . headers);
92+
93+ for (key , value ) in client . headers. unwrap (). iter () {
94+ println! (" {}: {:?}" , key , value );
95+ }
8996
9097 Ok (())
9198}
@@ -101,7 +108,7 @@ use std::env;
101108#[tokio:: main]
102109async fn main () -> Result <(), Box <dyn std :: error :: Error >> {
103110 let api_key = env :: var (" OPENROUTER_API_KEY" ). unwrap (). to_string ();
104- let client = OpenAIClient :: builder ()
111+ let mut client = OpenAIClient :: builder ()
105112 . with_endpoint (" https://openrouter.ai/api/v1" )
106113 . with_api_key (api_key )
107114 . build ()? ;
@@ -119,7 +126,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
119126
120127 let result = client . chat_completion (req ). await ? ;
121128 println! (" Content: {:?}" , result . choices[0 ]. message. content);
122- println! (" Response Headers: {:?}" , result . headers);
129+
130+ for (key , value ) in client . headers. unwrap (). iter () {
131+ println! (" {}: {:?}" , key , value );
132+ }
123133
124134 Ok (())
125135}
0 commit comments