async-openai is an unofficial Rust crate that maps the OpenAI OpenAPI surface with builders, SSE streaming, feature flags, Azure support, and hooks for compatible providers.
Overview
async-openai is a Rust library for calling OpenAI's HTTP APIs from application code. It is generated around the official OpenAPI specification and exposes typed request and response structures with companion builder types for each call.
Granular Cargo features let you compile only the API families you need, from chat completions and responses through audio, images, embeddings, vector stores, batch jobs, administration, webhooks, and realtime channels. The client reads standard environment variables for API keys, base URL, organization, and project identifiers.
Streaming uses server-sent events where the API supports it. Optional bring-your-own-type methods accept generic request and response shapes for OpenAI-compatible gateways. You can override paths, headers, and query parameters per request or globally through config objects, and wrap configs in Box or Arc for dynamic dispatch across providers. Microsoft Azure OpenAI has a dedicated config type.
WASM targets are supported for browser and Tower-based middleware stacks. TLS can use rustls or native system stacks via separate feature flags. Webhook helpers cover event typing and signature verification, and an optional openapi feature emits utoipa schemas for chat and completion types.
Key features
- OpenAPI-aligned typed requests
- Per-API Cargo feature flags
- SSE streaming support
- Azure OpenAI configuration
- OpenAI-compatible provider tuning
- Bring-your-own-type generic calls
- Tower middleware integration
- Webhook signature verification
Use cases
- Rust services calling OpenAI APIs
- Custom gateways with shared client code
- Browser WASM OpenAI clients
- Selective API surface builds
- Azure-hosted model deployments