Skip to content

fix: add models.providers.*.apiKey fallback to getApiKey()#179

Closed
catgodtwno4 wants to merge 1 commit intoMartian-Engineering:mainfrom
catgodtwno4:fix/getApiKey-provider-config-fallback
Closed

fix: add models.providers.*.apiKey fallback to getApiKey()#179
catgodtwno4 wants to merge 1 commit intoMartian-Engineering:mainfrom
catgodtwno4:fix/getApiKey-provider-config-fallback

Conversation

@catgodtwno4
Copy link

Summary

Relates to #177 — LCM summarizer cannot resolve provider credentials when API key is configured via models.providers.*.apiKey rather than environment variables or auth profiles.

Problem

getApiKey() and requireApiKey() walk a fallback chain:

  1. modelAuth.getApiKeyForModel()
  2. resolveApiKey(provider, readEnv) → env vars → authProfiles

But they never read models.providers.<provider>.apiKey from the config. The main model's complete() function (line ~1217) has this fallback, but the LCM summarizer's getApiKey() does not.

Impact

When a provider's API key is only configured in models.providers.*.apiKey (common for non-built-in providers like MiniMax), the main model works fine but LCM compaction fails with 401.

Adding the env var to launchd plist doesn't fully help because getApiKey() may use a startup-time snapshot of process.env.

Fix

Add a 6th fallback layer to getApiKey() and requireApiKey() that reads models.providers.<provider>.apiKey from the config, matching the complete() function's behavior.

Verified On

Machine Config Result
Scott#2 MiniMax key only in models.providers.minimax.apiKey Before: 401 on every compaction. After: clean
Scott#4 Same config 200+ summaries, zero auth errors

Note: v0.5.1 may already partially address this via findProviderConfigValue. This PR ensures full parity between getApiKey() and complete() fallback chains.

…eApiKey()

getApiKey() and requireApiKey() were missing the models.providers config
fallback that complete() already had (line 1217-1231). This caused 401
auth errors for providers like MiniMax whose API keys are stored in
openclaw.json under models.providers.<provider>.apiKey rather than in
process.env or keychain.

The fix adds the same provider config lookup as the last fallback step
in both getApiKey() and requireApiKey(), matching the existing behavior
in complete().

Fixes: LCM 401 auth errors when summaryProvider uses a proxy provider
(e.g. MiniMax via api.minimaxi.com/anthropic) with keys only in config.
@catgodtwno4
Copy link
Author

Closing — v0.5.1 already contains findProviderConfigValue fallback in getApiKey(). This PR was based on an older commit and the diff was misleading; the fix was already shipped. Sorry for the noise! Only PR #178 (false-positive auth error) is a real fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant