7 releases

Uses new Rust 2024

0.1.6 May 2, 2025
0.1.5 Apr 17, 2025
0.1.4 Mar 14, 2025

#1058 in Web programming

Download history 339/week @ 2025-03-10 45/week @ 2025-03-17 31/week @ 2025-03-24 113/week @ 2025-03-31 130/week @ 2025-04-07 233/week @ 2025-04-14 33/week @ 2025-04-21 128/week @ 2025-04-28 498/week @ 2025-05-05

893 downloads per month
Used in aiflow

MIT license

77KB
1K SLoC

OpenAI Responses SDK

crates.io download count badge docs.rs

An unofficial Rust SDK for the OpenAI Responses API.

Usage

To get started, create a new Client and call the create method with a Request object. The Request object contains the parameters for the API call, such as the model, instructions, and input. The create method returns a Response object, which contains the output of the API call.

use openai_responses::{Client, Request, types::{Input, Model}};

let response = Client::from_env()?.create(Request {
    model: Model::GPT4o,
    input: Input::Text("Are semicolons optional in JavaScript?".to_string()),
    instructions: Some("You are a coding assistant that talks like a pirate".to_string()),
    ..Default::default()
}).await?;

println!("{}", response.output_text());

To stream the response as it is generated, use the stream method:

use openai_responses::{Client, Request};

// You can also build the `Request` struct with a fluent interface
let mut stream = Client::from_env()?.stream(
    Request::builder()
        .model("gpt-4o")
        .input("Are semicolons optional in JavaScript?")
        .instructions("You are a coding assistant that talks like a pirate")
        .build()
);

while let Some(event) = stream.next().await {
    dbg!(event?);
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~6–21MB
~302K SLoC