Crate gpt5

Crate gpt5 

Source
Expand description

§GPT-5 Rust Client Library

A comprehensive Rust client library for OpenAI’s GPT-5 API with support for:

  • Function calling and tool usage
  • Reasoning capabilities with configurable effort levels
  • Verbosity control for response detail
  • Streaming and non-streaming responses
  • Type-safe enums for all API parameters

§Quick Start

use gpt5::{Gpt5Client, Gpt5Model, Gpt5RequestBuilder, VerbosityLevel};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Gpt5Client::new("your-api-key".to_string());
     
    let response = client
        .simple(Gpt5Model::Gpt5Nano, "Hello, world!")
        .await?;
     
    println!("Response: {}", response);
    Ok(())
}

§Advanced Usage with Function Calling

use gpt5::{Gpt5Client, Gpt5Model, Gpt5RequestBuilder, Tool};
use serde_json::json;

let weather_tool = Tool {
    tool_type: "function".to_string(),
    name: Some("get_weather".to_string()),
    description: Some("Get current weather".to_string()),
    parameters: Some(json!({
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "City name"}
        },
        "required": ["location"]
    })),
};

let req = Gpt5RequestBuilder::new(Gpt5Model::Gpt5)
    .input("What's the weather in Boston?")
    .tools(vec![weather_tool])
    .tool_choice("auto")
    .build();

Structs§

Gpt5Client
Main client for interacting with the GPT-5 API
Gpt5Request
Request structure for the GPT-5 /v1/responses endpoint
Gpt5RequestBuilder
Builder for GPT-5 requests using /v1/responses
Gpt5Response
Response structure from /v1/responses
InputTokenDetails
Input token details
OpenAiError
Error response structure from OpenAI
OpenAiErrorDetails
Error details
OutputContent
Content within an output message
RequestReasoning
Reasoning configuration for requests
RequestText
Text configuration for requests
ResponseOutput
Output content in the response
ResponseReasoning
Reasoning information in the response
ResponseText
Text formatting information
ResponseTextFormat
Text format specification
ResponseTokenDetails
Output token details
ResponseUsage
Token usage statistics
Tool
Tool definition for function calling
WebSearchConfig
Configuration for enabling web search assistance.

Enums§

ContentType
Content type for output content
FormatType
Format type for text responses
Gpt5Model
GPT-5 Models available for the /v1/responses endpoint
OutputType
Output type for GPT-5 responses
ReasoningEffort
Reasoning effort level for GPT-5 responses
Role
Role in the conversation
Status
Response status for GPT-5 responses
VerbosityLevel
Verbosity level for GPT-5 responses