openai_rust_sdk 1.2.0

Comprehensive OpenAI API SDK for Rust with YARA rule validation
Documentation
# GPT-5 Support in OpenAI SDK

## **Complete GPT-5 Support Added**

The SDK now includes comprehensive support for all GPT-5 features and capabilities, fully compatible with the Responses API.

### 🚀 **Key Features Implemented**

#### 1. **Model Family Support**
```rust
// All GPT-5 model variants
pub const GPT_5: &str = "gpt-5";
pub const GPT_5_MINI: &str = "gpt-5-mini";
pub const GPT_5_NANO: &str = "gpt-5-nano";
pub const GPT_5_CHAT_LATEST: &str = "gpt-5-chat-latest";

// Dated snapshots for production pinning
pub const GPT_5_2025_01_01: &str = "gpt-5-2025-01-01";
pub const GPT_5_MINI_2025_01_01: &str = "gpt-5-mini-2025-01-01";
pub const GPT_5_NANO_2025_01_01: &str = "gpt-5-nano-2025-01-01";
```

#### 2. **Reasoning Effort Control**
```rust
pub enum ReasoningEffort {
    Minimal,  // Fastest time-to-first-token
    Low,      // Balance of speed and quality
    Medium,   // Default, good for most tasks
    High,     // Most thorough reasoning
}

// Usage
let response = api.create_reasoned_response(
    "gpt-5",
    "Complex question here",
    ReasoningEffort::High,
    Verbosity::Medium
).await?;
```

#### 3. **Verbosity Settings**
```rust
pub enum Verbosity {
    Low,     // Concise answers
    Medium,  // Balanced responses
    High,    // Detailed explanations
}

// Fast, concise response
let response = api.create_fast_response(
    "gpt-5",
    "What is 42?",
    Verbosity::Low
).await?;
```

#### 4. **Chain of Thought (CoT) Support**
```rust
// Multi-turn conversations with previous response ID
let first = api.create_complex_response(input, None).await?;

// Continue with CoT from previous response
if let Some(id) = first.id {
    let followup = api.continue_conversation(
        "gpt-5",
        "Follow-up question",
        id,  // Passes reasoning to next turn
        ReasoningEffort::Low  // Less reasoning needed
    ).await?;
}
```

#### 5. **Optimized Methods for Different Use Cases**

##### For Coding Tasks:
```rust
let response = api.create_coding_response(
    "Write a Python function for quicksort",
    Verbosity::Medium
).await?;
```

##### For Complex Reasoning:
```rust
let response = api.create_complex_response(
    "Analyze this quantum mechanics problem",
    Some("Show step-by-step reasoning".to_string())
).await?;
```

##### For Fast Responses:
```rust
let response = api.create_minimal_response(
    "gpt-5-nano",
    "Classify sentiment: 'Great product!'"
).await?;
```

##### For Cost Optimization:
```rust
let response = api.create_cost_optimized_response(
    "Explain photosynthesis"
).await?;  // Uses gpt-5-mini
```

##### For High Throughput:
```rust
let response = api.create_high_throughput_response(
    "Simple classification task"
).await?;  // Uses gpt-5-nano
```

### 📦 **Request Builder Pattern**

Fluent API for building GPT-5 requests:

```rust
let request = GPT5RequestBuilder::new()
    .gpt5()                          // Select model
    .input("Your question here")
    .instructions("Be concise")
    .minimal_reasoning()             // Fastest reasoning
    .low_verbosity()                 // Short answers
    .temperature(0.3)                // Low randomness
    .max_tokens(100)                 // Limit output
    .previous_response(prev_id)      // Chain of thought
    .build()?;
```

### 🎯 **Model Selection Helper**

Automatic model selection based on use case:

```rust
// Get recommended model for task type
let model = GPT5ModelSelector::for_complex_reasoning();  // gpt-5
let model = GPT5ModelSelector::for_cost_optimized();     // gpt-5-mini
let model = GPT5ModelSelector::for_high_throughput();    // gpt-5-nano
let model = GPT5ModelSelector::for_coding();             // gpt-5
let model = GPT5ModelSelector::for_chat();               // gpt-5-chat-latest

// Migration recommendations
let new_model = GPT5ModelSelector::migration_from("o3");        // gpt-5
let new_model = GPT5ModelSelector::migration_from("gpt-4.1");   // gpt-5
```

### 🔧 **Integration with Existing Features**

GPT-5 features work seamlessly with:
- **Function Calling**: Minimal reasoning for tool selection
- **Custom Tools**: Grammar-constrained outputs
- **Structured Outputs**: JSON schema validation
- **Streaming**: Real-time token generation (coming soon)
- **Batch API**: Process multiple GPT-5 requests efficiently

### 📊 **Performance Guidelines**

| Use Case | Model | Reasoning | Verbosity | Notes |
|----------|-------|-----------|-----------|-------|
| Simple Q&A | gpt-5-nano | Minimal | Low | Fastest, cheapest |
| Code Generation | gpt-5 | Medium | Medium-High | Best quality |
| Complex Analysis | gpt-5 | High | High | Most thorough |
| Chat Applications | gpt-5-chat-latest | Low-Medium | Medium | Optimized for conversation |
| Cost-Sensitive | gpt-5-mini | Low | Medium | Good balance |

### 🚀 **Quick Start Example**

```rust
use openai_rust_sdk::{
    api::GPT5Api,
    models::gpt5::{ReasoningEffort, Verbosity, models},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api = GPT5Api::new(std::env::var("OPENAI_API_KEY")?)?;
    
    // Fast response with minimal reasoning
    let quick = api.create_minimal_response(
        models::GPT_5_NANO,
        "What's 2+2?"
    ).await?;
    println!("Quick answer: {}", quick.output_text());
    
    // Complex reasoning task
    let complex = api.create_complex_response(
        "Explain how transformers work in LLMs",
        Some("Use analogies suitable for a CS student".to_string())
    ).await?;
    println!("Detailed explanation: {}", complex.output_text());
    
    Ok(())
}
```

### 📝 **Migration from Older Models**

Moving from older models to GPT-5:

| From | To | Reasoning | Notes |
|------|-----|-----------|-------|
| o3 | gpt-5 | Medium-High | Similar reasoning capabilities |
| gpt-4.1 | gpt-5 | Minimal-Low | Faster with better results |
| o4-mini | gpt-5-mini | Low-Medium | Cost-optimized alternative |
| gpt-4.1-nano | gpt-5-nano | Minimal | High-throughput replacement |

### **Best Practices**

1. **Use minimal reasoning** for simple tasks to reduce latency
2. **Set low verbosity** when you just need the answer
3. **Use previous_response_id** for multi-turn conversations to avoid re-reasoning
4. **Pin to specific model snapshots** in production (e.g., `gpt-5-2025-01-01`)
5. **Choose the right model** for your use case (complexity vs. cost vs. speed)
6. **Combine with function calling** using minimal reasoning for tool selection
7. **Add preambles** in instructions for better tool calling accuracy

### 🔌 **Full API Compatibility**

All GPT-5 features are compatible with the Responses API endpoints:
- `/v1/responses` - Main endpoint for GPT-5 models
- Supports all parameters: `reasoning`, `text`, `previous_response_id`
- Works with tools, structured outputs, and streaming
- Maintains backward compatibility with existing code

The SDK is now fully equipped to leverage GPT-5's advanced capabilities for complex reasoning, code generation, and agentic tasks with optimal performance settings.