docs/concepts/models.md
Model refs choose a provider and model. They do not usually choose the low-level agent runtime. For example, openai/gpt-5.5 can run through the normal OpenAI provider path or through the Codex app-server runtime, depending on agents.defaults.agentRuntime.id. In Codex runtime mode, the openai/gpt-* ref does not imply API-key billing; auth can come from a Codex account or openai-codex auth profile. See Agent runtimes.
OpenClaw selects models in this order:
<Steps> <Step title="Primary model"> `agents.defaults.model.primary` (or `agents.defaults.model`). </Step> <Step title="Fallbacks"> `agents.defaults.model.fallbacks` (in order). </Step> <Step title="Provider auth failover"> Auth failover happens inside a provider before moving to the next model. </Step> </Steps> <AccordionGroup> <Accordion title="Related model surfaces"> - `agents.defaults.models` is the allowlist/catalog of models OpenClaw can use (plus aliases). - `agents.defaults.imageModel` is used **only when** the primary model can't accept images. - `agents.defaults.pdfModel` is used by the `pdf` tool. If omitted, the tool falls back to `agents.defaults.imageModel`, then the resolved session/default model. - `agents.defaults.imageGenerationModel` is used by the shared image-generation capability. If omitted, `image_generate` can still infer an auth-backed provider default. It tries the current default provider first, then the remaining registered image-generation providers in provider-id order. If you set a specific provider/model, also configure that provider's auth/API key. - `agents.defaults.musicGenerationModel` is used by the shared music-generation capability. If omitted, `music_generate` can still infer an auth-backed provider default. It tries the current default provider first, then the remaining registered music-generation providers in provider-id order. If you set a specific provider/model, also configure that provider's auth/API key. - `agents.defaults.videoGenerationModel` is used by the shared video-generation capability. If omitted, `video_generate` can still infer an auth-backed provider default. It tries the current default provider first, then the remaining registered video-generation providers in provider-id order. If you set a specific provider/model, also configure that provider's auth/API key. - Per-agent defaults can override `agents.defaults.model` via `agents.list[].model` plus bindings (see [Multi-agent routing](/concepts/multi-agent)). </Accordion> </AccordionGroup>The same provider/model can mean different things depending on where it came from:
agents.defaults.model.primary and agent-specific primaries) are the normal starting point and use agents.defaults.model.fallbacks.modelOverrideSource: "auto" so later turns can keep using the fallback chain without probing a known-bad primary first./model, the model picker, session_status(model=...), and sessions.patch store modelOverrideSource: "user"; if that selected provider/model is unreachable, OpenClaw fails visibly instead of falling through to another configured model.--model / payload model is a per-job primary. It still uses configured fallbacks unless the job supplies explicit payload fallbacks (use fallbacks: [] for a strict cron run).models.mode: "replace" by listing explicit models.providers.*.models instead of loading the full built-in catalog.agents.defaults.models when present, otherwise explicit models.providers.*.models plus providers with usable auth. The full built-in catalog is reserved for explicit browse views such as models.list with view: "all" or openclaw models list --all.If you don't want to hand-edit config, run onboarding:
openclaw onboard
It can set up model + auth for common providers, including OpenAI Code (Codex) subscription (OAuth) and Anthropic (API key or Claude CLI).
agents.defaults.model.primary and agents.defaults.model.fallbacksagents.defaults.imageModel.primary and agents.defaults.imageModel.fallbacksagents.defaults.pdfModel.primary and agents.defaults.pdfModel.fallbacksagents.defaults.imageGenerationModel.primary and agents.defaults.imageGenerationModel.fallbacksagents.defaults.videoGenerationModel.primary and agents.defaults.videoGenerationModel.fallbacksagents.defaults.models (allowlist + aliases + provider params)models.providers (custom providers written into models.json)Provider configuration examples (including OpenCode) live in OpenCode. </Note>
Use additive writes when updating agents.defaults.models by hand:
openclaw config set agents.defaults.models '{"openai/gpt-5.4":{}}' --strict-json --merge
Interactive provider setup and `openclaw configure --section model` also merge provider-scoped selections into the existing allowlist, so adding Codex, Ollama, or another provider does not drop unrelated model entries. Configure preserves an existing `agents.defaults.model.primary` when provider auth is re-applied. Explicit default-setting commands such as `openclaw models auth login --provider <id> --set-default` and `openclaw models set <model>` still replace `agents.defaults.model.primary`.
If agents.defaults.models is set, it becomes the allowlist for /model and for session overrides. When a user selects a model that isn't in that allowlist, OpenClaw returns:
Model "provider/model" is not allowed. Use /models to list providers, or /models <provider> to list models.
Add it with: openclaw config set agents.defaults.models '{"provider/model":{}}' --strict-json --merge
agents.defaults.models, oragents.defaults.models), or/model list.When the rejected command included a runtime override such as /model openai/gpt-5.5 --runtime codex, fix the allowlist first, then retry the same /model ... --runtime ... command. For native Codex execution, the selected model is still openai/gpt-5.5; the codex runtime selects the harness and uses Codex auth separately.
For local/GGUF models, store the full provider-prefixed ref in the allowlist,
for example ollama/gemma4:26b, lmstudio/Gemma4-26b-a4-it-gguf, or the
exact provider/model shown by openclaw models list --provider <provider>.
Bare local filenames or display names are not enough when the allowlist is
active.
Example allowlist config:
{
agent: {
model: { primary: "anthropic/claude-sonnet-4-6" },
models: {
"anthropic/claude-sonnet-4-6": { alias: "Sonnet" },
"anthropic/claude-opus-4-6": { alias: "Opus" },
},
},
}
/model)You can switch models for the current session without restarting:
/model
/model list
/model 3
/model openai/gpt-5.4
/model status
Full command behavior/config: Slash commands.
openclaw models list
openclaw models status
openclaw models set <provider/model>
openclaw models set-image <provider/model>
openclaw models aliases list
openclaw models aliases add <alias> <provider/model>
openclaw models aliases remove <alias>
openclaw models fallbacks list
openclaw models fallbacks add <provider/model>
openclaw models fallbacks remove <provider/model>
openclaw models fallbacks clear
openclaw models image-fallbacks list
openclaw models image-fallbacks add <provider/model>
openclaw models image-fallbacks remove <provider/model>
openclaw models image-fallbacks clear
openclaw models (no subcommand) is a shortcut for models status.
models listShows configured/auth-available models by default. Useful flags:
<ParamField path="--all" type="boolean"> Full catalog. Includes bundled provider-owned static catalog rows before auth is configured, so discovery-only views can show models that are unavailable until you add matching provider credentials. </ParamField> <ParamField path="--local" type="boolean"> Local providers only. </ParamField> <ParamField path="--provider <id>" type="string"> Filter by provider id, for example `moonshot`. Display labels from interactive pickers are not accepted. </ParamField> <ParamField path="--plain" type="boolean"> One model per line. </ParamField> <ParamField path="--json" type="boolean"> Machine-readable output. </ParamField>models statusShows the resolved primary model, fallbacks, image model, and an auth overview of configured providers. It also surfaces OAuth expiry status for profiles found in the auth store (warns within 24h by default). --plain prints only the resolved primary model.
Example (Claude CLI):
claude auth login
openclaw models status
openclaw models scan inspects OpenRouter's free model catalog and can optionally probe models for tool and image support.
Scan results are ranked by:
Input:
/models list (filter :free)OPENROUTER_API_KEY (see Environment variables)--max-age-days, --min-params, --provider, --max-candidates--timeout, --concurrencyWhen live probes run in a TTY, you can select fallbacks interactively. In non-interactive mode, pass --yes to accept defaults. Metadata-only results are informational; --set-default and --set-image require live probes so OpenClaw does not configure an unusable keyless OpenRouter model.
models.json)Custom providers in models.providers are written into models.json under the agent directory (default ~/.openclaw/agents/<agentId>/agent/models.json). This file is merged by default unless models.mode is set to replace.
- Non-empty `baseUrl` already present in the agent `models.json` wins.
- Non-empty `apiKey` in the agent `models.json` wins only when that provider is not SecretRef-managed in current config/auth-profile context.
- SecretRef-managed provider `apiKey` values are refreshed from source markers (`ENV_VAR_NAME` for env refs, `secretref-managed` for file/exec refs) instead of persisting resolved secrets.
- SecretRef-managed provider header values are refreshed from source markers (`secretref-env:ENV_VAR_NAME` for env refs, `secretref-managed` for file/exec refs).
- Empty or missing agent `apiKey`/`baseUrl` fall back to config `models.providers`.
- Other provider fields are refreshed from config and normalized catalog data.