Repolode
dongri

dongri/openai-api-rs

An unofficial Rust client library for the OpenAI API, also usable with OpenRouter endpoints.

Stars
485
Forks
93
Open issues
7
Last commit
last month

What is it?

openai-api-rs is an unofficial Rust client for the OpenAI API. It wraps the REST endpoints in typed Rust structs and methods, so Rust applications can send requests without building HTTP calls by hand. The client is created with a builder, and the API key is typically read from the OPENAI_API_KEY environment variable.

The library covers a broad set of OpenAI endpoints, including chat completions, embeddings, images, audio, files, fine-tuning, moderations, function calling, assistants, batch, realtime, and responses. Setting a custom endpoint lets the same client talk to OpenRouter, and the base URL can also be overridden through OPENAI_API_BASE.

The crate is published on crates.io under the MIT license, with full API docs on docs.rs and additional examples in the repository.

Key features

  • 01Typed Rust structs and methods for OpenAI REST endpoints
  • 02Builder-based client setup with API key from environment variables
  • 03Custom endpoint support for OpenRouter
  • 04Async chat completion example using tokio
  • 05Covers chat, embeddings, images, audio, files, fine-tuning, and more

Use cases

  • Adding OpenAI chat or embedding calls to a Rust backend service
  • Calling OpenRouter-hosted models from Rust through the same client interface
  • Prototyping LLM features in a Rust command-line tool

Quick start

  1. 1

    Add the crate to Cargo.toml

    cargo add openai-api-rs
  2. 2

    Set your OpenAI or OpenRouter API key as an environment variable

    export OPENAI_API_KEY=sk-xxxxxxx

Things to know

  • Unofficial client library, not maintained by OpenAI.
  • Requires an OpenAI or OpenRouter API key to make requests.

Topics

FAQ

What is openai-api-rs?
An unofficial Rust client library for the OpenAI API, also usable with OpenRouter endpoints. openai-api-rs is an unofficial Rust client for the OpenAI API. It wraps the REST endpoints in typed Rust structs and methods, so Rust applications can send requests without building HTTP calls by hand. The client is created with a builder, and the API key is typically read from the OPENAI_API_KEY environment variable.
Is openai-api-rs free to use? What license does it have?
openai-api-rs is open source under the MIT license. Check the license terms before using it in commercial products.
Is openai-api-rs still maintained?
Updated within 6 months. The last commit to openai-api-rs was on Oct 3, 2026.
What can I use openai-api-rs for?
Adding OpenAI chat or embedding calls to a Rust backend service Calling OpenRouter-hosted models from Rust through the same client interface Prototyping LLM features in a Rust command-line tool
How do I install openai-api-rs?
Add the crate to Cargo.toml: cargo add openai-api-rs Set your OpenAI or OpenRouter API key as an environment variable: export OPENAI_API_KEY=sk-xxxxxxx
Where can I get openai-api-rs?
The source code and installation instructions are on GitHub: https://github.com/dongri/openai-api-rs

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects