The Problem
Teams building AI-powered applications face a fragmented ecosystem: each provider (OpenAI, Anthropic, Gemini, etc.) has its own API shape, streaming format, and authentication scheme. Maintaining separate clients for each provider multiplies code, complicates testing, and makes switching providers a significant refactor.
What This Does
rust-genai is a Rust crate that provides a single, unified chat and embedding API across 14+ AI providers. The core abstraction lives in src/chat/ (request/response/stream types) and src/adapter/ (provider-specific implementations). Each provider gets its own directory under src/adapter/adapters/ (e.g., openai/, anthropic/, gemini/), with shared streaming logic consolidated in src/webc/eventsourcestream.rs.
The library handles provider-specific concerns internally: native protocol support for Gemini thinking and Anthropic reasoning, image/PDF input, streaming, and embeddings. A ServiceTargetResolver (see src/resolver/) allows custom endpoints and auth overrides, useful for proxies or self-hosted models. The examples/ folder contains 18 runnable examples covering everything from basic chat (c00-readme.rs) to tool use (c20-tooluse.rs) and image generation (c08-image-gen.rs).
How To Use It
Setup: Add genai to your Cargo.toml dependencies. The crate is published on crates.io (per the README badge).
Configuration: Set the provider API key as an environment variable. The exact variable names are resolved at runtime via src/resolver/authresolver.rs; the README and examples (c02-auth.rs) show the pattern but the repo does not document a single canonical list.
Running it: The library is consumed as a dependency, not a binary. The pattern is:
use genai::Client; let client = Client::default(); let response = client.chat("gpt-4o", "Hello").await?;
The examples in examples/ are runnable with cargo run --example c00-readme. Note: there is no Cargo.lock file, so builds are not pinned to specific dependency versions.
Real-World Use
A typical scenario: a customer-support bot that needs to switch between OpenAI (default) and a cheaper provider (Groq) during peak load, or fall back to a local Ollama model when the network is down. The unified API means the application code stays unchanged; only the model name in the request changes. For agentic workflows, examples/c20-tooluse.rs through c23-tool-web-search.rs show how to wire up function calling across providers.
Code Health & Issues
Low - Missing lockfile: No Cargo.lock in the repo, so builds are not reproducible. This is common for libraries but risky for applications. Med - Large provider surface: 20+ adapters means significant maintenance burden. Some adapters (e.g., mimo, bigmodel) are newer and may have less battle-testing than openai or anthropic. Low - CI coverage: Only one workflow (.github/workflows/yakbak-replay-tests.yml) runs recorded HTTP replay tests. Live provider tests exist (tests/testsp_*.rs) but require API keys and are likely not run in CI. Good - Test infrastructure: 53 test files with a solid yakbak replay system (tests/support/yakbak/) for offline testing. This is a genuine strength.
The Bottom Line
rust-genai is a well-architected solution to a real problem: provider fragmentation in Rust AI applications. The code is organized, tested, and actively maintained (v0.5.x with recent updates). The main trade-off is the breadth of providers means depth per provider varies. Teams needing a single, ergonomic Rust client across multiple AI providers should evaluate this seriously; teams locked into one provider may find the abstraction unnecessary.