Skip to content
Get Started

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.

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") or client.embedding_model("text-embedding-3-small"). Models implement Rig’s CompletionModel / EmbeddingModel traits, which is what the rest of the framework builds on.

The flow is always: provider → client → model → agent/extractor/index.

Every provider client offers the same three constructors.

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()?;

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");

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()?;

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.

Anthropic and OpenAI have dedicated guides below; the rest link to their docs.rs module reference.