Skip to main content

Crate openai_oxide

Crate openai_oxide 

Source
Expand description

§openai-oxide

Idiomatic Rust client for the OpenAI API — 1:1 parity with the official Python SDK.

§Quick Start

use openai_oxide::{OpenAI, types::chat::*};

#[tokio::main]
async fn main() -> Result<(), openai_oxide::OpenAIError> {
    let client = OpenAI::from_env()?;

    let request = ChatCompletionRequest::new(
        "gpt-4o-mini",
        vec![
            ChatCompletionMessageParam::System {
                content: "You are a helpful assistant.".into(),
                name: None,
            },
            ChatCompletionMessageParam::User {
                content: UserContent::Text("Hello!".into()),
                name: None,
            },
        ],
    );

    let response = client.chat().completions().create(request).await?;
    println!("{}", response.choices[0].message.content.as_deref().unwrap_or(""));
    Ok(())
}

Re-exports§

pub use azure::AzureConfig;
pub use client::OpenAI;
pub use config::ClientConfig;
pub use error::OpenAIError;
pub use hedged::hedged_request;
pub use hedged::hedged_request_n;
pub use hedged::speculative;
pub use pagination::Paginator;
pub use request_options::RequestOptions;
pub use streaming::SseStream;

Modules§

azure
client
config
error
hedged
Hedged requests — send N copies, take the fastest response.
middleware
Middleware and interceptor system.
pagination
rate_limit
request_options
resources
stream_helpers
streaming
types