openai_rs/openai.rs
1use hyper_openssl::HttpsConnector;
2use crate::client::Client;
3
4/// Returns a new client for the OpenAI API.
5///
6/// # Arguments
7/// * `api_key` - The API key to use.
8///
9/// # Example
10/// ```
11/// use openai_rs::client::Client;
12/// use openai_rs::openai;
13///
14/// // Create the Client with your API key.
15/// let client: Client = openai::new("api_key");
16/// ```
17pub fn new(api_key: &str) -> Client {
18 let hyper_client = hyper::Client::builder()
19 .http2_only(true)
20 .pool_idle_timeout(std::time::Duration::from_secs(10))
21 .build(HttpsConnector::new().expect("Could not create HTTPS connector"));
22
23 Client {
24 api_key: api_key.to_owned(),
25 https: hyper_client,
26 }
27}