Module providers
Expand description
ModelProvider subsystem — re-exported from zeroclaw-providers.
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.
- dispatch
ProviderDispatch— single source of truth forattribution_span!on theModelProvidersurface.- factory
- Per-family construction dispatch for model providers.
- gemini
- Google Gemini model_provider with support for:
- gemini_
cli - Gemini CLI subprocess model_provider.
- grok_
cli - Grok Build CLI subprocess model provider.
- hailo_
ollama - kilocli
- KiloCLI subprocess model_provider.
- model_
pin - models_
dev - Unauthenticated cross-provider model catalog via models.dev.
- multimodal
- ollama
- openai
- openai_
codex - opencode_
session x-opencode-session— OpenCode relay session-affinity header.- openrouter
- openrouter_
catalog - Cross-vendor model catalog via OpenRouter’s public
/api/v1/modelsendpoint. - pricing
- Live model pricing: a single process-global snapshot of token prices
fetched from providers’ own
/modelslistings (with the models.dev catalog as a secondary source for models the gateway doesn’t price), used as a FALLBACK beneath the operator’s[cost.rates]config. - reliable
- router
- safeguard_
notice - Task-local side-channel for safeguard (refusal-triggered) model switches.
- telnyx
- Telnyx AI inference model_provider.
- traits
- vision_
override
Structs§
- Accounted
Chat Response - A successful response plus billed usage from Reliable attempts that were rejected before that response was accepted.
- Anthropic
Refusal Error - A provider safety refusal that completed at the transport layer but cannot be accepted as an assistant response.
- 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.
- Provider
Dispatch - Wraps a model provider so every call opens the correct
attribution_span!automatically. See the module docs for the rationale and the CI gate that enforces routing through this type. - Provider
Dispatch Ref - Reliable
Provider Terminal Failure - The typed terminal presentation cause for a Reliable provider failure.
- Reliable
Rejected Completion Usage - A Reliable chat request exhausted its candidates after receiving rejected semantic completions. The provider-reported usage is retained so the turn loop can account for work that was billed even though no response was accepted.
- Reliable
Semantic Empty Completion - The final candidate attempt completed successfully at the transport layer but supplied neither usable text nor a native tool call. This remains typed independently from optional rejected-attempt usage so delivery layers can classify the actual terminal failure without guessing from accounting data.
- Resolved
Model Provider Ref - A provider resolved from a config reference together with the model declared by that same alias. The model is an on-demand view of Config, not stored provider state.
- Safeguard
Fallback Notice - One safeguard (refusal-triggered) fallback event for the current turn.
Read post-loop by the channel orchestrator (PR 5); mirrors
ProviderFallbackInfo’s task-local contract. - 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.
- Model
Provider Category - Grouping for a model-provider family. Replaces the section comments in the
registry list with data so surfaces (CLI list, docs capability table) can
group families without re-typing the membership. Mirrors the registry’s
own sections exactly; locality is the separate
localflag, not a category. - Reliable
Provider Terminal Failure Kind - A terminal Reliable failure that can be rendered safely at a user-facing delivery boundary without exposing retry-attempt diagnostics.
- Safeguard
Fallback Kind - Which layer performed the safeguard-triggered model switch.
Traits§
Functions§
- api_
error - Build a sanitized model_provider error from a failed HTTP response.
- canonical_
model_ provider_ slots - canonicalize_
v2_ model_ provider_ name - commit_
safeguard_ fallback - Commit the safeguard attribution for the latest accepted response.
- create_
model_ provider - create_
model_ provider_ for_ alias - create_
model_ provider_ for_ alias_ with_ url - Factory: create model_provider with alias context AND custom base URL.
- create_
model_ provider_ from_ ref - Build a bare (non-resilient) provider named by
name- a bare family ("llamacpp"), a dotted alias ("llamacpp.text_model"), or acustom:<url>ref - resolving its alias-specific runtime options fromconfig: thevisioncapability override, the endpoint URI, and per-alias credentials from[providers.models.<family>.<alias>]. - create_
model_ provider_ from_ ref_ with_ model - Resolve a provider reference and its alias-owned model as one materialized
view. Callers may apply their own explicit model override after resolution;
when the reference is bare or URL-based,
modelisNone. - create_
model_ provider_ with_ options - Factory: create model_provider with runtime options.
Legacy entry point — see
create_model_provider. - create_
model_ provider_ with_ url - Factory: create model_provider with optional custom base URL.
Legacy entry point — see
create_model_provider. - 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 - create_
resilient_ model_ provider_ with_ options - create_
routed_ model_ provider_ with_ options - create_
routed_ model_ provider_ with_ options_ and_ resolver - Build the routed provider together with the exact immutable route resolver it uses. Agent turn metadata can therefore resolve the serving profile and model without maintaining a second hint table.
- 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). - durable_
chat_ messages - Project a full agent conversation history down to the flat
ChatMessageshape durable session backends store: user/assistant chat turns only, system prompt excluded (the backend restores against the caller’s own system prompt, not a persisted one).AssistantToolCallsandToolResultsare tool-loop plumbing that durable session transcripts have never persisted; only the visible chat turns are kept. - fetch_
context_ window - Attempt to fetch context window from provider’s /models endpoint.
Returns
Noneon any failure (network, parsing, missing field) — caller uses fallback. - 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 - model_
refusal_ from_ error - Return the typed refusal that terminated a provider result, if any.
- 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>"). Returns safe defaults when the agent alias doesn’t exist, doesn’t have amodel_providerset, or names a non-existent entry. - provider_
runtime_ options_ for_ alias - provider_
runtime_ options_ for_ bare_ family - Runtime options for a bare family reference (e.g.
ollama), which has no alias entry to resolve. - recommended_
runtime_ profile - Provider-specific runtime recommendations. This is deliberately separate
from
local: credential-free CLI shims can call cloud models, and local providers without native tool support must retain text-fallback prompting. - rejected_
attempt_ usage_ from_ error - Return billed usage carried by a rejected provider result.
- sanitize_
api_ error - Sanitize API error text by scrubbing secrets and truncating length.
- scope_
safeguard_ fallback - Run the given future within a safeguard-fallback scope.
Both
commit_safeguard_fallback(inside the accepted-response owner) andtake_last_safeguard_fallback(the runtime turn boundary) must execute within this scope for the data to be visible. - scrub_
secret_ patterns - Scrub known secret-like token prefixes from model_provider error strings. Provider API-key prefixes come from the same canonical table used for credential-family validation; non-provider prefixes cover Slack, GitHub, and Google/Gemini credentials. Complete query strings and fragments are removed from embedded HTTP(S) URLs because either suffix may carry credentials under provider-specific names.
- take_
last_ safeguard_ fallback - Take (consume) the last safeguard fallback notice, if any.
Must be called within a
scope_safeguard_fallbackscope. - visible_
provider_ fallback - Select the generic provider-fallback record that still needs its own
presentation next to
safeguard.