Skip to content

wanggang316/openai-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openai-rust

A Rust client library for the OpenAI API. This library provides a native Rust interface for interacting with OpenAI's services, including support for OpenAI-compatible providers like DeepSeek and OpenRouter.

Features

  • Chain-style API for easy interaction
  • Builder pattern for client configuration
  • Streaming support using async streams
  • Support for completions, models, and responses API
  • Compatible with OpenAI, DeepSeek, OpenRouter, and more

Installation

Add this to your Cargo.toml:

[dependencies]
openai-rust = { git = "https://github.com/wanggang316/openai-rust", tag = "v0.1.0" }

Quick Start

use openai_rust::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::builder()
        .api_key("your-api-key")
        .build()?;

    let response = client.completions()
        .create(&request)
        .await?;

    println!("{:?}", response);
    Ok(())
}

Development

Prerequisites

  • Rust 1.85 or later
  • Cargo (comes with Rust)

Building

cargo build --release

Running Examples

cargo run --example chat-completions
cargo run --example streaming
cargo run --example models

Testing

cargo test

Contributing

See CONTRIBUTING.md for contribution guidelines and AGENTS.md for project-specific rules (for both humans and agents).

License

This project is licensed under the MIT License.

Acknowledgments

Built based on the official OpenAI API specification.

About

OpenAI Rust API client

Resources

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages