Model Providers
A model provider is a service that hosts LLMs and embedding models (OpenAI, Anthropic, Cohere, and so on). Rig gives each provider a small client with a consistent API, so switching providers is usually a one-line change.
Vocabulary
Section titled “Vocabulary”Three terms show up throughout these pages:
- Provider — the vendor and its module in
rig, e.g.rig::providers::openai. Each provider module holds its client, model constants, and request/response types. - Client — the configured entry point for a provider, e.g.
openai::Client. A client holds your API key and base URL and knows how to make requests. From a client you build models and higher-level constructs (agents, extractors, RAG systems). - Model — a specific completion or embedding model handle produced by the client, e.g.
client.completion_model("gpt-5.5")orclient.embedding_model("text-embedding-3-small"). Models implement Rig’sCompletionModel/EmbeddingModeltraits, which is what the rest of the framework builds on.
The flow is always: provider → client → model → agent/extractor/index.
Configure any provider
Section titled “Configure any provider”Every provider client offers the same three constructors.
From environment variables
Section titled “From environment variables”The most common option. Reads the provider’s API key from a well-known environment variable (for example OPENAI_API_KEY, ANTHROPIC_API_KEY, COHERE_API_KEY):
use rig::prelude::*;use rig::providers::openai;
let client = openai::Client::from_env()?;From an explicit key
Section titled “From an explicit key”Pass the key yourself — useful when you load secrets from a config file or secret manager:
use rig::prelude::*;use rig::providers::openai;
let client = openai::Client::new("your-api-key");From a custom base URL
Section titled “From a custom base URL”The client builder sets both the key and the API endpoint. Use it to target a proxy, a self-hosted gateway, or any OpenAI-compatible endpoint:
use rig::prelude::*;use rig::providers::openai;
let client = openai::Client::builder() .api_key("your-api-key") .base_url("https://your-gateway.example.com/v1") .build()?;Build a model or agent
Section titled “Build a model or agent”Once you have a client, the pattern is identical across providers:
use rig::prelude::*;use rig::providers::openai;
let client = openai::Client::from_env()?;
// A raw completion model...let model = client.completion_model("gpt-5.5");
// ...an embedding model...let embedder = client.embedding_model("text-embedding-3-small");
// ...or an agent built directly from the client.let agent = client .agent("gpt-5.5") .preamble("You are Gandalf the White, discussing the fate of Middle Earth.") .build();Swapping to another provider is usually just changing the import and the model id — the client methods (agent, completion_model, embedding_model) are the same. See Providers & Clients for how these fit into the broader architecture.
Supported providers
Section titled “Supported providers”Anthropic and OpenAI have dedicated guides below; the rest link to their docs.rs module reference.
See also
Section titled “See also”- Providers & Clients — how clients fit into Rig’s architecture
- Completions — using completion models directly
- Embeddings — using embedding models
rig::providerson docs.rs
