$ show 64bit/async-openai
async-openai is a comprehensive, async Rust library providing typed access to the full OpenAI REST API surface. It covers all major endpoints including Chat Completions, the modern Responses API, Audio transcription/speech, Image generation/editing, Embeddings, Fine-tuning, Assistants (deprecated), Vector Stores, Realtime WebSocket sessions, Admin & Usage, Evals, Containers, Videos, and more. The architecture centers on a `Client<C: Config>` struct that dispatches requests through a configurable HTTP stack built on `reqwest`, `tokio`, and `tower` middleware. Each API group is a separate module with strongly-typed request/response structs, builder patterns via `derive_builder`, and first-class streaming support via SSE event streams. The library emphasizes flexibility and production readiness: it supports multiple OpenAI-compatible providers (Azure, Ollama, Gemini) through the BYOT (Bring Your Own Type) pattern, allowing users to swap in custom serialization for any endpoint. A powerful middleware system integrates with the Tower ecosystem, providing retry with exponential backoff, timeouts, and concurrency limiting. The codebase is fully compatible with WASM targets, with dedicated examples and CI. Over 40 example projects demonstrate real-world usage patterns including multi-turn reasoning, function calling, web search, and realtime audio sessions. Code quality is high: type definitions are meticulously crafted with serde tagging, feature flags for minimal builds, and extensive use of macros to reduce boilerplate. The project tracks OpenAI's rapidly evolving API closely, with deprecated endpoints (Assistants) clearly marked and a migration path to Responses API. While the large surface area and many feature flags add complexity, the overall engineering is clean, well-organized, and suitable for production use. The maintainers actively respond to issues and keep dependencies up to date, making this one of the most thorough and reliable OpenAI SDKs in the Rust ecosystem.
The LLM identified 3 files worth highlighting for reuse:
Implements the `#[byot]` proc macro that generates generic `*_byot` methods for every API endpoint. This allows users to provide custom serializable types for request and response, enabling compatibility with any OpenAI-compatible provider without forking the library. The macro is self-contained, demonstrates advanced Rust macro techniques, and could be extracted and adapted for other API client libraries that need similar BYOT flexibility.
A tower middleware layer for automatic retry with exponential backoff. It implements a configurable retry policy that respects `Retry-After` headers, handles both 429 and 5xx status codes, and rebuilds requests via `HttpRequestFactory` to support non-cloneable bodies. This is a clean, well-structured implementation of a common cross-cutting concern that can be reused in any HTTP client built on the Tower service abstraction.
Defines `StreamResponse<T>` - a generic, async stream wrapper over Server-Sent Events (SSE) that deserializes each event into the appropriate typed variant using the `EventType` trait. Used across all streaming endpoints (chat, responses, audio, images). This pattern is reusable for any SSE-based API client and demonstrates a clean separation between transport (eventsource-stream) and domain-specific event types.