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