diff --git a/src/agents/model-auth.ts b/src/agents/model-auth.ts index e494cc71b8c..09e5c0397d9 100644 --- a/src/agents/model-auth.ts +++ b/src/agents/model-auth.ts @@ -167,6 +167,18 @@ function resolveSyntheticLocalProviderAuth(params: { cfg: OpenClawConfig | undefined; provider: string; }): ResolvedProviderAuth | null { + // Check for known local providers first — these should always get synthetic auth, + // even when the user sets models.primary without running the provider setup wizard + // (i.e., no explicit models.providers.{name} config entry exists). + const normalizedProvider = normalizeProviderId(params.provider); + if (normalizedProvider === "ollama") { + return { + apiKey: OLLAMA_LOCAL_AUTH_MARKER, + source: "models.providers.ollama (synthetic local key)", + mode: "api-key", + }; + } + const providerConfig = resolveProviderConfig(params.cfg, params.provider); if (!providerConfig) { return null; @@ -180,15 +192,6 @@ function resolveSyntheticLocalProviderAuth(params: { return null; } - const normalizedProvider = normalizeProviderId(params.provider); - if (normalizedProvider === "ollama") { - return { - apiKey: OLLAMA_LOCAL_AUTH_MARKER, - source: "models.providers.ollama (synthetic local key)", - mode: "api-key", - }; - } - const authOverride = resolveProviderAuthOverride(params.cfg, params.provider); if (authOverride && authOverride !== "api-key") { return null;