use gpt5::{Gpt5Client, Gpt5Model};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🔑 Testing with invalid API key...");
let invalid_client = Gpt5Client::new("invalid-key".to_string());
match invalid_client.simple(Gpt5Model::Gpt5Nano, "Hello").await {
Ok(response) => println!("Unexpected success: {}", response),
Err(e) => {
println!("❌ Expected error: {}", e);
let error_str = e.to_string();
if error_str.contains("401") || error_str.contains("Unauthorized") {
println!(" Error type: Authentication error");
} else if error_str.contains("timeout") {
println!(" Error type: Timeout error");
} else if error_str.contains("network") {
println!(" Error type: Network error");
} else {
println!(" Error type: Other error");
}
}
}
if let Ok(api_key) = std::env::var("OPENAI_API_KEY") {
println!("\n✅ Testing with valid API key...");
let client = Gpt5Client::new(api_key);
println!("📝 Testing empty input...");
match client.simple(Gpt5Model::Gpt5Nano, "").await {
Ok(response) => println!("Response: {}", response),
Err(e) => println!("❌ Error with empty input: {}", e),
}
println!("\n📝 Testing very long input...");
let long_input = "Hello ".repeat(10000); match client.simple(Gpt5Model::Gpt5Nano, &long_input).await {
Ok(response) => println!("Response length: {} chars", response.len()),
Err(e) => println!("❌ Error with long input: {}", e),
}
println!("\n✅ Testing normal usage...");
match client
.simple(Gpt5Model::Gpt5Nano, "Say hello in 3 different languages")
.await
{
Ok(response) => println!("✅ Success: {}", response),
Err(e) => println!("❌ Unexpected error: {}", e),
}
} else {
println!("⚠️ OPENAI_API_KEY not set, skipping valid key tests");
}
println!("\n🔍 Error type checking example...");
let client = Gpt5Client::new("test-key".to_string());
match client.simple(Gpt5Model::Gpt5Nano, "test").await {
Ok(_) => println!("Unexpected success"),
Err(e) => {
if e.to_string().contains("401") || e.to_string().contains("Unauthorized") {
println!("🔐 Authentication error detected");
} else if e.to_string().contains("timeout") {
println!("⏰ Timeout error detected");
} else if e.to_string().contains("network") {
println!("🌐 Network error detected");
} else {
println!("❓ Other error: {}", e);
}
}
}
Ok(())
}