| Crates.io | openai-ergonomic |
| lib.rs | openai-ergonomic |
| version | 0.1.0 |
| created_at | 2025-09-21 19:48:50.331723+00 |
| updated_at | 2025-09-21 19:48:50.331723+00 |
| description | Ergonomic Rust wrapper for OpenAI API |
| homepage | https://github.com/genai-rs/openai-ergonomic |
| repository | https://github.com/genai-rs/openai-ergonomic |
| max_upload_size | |
| id | 1849074 |
| size | 189,857 |
Ergonomic Rust wrapper for the OpenAI API, providing type-safe builder patterns and async/await support.
bontokio and reqwest for modern async RustOpenAI API endpoints๐ง Under Construction - This crate is currently being developed and is not yet ready for production use.
Add openai-ergonomic to your Cargo.toml:
[dependencies]
openai-ergonomic = "0.1"
tokio = { version = "1.0", features = ["full"] }
use openai_ergonomic::{Client, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::from_env()?
.api_key("your-api-key-here")
.build();
let response = client
.chat_completions()
.model("gpt-4")
.message("user", "Hello, world!")
.send()
.await?;
println!("{}", response.choices[0].message.content);
Ok(())
}
use openai_ergonomic::{Client, Config};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::from_env()?
.api_key("your-api-key-here")
.build();
let mut stream = client
.chat_completions()
.model("gpt-4")
.message("user", "Tell me a story")
.stream()
.await?;
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
if let Some(content) = chunk.choices[0].delta.content {
print!("{}", content);
}
}
Ok(())
}
The examples/ directory contains comprehensive examples for all major OpenAI API features:
Run an example:
cargo run --example quickstart
We welcome contributions! Please see our Contributing Guide for details.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.