Overview
async-openai
is an unofficial Rust library for OpenAI REST API.
- It's based on OpenAI OpenAPI spec
- Current features:
- Audio
- Chat (including SSE streaming)
- Completions (including SSE streaming)
- Edits
- Embeddings
- Files
- Fine-Tuning (including SSE streaming)
- Images
- Microsoft Azure Endpoints
- Models
- Moderations
- Non-streaming requests are retried with exponential backoff when rate limited by the API server.
- Ergonomic Rust library with builder pattern for all request objects.
Note on Azure OpenAI Service: async-openai
primarily implements OpenAI APIs, and exposes same library for Azure OpenAI Service too. In reality Azure OpenAI Service provides only subset of OpenAI APIs.
Usage
The library reads API key from the environment variable OPENAI_API_KEY
.
# On macOS/Linux
# On Windows Powershell
$Env:OPENAI_API_KEY='sk-...'
- Visit examples directory on how to use
async-openai
. - Visit docs.rs/async-openai for docs.
Image Generation Example
use ;
use Error;
async
Contributing
Thank you for your time to contribute and improve the project, I'd be happy to have you!
A good starting point would be existing open issues.
Complimentary Crates
- openai-func-enums provides procedural macros that make it easier to use this library with OpenAI API's function calling feature. It also provides derive macros you can add to existing clap application subcommands for natural language use of command line tools.
License
This project is licensed under MIT license.