rust-genai

Library Featured

Multi-AI Providers Library for Rust. (OpenAI, Gemini, Anthropic, DeepSeek, Ollama, OMLX, AWS Bedrock, Vertex, Xai, Groq, Kimi, GLM and many more)

Checked · Sources

Downloads
118,643
Dependents
81
Stars
938
Forks
199
Contributors
79
Commits
1,184
Latest release
0.7.3 ·

About

From the project README ·

genai

A Native-Protocol Multi-AI Provider Library for Rust

# Current release
genai = "0.7"

See v0.7.x

v0.7.x · CHANGELOG · Key Features · Providers · Examples · Chat Options · Usage · TLS Backends · Contribution

genai provides a single, ergonomic Rust API for native-protocol multi-AI provider access, including Anthropic, OpenAI, Gemini, xAI, Ollama, Groq, and more.

Supports many models and providers out of the box, including Ollama for local execution.

Out-of-the-box providers and adapters: openai, openai_resp, anthropic, gemini, gemini_ix, omlx, ollama, ollama_cloud, vertex, bedrock_api, bedrock_sigv4, github_copilot, opencode_go, groq, together, fireworks, cohere, nebius, mimo, deepseek, mistral, minimax, zai, zai_coding, bigmodel, aliyun, qwen_cloud, baidu, moonshot (moonshot.cn), kimi (moonshot.ai), aihubmix, open_router, requesty, api_route, heabsy, runcrate, cloudgpu, cheapaimodel, atlascloud, xai

Common models from OpenAI, Anthropic, and Gemini can be accessed by name, such as gpt-6-luna, claude-..., or gemini-..., and the appropriate adapter will be selected.

Read the full README

Providers and adapters can also be forced with a namespaced model name via [name_space]::[model_name], for example, qwen_cloud::qwen3.8-max

Custom OpenAI-compatible endpoints can be accessed with the built-in genai_n adapter. Set GENAI_{n}_ENDPOINT and optionally GENAI_{n}_API_KEY, then use the genai_{n}::model_name namespace:

GENAI_1_ENDPOINT=https://my-host.example.com/v1/
GENAI_1_API_KEY=sk-your-api-key
let client = Client::new()?;
let chat_res = client.exec_chat("genai_1::my-model", chat_req, None).await?;

For an OMLX deployment, set OMLX_ENDPOINT to the OpenAI-compatible base URL before creating the client. OMLX uses OMLX_API_KEY when authentication is required:

OMLX_ENDPOINT=http://my-omlx-host:8000/v1/
OMLX_API_KEY=your-api-key

Then target the model with the omlx:: namespace:

let client = Client::new()?;
let chat_res = client.exec_chat("omlx::my-model", chat_req, None).await?;

Also supports custom endpoints and auth with ServiceTargetResolver (see examples/c06-target-resolver.rs) to support any other providers.


// Can talk to any models / providers
let client = Client::new()?;

let question = "Why is the sky red?";

let chat_req = ChatRequest::new(vec![
	ChatMessage::system("Answer in one sentence"),
	ChatMessage::user(question),
]);

// Model names can even have a reasoning effort suffix, such as "-high", which will be set, and then removed from name when sent to the provider.
let chat_res = client.exec_chat("gpt-5.4-mini-high", chat_req, None).await?;

println!("{}", chat_res.first_text().unwrap_or("NO ANSWER"));

Docs for LLMs | CHANGELOG | BIG THANKS

Key Features

  • Multi-AI provider/model access optimized per provider: native protocols when available, OpenAI-compatible APIs when appropriate or required, and one common Rust API for OpenAI, OpenAI Responses, Anthropic, Gemini, Ollama, Ollama Cloud, OpenCode Go, Groq, xAI, DeepSeek, Cohere, Together, Fireworks, Nebius, Mimo, Zai, BigModel, Aliyun, Atlas Cloud, Google Vertex, GitHub Copilot, Mistral, Requesty, API Route, Qwen Cloud, Kimi, and OMLX (direct chat and streaming), plus custom genai_{n} OpenAI-compatible endpoints (see examples/c00-readme.rs)
  • Image analysis (for OpenAI, Gemini Flash-2, Anthropic) (see examples/c07-image.rs)
  • Custom auth/API key (see examples/c02-auth.rs)
  • Model aliases (see examples/c03-mapper.rs)
  • Custom endpoint, auth, and model identifier (see examples/c06-target-resolver.rs)
  • And much more

Examples | Thanks | Library Focus | Changelog | Provider Mapping: ChatOptions | Usage

Model to Adapter Resolution

By default, the library resolves the AdapterKind (AI provider) based on the model name prefix:

  • OpenAI: gpt-* (most), o1-*, o3-*, o4-*, chatgpt-*, codex-*
  • OpenAI Responses: gpt-5-*, gpt-6-*, gpt-* (containing codex or pro)
  • Anthropic: claude-*
  • Gemini: gemini-*
  • Gemini Interactions API (Argon): gemini-4-argon* models are routed to the gemini_ix adapter. The gemini_ix:: namespace also forces this adapter.
  • xAI: grok-*
  • DeepSeek: deepseek-*
  • Moonshot: moonshot-*
  • Kimi: kimi* (moonshot.ai)
  • Zai: glm-*
  • Cohere: command-*, embed-*
  • Mimo: mimo-*
  • OpenCode Go: Namespace opencode_go:: only
  • Mistral AI: Namespace mistral:: only
  • Atlas Cloud: Namespace atlascloud:: only
  • Qwen Cloud: Namespace qwen_cloud:: only, for the managed Qwen Cloud service at qwencloud.com. It uses the international Aliyun-compatible endpoint and QWEN_CLOUD_API_KEY.
  • Fireworks: Models containing fireworks
  • Ollama: Fallback for any other names, defaulting to local Ollama.
Namespacing (Forcing an Adapter)

You can force a specific adapter by using the adapter_kind::model_name syntax. This is the recommended way for many providers and for disambiguating OpenAI-compatible services.

  • groq::openai/gpt-oss-20b (Forces Groq adapter)
  • mistral::mistral-large-4 (Forces Mistral AI adapter)
  • together::meta-llama/Llama-3-8b-chat-hf (Forces Together adapter)
  • fireworks::glm-5p1 (for fireworks.ai)
  • ollama_cloud::gemma3:4b (Forces Ollama Cloud adapter)
  • github_copilot::openai/gpt-5.4-mini (Forces GitHub Copilot adapter)
  • nebius::Qwen/Qwen3-235B-A22B (Forces Nebius adapter)
  • aliyun::qwen-plus (Forces Aliyun adapter)
  • qwen_cloud::qwen-plus (Forces Qwen Cloud adapter, managed by qwencloud.com and backed by the international Aliyun-compatible service)
  • vertex::gemini-3.8-flash (Forces Google Vertex adapter)
  • gemini_ix::gemini-3.5-flash (Forces Gemini Interactions API adapter)
  • moonshot::moonshot-v1-8k (Forces Moonshot adapter)
  • baidu::ernie-4.0 (Forces Baidu adapter)
  • zai_coding::glm-4.6 (Special namespace for Zai coding subscription)
  • opencode_go::minimax-m2.5 (Forces OpenCode Go adapter)
  • bedrock_api::anthropic.claude-v2 (Forces AWS Bedrock adapter)
  • open_router::google/gemini-2.0-flash-001 (Forces OpenRouter adapter)
  • requesty::openai/gpt-4o-mini (Forces Requesty adapter)
  • api_route::gpt-6.1-sol or api_route::claude-fable-5-1 (Forces API Route adapter)
  • heabsy::qwen38 (Forces Heabsy adapter)
  • runcrate::deepseek-ai/DeepSeek-V4.1-Flash (Forces Runcrate adapter)
  • cloudgpu::deepseek-v4.1-flash (Forces CloudGPU adapter)
  • cheapaimodel::deepseek-v4-1-flash (Forces cheapaimodel adapter)
  • atlascloud::qwen/qwen3.5-flash (Forces Atlas Cloud adapter)
  • genai_1::my-model-7b (Forces Custom adapter with index 1)

For a complete list of AdapterKind, see the AdapterKind enum.

v0.7.0 Released

v0.7.0 release date: 2026-10-19

See all in CHANGELOG and v0.7.0 migration guide for more details.

Big release: Many fixes, new capabilities, new providers, and minimal API changes.

Key Breaking Changes:

  • Fallible client initialization: Client::new()? and ClientBuilder::build()? return Result<Client> (no more Client::default()).
  • ReasoningEffort::Zero replaces ReasoningEffort::None ("zero" keyword, "none" backward-compatible alias).
  • Error::HttpError now carries the failed response headers.
  • Tool adds custom_format, and ChatOptions adds raw_frame_sink, stream_header_timeout, and stream_read_timeout (use ..Default::default() or add the fields to struct literals).
  • Optional None fields are omitted from serialized JSON instead of null.
  • JsonSpec::schema_with_additional_properties_false is removed; adapters now sanitize schemas.

New Providers & Adapters:

  • Gemini Interactions API (gemini_ix::, and gemini-4-argon* models mapped to it): stateful conversation sessions (previous_response_id, store).
  • Mistral AI (mistral::): Chat Completions with typed thinking content, assistant reasoning replay, and random_seed mapping.
  • Atlas Cloud (atlascloud::), Qwen Cloud (qwen_cloud::), Kimi (kimi::, kimi-*), OMLX (omlx::, omlx-*).
  • Custom adapter (genai_{n}::): generic OpenAI-compatible routing via GENAI_{n}_ENDPOINT and GENAI_{n}_API_KEY.

Key Capabilities & Improvements:

  • Declarative provider config via ClientBuilder::append_provider_config and ClientConfig::append_provider_config.
  • Stream frame inspection via ChatFrameSink and ChatOptions::with_raw_frame_sink.
  • Thought signature and signed thinking block preservation across tool turns (Anthropic, Gemini, OpenRouter).
  • Bedrock Converse: preserve streaming usage from metadata after the stop event, replay signed and redacted reasoning across tool turns, and refine publisher detection, Nova/OpenAI reasoning mappings, and document naming.
  • Anthropic prompt caching on tools (Tool::with_cache_control) and SSE heartbeat events (ChatStreamEvent::Heartbeat).
  • OpenTelemetry GenAI semantic conventions instrumentation behind the otel feature flag.

Examples

Library Focus:

  • Focuses on standardizing chat completion APIs across major AI providers while preserving provider-specific strengths.

  • Native implementation without per-service SDK dependencies.

    • Reason: genai uses each provider's native protocol when available, so features such as reasoning controls, thinking budgets, streaming metadata, and multimodal inputs can be represented more completely. When a provider primarily exposes an OpenAI-compatible API, genai uses that compatibility layer instead. Managing these protocol differences at the adapter layer is simpler and more scalable than dealing with multiple SDKs.
  • Prioritizes ergonomics and commonality, while depth is secondary. (If you require a complete client API, consider using async-openai and ollama-rs; both are excellent and easy to use.)

  • This library focuses on text chat, vision, and function calling APIs. (If you require a complete client API, consider using async-openai and ollama-rs; both are excellent and easy to use.)

ChatOptions

  • (1) - OpenAI-compatible notes
    • Models: OpenAI, DeepSeek, Groq, xAI, Mimo, Together, Fireworks, Nebius, Zai, AIHubMix, Atlas Cloud
PropertyOpenAI Compatibles (*1)AnthropicGemini generationConfig.Cohere
temperaturetemperaturetemperaturetemperaturetemperature
max_tokensmax_tokensmax_tokens (default 1024)maxOutputTokensmax_tokens
top_ptop_ptop_ptopPp

Usage

PropertyOpenAI Compatibles (1)Anthropic usage.Gemini usageMetadata.Cohere meta.tokens.
prompt_tokensprompt_tokensinput_tokens (added)promptTokenCount (2)input_tokens
completion_tokenscompletion_tokensoutput_tokens (added)candidatesTokenCount (2)output_tokens
total_tokenstotal_tokens(computed)totalTokenCount (2)(computed)
prompt_tokens_detailsprompt_tokens_detailscached/cache_creationN/A for nowN/A for now
completion_tokens_detailscompletion_tokens_detailsN/A for nowN/A for nowN/A for now
  • (1) - OpenAI-compatible notes

    • Models: OpenAI, DeepSeek, Groq, xAI, Mimo, AIHubMix, Atlas Cloud
    • For Groq, the property is x_groq.usage.
    • Usage availability can vary by provider and streaming mode.
    • prompt_tokens_details and completion_tokens_details will have the value sent by the compatible provider, or None
  • (2): Gemini tokens

    • Right now, with the Gemini Stream API, it’s not clear whether usage for each event is cumulative or must be summed. It appears to be cumulative, meaning the last message shows the total number of input, output, and total tokens, so that is the current assumption. See possible tweet answer for more info.

Usage examples

  • AIPack - Check out AIPack, which wraps this genai library into an agentic runtime to run, build, and share AI Agent Packs. See pro@coder for a simple example of how I use AI PACK/genai for production coding.

  • zcoder - I am also in the process of building zcoder, which will be a parallel-first coding harness.

Note: Feel free to send me a short description and a link to your application or library that uses genai. I'm happy to add it.

TLS Backends

TLS is selectable via cargo features. The default works out of the box and is right for almost everyone.

You want…Use
A backend that just works (default)nothing — rustls-tls (rustls + aws-lc-rs + OS trust store)
System trust policy / OpenSSL or SChannelgenai = { default-features = false, features = ["native-tls", "system-proxy"] }
ring / FIPS / no aws-lc-sys (lean musl & cross builds)genai = { default-features = false }, add your own reqwest = { features = ["rustls-no-provider"] } + a provider (e.g. rustls with ring), and call CryptoProvider::install_default() at startup
Static OpenSSLgenai = { default-features = false } + your own reqwest = { features = ["native-tls-vendored"] }
Custom root CA / mTLS / fully custom clientbuild your own reqwest::Client and inject it via with_reqwest(...)

rustls-tls and native-tls are mutually exclusive. When selecting native-tls, set default-features = false (as shown above) — otherwise both backends compile and the build fails with a compile_error! telling you to do so.

rustls-tls reads the OS trust store via rustls-platform-verifier, so enterprise/custom CAs work without native-tls, and it needs no system OpenSSL. Note the default aws-lc-rs provider builds aws-lc-sys (a C/assembly crate); for a leaner static-musl or cross build, drop it with default-features = false and use the ring provider as in the table above.

For full control, build a reqwest::Client yourself and inject it:

let reqwest_client = reqwest::Client::builder()
    // .add_root_certificate(...), client identity for mTLS, custom CryptoProvider, etc.
    .build()?;

let client = genai::Client::builder()
    .with_reqwest(reqwest_client)
    .build()?;

If you set default-features = false on genai without enabling a TLS feature, add reqwest with a TLS feature directly to your own Cargo.toml (or use the rustls-no-provider path and install a CryptoProvider) — otherwise HTTPS requests fail at runtime.

The default system-proxy feature turns on reqwest's system-proxy, which reads the macOS and Windows system proxy settings when a client is built. Cargo unifies features, so it applies to every reqwest client in the binary. With default-features = false it is off; add features = ["system-proxy"] to keep it. Proxy environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) are honored either way.

Contribution

Contributions are welcome. To keep review fast and the codebase consistent, please follow these guidelines.

  • Keep your PR focused on one problem or one enhancement, or on very closely related changes. Small, focused PRs are easier to review and faster to merge.

  • This crate follows a zero-panic approach, so avoid .unwrap(), .expect(...), and similar panic-prone calls in the production code path, and avoid array indexing with [] as much as possible.

    • For now, .unwrap() and .expect(...) are tolerated in tests and examples, but they should be avoided going forward and will be changed soon. Favor .ok_or("...")? and other non-panicking alternatives.
  • When changing a provider or adapter implementation behavior, updating or adding a Yakbak cassette is appreciated when it makes sense.

  • Using AI is completely fine, as long as you fully review and control the end result before submitting the PR.

    • Concise, to-the-point description.
    • Clean and focused code.
    • Emoticonless, especially in code.
  • Do not update CHANGELOG.md, BIG-THANKS.md, or the migration docs under docs/migration/ in your PR. The maintainer handles those in a single pass so the formatting, wording, and ordering stay consistent across releases. Describe the change in your PR instead, and call out anything user-visible or breaking so it can be captured accurately.

    • If CHANGELOG.md or migration files are erroneous, submitting a PR to rectify them is a good approach.

Links

Runs on
GPU support unknown
What shows it
  • no dependency or feature matches a backend row
Native code
None found
  • No native code found
Python bindings
No Python binding crate found
License
Apache-2.0 OR MIT

Compare with similar projects

Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.

rust-genai beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
rust-genai This page Featured

Multi-AI Providers Library for Rust. (OpenAI, Gemini, Anthropic, DeepSeek, Ollama, OMLX, AWS Bedrock, Vertex, Xai, Groq, Kimi, GLM and many more)

118,643 downloads over 30 days 81 938 0.7.3 GPU support unknown No native code found Apache-2.0 OR MIT
async-openai Featured

Rust library for OpenAI

1,302,033 downloads over 30 days 275 2,031 0.43.0 GPU support unknown No native code found MIT
ollama-rs Featured

A Rust library for interacting with the Ollama API

45,579 downloads over 30 days 68 1,061 0.3.6 GPU support unknown No native code found MIT
aichat App Featured

All-in-one LLM CLI tool featuring Shell Assistant, Chat-REPL, RAG, AI Tools & Agents, with access to OpenAI, Claude, Gemini, Ollama, Groq, and more.

28,422 binary downloads per release Not applicable 10,556 0.30.0 GPU support unknown No native code found Apache-2.0 OR MIT

OpenAI API client library for Rust (unofficial)

46,400 downloads over 30 days 33 485 10.0.2 GPU support unknown No native code found MIT
rstructor Listed

Get structured, validated data out of LLMs as native Rust structs and enums. Derive a type and rstructor generates the JSON Schema, prompts the model, parses the reply, and retries on validation errors — across OpenAI, Anthropic Claude, Google Gemini, and xAI Grok.

1,269 downloads over 30 days 3 34 0.6.0 GPU support unknown No native code found MIT
blazr App Listed

Inference server for LLMs, speech and embeddings: OpenAI-compatible routes with streaming, plus speech synthesis (TTS) and transcription (ASR). Serves Llama, Mistral, Qwen, Mamba2, MLA+MoE and hybrid models from SafeTensors, AWQ, GPTQ and GGUF.

8 binary downloads per release Not applicable 7 0.7.1 CUDA, WebGPU Binds native code: ring (feature distributed) Apache-2.0
Why FeaturedIt passes every Featured gate.

What it meets

  • It has 47 active dependents and 43 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
  • Active dependents are at 100% of their peak. Featured needs at least 50%.
  • Docs are present. The release commit or a manifest ties the crate to the repository.
  • No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
  • The last activity is on 4 Nov 2026, 5 days ago. The rules expect an update within 1200 days. Dormancy rule

Exact rules: Featured library. The check on applied thresholds version 9.

Every rule outcome, as the check records it
  • expected-interval: version 0.7.3 base 300, doubled for 118643 downloads per month, doubled for 47 active users: E = 1200 days
  • dormancy: last activity 2026-11-04, 5 days ago, E = 1200: active
  • featured: featured: active_users 47, new_adopters 43, former_glory 1

Measurements and sources

Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.

Sources6 sources
Adoption47 active dependents, 43 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents47crates.io database dumpYes
New dependents (365 days)43crates.io database dumpYes
Peak active dependents46.5crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 5 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-04GitHub repositoryYes
Latest release2026-11-03crates.io database dumpYes
First release2024-06-01crates.io database dumpYes
Latest version0.7.3crates.io database dumpYes
Days the oldest outside issue waits for a reply218GitHub repositoryYes
Maintainer replies over 365 days149GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution149 releases, 118,643 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases149crates.io database dumpYes
Downloads over 30 days118643crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository938 stars, 199 forks, 79 contributors, 1,184 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars938GitHub repositoryYes — one part of the repository route
GitHub forks199GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account79GitHub contributorsYes — one part of the repository route
Commits on the default branch1184GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0 OR MITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly81crates.io database dumpNo

Corrections and review history

Report a correction

No correction applies to this entry.

Judgments

A judgment enters only through an approved issue and a merged pull request.

No judgment applies to this entry.