1use openai_api_rs::v1::api::OpenAIClient;
2use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
3use openai_api_rs::v1::common::GPT4_O_MINI;
4use std::env;
5
6#[tokio::main]
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let api_key = env::var("OPENROUTER_API_KEY").unwrap().to_string();
9 let mut client = OpenAIClient::builder()
10 .with_endpoint("https://openrouter.ai/api/v1")
11 .with_api_key(api_key)
12 .build()?;
13
14 let req = ChatCompletionRequest::new(
15 GPT4_O_MINI.to_string(),
16 vec![chat_completion::ChatCompletionMessage {
17 role: chat_completion::MessageRole::user,
18 content: chat_completion::Content::Text(String::from("What is bitcoin?")),
19 name: None,
20 tool_calls: None,
21 tool_call_id: None,
22 }],
23 );
24
25 let result = client.chat_completion(req).await?;
26 println!("Content: {:?}", result.choices[0].message.content);
27 println!("Response Headers: {:?}", client.response_headers);
28
29 Ok(())
30}
31
32