basic_usage/
basic_usage.rs

1//! Basic usage example for the GPT-5 Rust client
2//!
3//! This example shows the simplest way to use the GPT-5 client
4//! Run with: cargo run --example basic_usage
5
6use gpt5::{Gpt5Client, Gpt5Model};
7
8#[tokio::main]
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    // Initialize the client with your API key
11    let api_key =
12        std::env::var("OPENAI_API_KEY").expect("Please set OPENAI_API_KEY environment variable");
13
14    let client = Gpt5Client::new(api_key);
15
16    // Simple text generation
17    println!("šŸ¤– Asking GPT-5 Nano a simple question...");
18    let response = client
19        .simple(Gpt5Model::Gpt5Nano, "What is the capital of France?")
20        .await?;
21
22    println!("Response: {}", response);
23
24    // Try different models
25    println!("\nšŸ¤– Asking GPT-5 Mini...");
26    let response = client
27        .simple(
28            Gpt5Model::Gpt5Mini,
29            "Explain quantum computing in simple terms",
30        )
31        .await?;
32
33    println!("Response: {}", response);
34
35    // Try the main GPT-5 model
36    println!("\nšŸ¤– Asking GPT-5 (main model)...");
37    let response = client
38        .simple(Gpt5Model::Gpt5, "Write a short poem about coding")
39        .await?;
40
41    println!("Response: {}", response);
42
43    Ok(())
44}