Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Migrating from async-openai

openai-oxide and async-openai are both Rust OpenAI clients, but differ in API design, feature set, and architecture.

Key Differences

async-openaiopenai-oxide
Client::new()OpenAI::from_env()?
CreateChatCompletionRequestArgs::default()...build()?ChatCompletionRequest::new("model")...
Derive-macro buildersManual builder methods (no proc macros)
backoff crate for retriesBuilt-in configurable retry policy
No WebSocket supportNative WebSocket sessions
No WASM supportFirst-class WASM target
No hedged requestsBuilt-in hedged request support

Pattern: async-openai to openai-oxide

#![allow(unused)]
fn main() {
// async-openai
let client = Client::new();
let request = CreateChatCompletionRequestArgs::default()
    .model("gpt-5.4")
    .messages(vec![ChatCompletionRequestUserMessageArgs::default()
        .content("Hello")
        .build()?
        .into()])
    .build()?;
let response = client.chat().create(request).await?;
}
#![allow(unused)]
fn main() {
// openai-oxide
let client = OpenAI::from_env()?;
let response = client.chat().completions().create(
    ChatCompletionRequest::new("gpt-5.4")
        .messages(vec![ChatMessage::user("Hello")])
).await?;
}

The main wins from switching: simpler builder API (no .build()? calls), WebSocket support, WASM compatibility, hedged requests, and feature-flag granularity.