Model failover
OpenClaw handles failures in two stages:- Auth profile rotation within the current provider.
- Model fallback to the next model in
agents.defaults.model.fallbacks.
Auth storage (keys + OAuth)
OpenClaw uses auth profiles for both API keys and OAuth tokens.- Secrets live in
~/.openclaw/agents/<agentId>/agent/auth-profiles.json(legacy:~/.openclaw/agent/auth-profiles.json). - Config
auth.profiles/auth.orderare metadata + routing only (no secrets). - Legacy import-only OAuth file:
~/.openclaw/credentials/oauth.json(imported intoauth-profiles.jsonon first use).
type: "api_key"â{ provider, key }type: "oauth"â{ provider, access, refresh, expires, email? }(+projectId/enterpriseUrlfor some providers)
Profile IDs
OAuth logins create distinct profiles so multiple accounts can coexist.- Default:
provider:defaultwhen no email is available. - OAuth with email:
provider:<email>(for examplegoogle-antigravity:user@gmail.com).
~/.openclaw/agents/<agentId>/agent/auth-profiles.json under profiles.
Rotation order
When a provider has multiple profiles, OpenClaw chooses an order like this:- Explicit config:
auth.order[provider](if set). - Configured profiles:
auth.profilesfiltered by provider. - Stored profiles: entries in
auth-profiles.jsonfor the provider.
- Primary key: profile type (OAuth before API keys).
- Secondary key:
usageStats.lastUsed(oldest first, within each type). - Cooldown/disabled profiles are moved to the end, ordered by soonest expiry.
Session stickiness (cache-friendly)
OpenClaw pins the chosen auth profile per session to keep provider caches warm. It does not rotate on every request. The pinned profile is reused until:- the session is reset (
/new//reset) - a compaction completes (compaction count increments)
- the profile is in cooldown/disabled
/model âŚ@<profileId> sets a user override for that session
and is not autoârotated until a new session starts.
Autoâpinned profiles (selected by the session router) are treated as a preference:
they are tried first, but OpenClaw may rotate to another profile on rate limits/timeouts.
Userâpinned profiles stay locked to that profile; if it fails and model fallbacks
are configured, OpenClaw moves to the next model instead of switching profiles.
Why OAuth can âlook lostâ
If you have both an OAuth profile and an API key profile for the same provider, roundârobin can switch between them across messages unless pinned. To force a single profile:- Pin with
auth.order[provider] = ["provider:profileId"], or - Use a per-session override via
/model âŚwith a profile override (when supported by your UI/chat surface).
Cooldowns
When a profile fails due to auth/rateâlimit errors (or a timeout that looks like rate limiting), OpenClaw marks it in cooldown and moves to the next profile. Format/invalidârequest errors (for example Cloud Code Assist tool call ID validation failures) are treated as failoverâworthy and use the same cooldowns. OpenAI-compatible stop-reason errors such asUnhandled stop reason: error,
stop reason: error, and reason: error are classified as timeout/failover
signals.
Cooldowns use exponential backoff:
- 1 minute
- 5 minutes
- 25 minutes
- 1 hour (cap)
auth-profiles.json under usageStats:
Billing disables
Billing/credit failures (for example âinsufficient creditsâ / âcredit balance too lowâ) are treated as failoverâworthy, but theyâre usually not transient. Instead of a short cooldown, OpenClaw marks the profile as disabled (with a longer backoff) and rotates to the next profile/provider. State is stored inauth-profiles.json:
- Billing backoff starts at 5 hours, doubles per billing failure, and caps at 24 hours.
- Backoff counters reset if the profile hasnât failed for 24 hours (configurable).
Model fallback
If all profiles for a provider fail, OpenClaw moves to the next model inagents.defaults.model.fallbacks. This applies to auth failures, rate limits, and
timeouts that exhausted profile rotation (other errors do not advance fallback).
When a run starts with a model override (hooks or CLI), fallbacks still end at
agents.defaults.model.primary after trying any configured fallbacks.
Related config
See Gateway configuration for:auth.profiles/auth.orderauth.cooldowns.billingBackoffHours/auth.cooldowns.billingBackoffHoursByProviderauth.cooldowns.billingMaxHours/auth.cooldowns.failureWindowHoursagents.defaults.model.primary/agents.defaults.model.fallbacksagents.defaults.imageModelrouting
This page is sourced from openclaw/openclaw.