@@ -7,7 +7,7 @@ Check out the [docs.rs](https://docs.rs/openai-api-rs/).
7
7
Cargo.toml
8
8
``` toml
9
9
[dependencies ]
10
- openai-api-rs = " 5.2.7 "
10
+ openai-api-rs = " 6.0.0 "
11
11
```
12
12
13
13
## Usage
@@ -23,13 +23,13 @@ $ export OPENROUTER_API_KEY=sk-xxxxxxx
23
23
### Create OpenAI client
24
24
``` rust
25
25
let 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 ()? ;
27
27
```
28
28
29
29
### Create OpenRouter client
30
30
``` rust
31
31
let api_key = env :: var (" OPENROUTER_API_KEY" ). unwrap (). to_string ();
32
- let client = OpenAIClient :: builder ()
32
+ let mut client = OpenAIClient :: builder ()
33
33
. with_endpoint (" https://openrouter.ai/api/v1" )
34
34
. with_api_key (api_key )
35
35
. build ()? ;
@@ -53,6 +53,10 @@ let req = ChatCompletionRequest::new(
53
53
``` rust
54
54
let result = client . chat_completion (req )? ;
55
55
println! (" Content: {:?}" , result . choices[0 ]. message. content);
56
+
57
+ for (key , value ) in client . headers. unwrap (). iter () {
58
+ println! (" {}: {:?}" , key , value );
59
+ }
56
60
```
57
61
58
62
### Set OPENAI_API_BASE to environment variable (optional)
@@ -70,7 +74,7 @@ use std::env;
70
74
#[tokio:: main]
71
75
async fn main () -> Result <(), Box <dyn std :: error :: Error >> {
72
76
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 ()? ;
74
78
75
79
let req = ChatCompletionRequest :: new (
76
80
GPT4_O . to_string (),
@@ -85,7 +89,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
85
89
86
90
let result = client . chat_completion (req ). await ? ;
87
91
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
+ }
89
96
90
97
Ok (())
91
98
}
@@ -101,7 +108,7 @@ use std::env;
101
108
#[tokio:: main]
102
109
async fn main () -> Result <(), Box <dyn std :: error :: Error >> {
103
110
let api_key = env :: var (" OPENROUTER_API_KEY" ). unwrap (). to_string ();
104
- let client = OpenAIClient :: builder ()
111
+ let mut client = OpenAIClient :: builder ()
105
112
. with_endpoint (" https://openrouter.ai/api/v1" )
106
113
. with_api_key (api_key )
107
114
. build ()? ;
@@ -119,7 +126,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
119
126
120
127
let result = client . chat_completion (req ). await ? ;
121
128
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
+ }
123
133
124
134
Ok (())
125
135
}
0 commit comments