Expand description
ModelProvider subsystem for model inference backends.
This module implements the factory pattern for AI model model_providers. Each model_provider
implements the ModelProvider trait defined in traits, and is registered in the
factory function create_model_provider by its canonical string key (e.g., "openai",
"anthropic", "ollama", "gemini"). ModelProvider aliases are resolved internally
so that user-facing keys remain stable.
Each model_provider call goes through the ReliableModelProvider wrapper, which adds
automatic retry with exponential backoff and API-key rotation on rate limits.
Model routing across multiple model_providers is available via [create_routed_model_provider].
§Extension
To add a new model_provider, implement ModelProvider in a new submodule and register it
in create_model_provider_with_url. See AGENTS.md §7.1 for the full change playbook.
Modules§
- anthropic
- auth
- azure_
openai - bedrock
- AWS Bedrock model_provider using the Converse API.
- catalog
- Per-family catalog source table.
- compatible
- Generic OpenAI-compatible model_provider.
Most LLM APIs follow the same
/v1/chat/completionsformat. This module provides a single implementation that works for all of them. - copilot
- GitHub Copilot model_provider with OAuth device-flow authentication.
- factory
- Per-family construction dispatch for model providers.
- gemini
- Google Gemini model_provider with support for:
- gemini_
cli - Gemini CLI subprocess model_provider.
- kilocli
- KiloCLI subprocess model_provider.
- models_
dev - Unauthenticated cross-provider model catalog via models.dev.
- multimodal
- ollama
- openai
- openai_
codex - openrouter
- openrouter_
catalog - Cross-vendor model catalog via OpenRouter’s public
/api/v1/modelsendpoint. - reliable
- router
- telnyx
- Telnyx AI inference model_provider.
- traits
Structs§
- Chat
Message - A single message in a conversation.
- Chat
Request - Request payload for model_provider chat calls.
- Chat
Response - An LLM response that may contain text, tool calls, or both.
- Model
Provider Info - Information about a supported model model_provider for display purposes.
- Model
Provider Runtime Options - Provider
Capability Error - Structured error returned when a requested capability is not supported.
- Tool
Call - A tool call requested by the LLM.
- Tool
Result Message - A tool result to feed back to the LLM.
Enums§
- Conversation
Message - A message in a multi-turn conversation, including tool interactions.
Traits§
Functions§
- api_
error - Build a sanitized model_provider error from a failed HTTP response.
- canonicalize_
v2_ model_ provider_ name - Map a V2 model-provider family name (synonyms, regional variants, OAuth
suffixes) to its V3 canonical family. Production configs are normalised at
TOML load time by
normalize_provider_typeinzeroclaw-config/src/schema/v2.rs. This helper duplicates the same table at the runtime factory boundary so callers that bypass the schema migration (programmatic factory invocations, tests, thecreate_model_provider_with_urlcolon-URL legacy entry point) still resolve. Inputs that are already canonical or unknown pass through unchanged. - create_
model_ provider - Factory: create the right model_provider from config (without custom URL).
- create_
model_ provider_ for_ alias - Factory: create model_provider with full alias context.
- create_
model_ provider_ for_ alias_ with_ url - Factory: create model_provider with alias context AND custom base URL.
- create_
model_ provider_ with_ options - Factory: create model_provider with runtime options.
- create_
model_ provider_ with_ url - Factory: create model_provider with optional custom base URL.
- create_
resilient_ model_ provider_ for_ alias - Wrap the primary model_provider in a retry/backoff harness with full alias context. Production callers (gateway, orchestrator) use this so the dispatch sees the typed alias config and routes Azure/Codex/Gemini extras correctly.
- create_
resilient_ model_ provider_ from_ ref - Build a resilient model provider from a name that may be either a bare
family (
"openai") or a dotted alias ("openai.work"). Dotted names dispatch through the typed alias factory so endpoint URI, family extras, and per-alias credentials from[model_providers.<family>.<alias>]are honored; bare names route through the family factory directly. - create_
resilient_ model_ provider_ with_ options - Wrap the primary model_provider in a retry/backoff harness, threading auth runtime options.
- create_
routed_ model_ provider_ with_ options - Build a router fronted by
primary_nameplus one provider per uniquemodel_routesentry. Each dotted<family>.<alias>name resolves through the typed[model_providers.<family>.<alias>]config (endpoint URI, Azure resource, Gemini OAuth, etc.); bare family names use family defaults. - default_
model_ provider_ url - Canonical base URL for
name, mirroring whatcreate_model_providerwould dial.Nonefor families without a fixed default (Azure, custom, multi-region, CLI shims). - format_
error_ chain - Format an error including its full source chain and sanitize the result.
- is_
bailian_ alias - is_
doubao_ alias - is_
glm_ alias - is_
glm_ cn_ alias - is_
glm_ global_ alias - is_
minimax_ alias - is_
minimax_ cn_ alias - is_
minimax_ intl_ alias - is_
moonshot_ alias - is_
moonshot_ cn_ alias - is_
moonshot_ intl_ alias - is_
qianfan_ alias - is_
qwen_ alias - is_
qwen_ cn_ alias - is_
qwen_ intl_ alias - is_
qwen_ oauth_ alias - is_
qwen_ us_ alias - is_
zai_ alias - is_
zai_ cn_ alias - is_
zai_ global_ alias - list_
model_ providers - Return the list of all known model_providers for display in
zeroclaw model_providers list. - model_
provider_ runtime_ options_ from_ model_ provider_ entry - Build
ModelProviderRuntimeOptionsfrom a specificModelProviderConfigentry plus the global config’s process-wide settings (zeroclaw_dir, secrets, runtime). Splits out the per-entry resolution so callers with agent context can pass in the alias-resolved entry instead of hittingfirst_model_provider(). - options_
for_ provider_ ref - Options to use when building a provider from a name that may be either
a bare family or a dotted alias. Dotted names yield alias-resolved
options; bare names inherit only provider-agnostic settings from
fallback. - provider_
runtime_ options_ for_ agent - Resolve
ModelProviderRuntimeOptionsfrom an agent’smodel_provideralias ("<type>.<alias>"). Falls back tofirst_model_provider()when the agent alias doesn’t exist, doesn’t have amodel_providerset, or names a non-existent model_provider entry. - provider_
runtime_ options_ for_ alias - Build runtime options for a specific dotted provider alias
(
<family>.<alias>). Mirrorsprovider_runtime_options_for_agentbut keyed on the typed provider entry directly, so routed providers can resolve their alias-specific endpoint URI and other typed extras without going through an owning agent. - provider_
runtime_ options_ from_ config - sanitize_
api_ error - Sanitize API error text by scrubbing secrets and truncating length.
- scrub_
secret_ patterns - Scrub known secret-like token prefixes from model_provider error strings.