Typed async Rust client for the OpenAI API: Responses API, Chat Completions, Embeddings, Images (gpt-image), Audio (TTS/STT), Moderations, and Models — with SSE streaming, Structured Outputs, and function calling
//! Basic text generation with the Responses API (the current primary API).
//!//! Run: `OPENAI_API_KEY=sk-... cargo run --example responses`
useopenai_chatgpt_api::responses::ResponseRequest;useopenai_chatgpt_api::OpenAiClient;#[tokio::main]
async fnmain()->Result<(), Box<dyn std::error::Error>>{let client =OpenAiClient::from_env()?;let request =ResponseRequest::new("gpt-5.6-terra","Explain Rust's ownership model in three sentences.",).instructions("You are a concise assistant.").max_output_tokens(300);let response = client.responses().create(&request).await?;println!("{}", response.output_text());ifletSome(usage)=&response.usage {println!("--- {} tokens total", usage.total_tokens);}Ok(())}