openclaw - 💡(How to fix) Fix image tool fails with Unknown model for non-built-in providers (validateConfig rejects missing apiKey) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70256Fetched 2026-04-23 07:27:08
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
commented ×1

The image tool fails with Unknown model: <provider>/<model> for any non-built-in provider (e.g. bailian, mimo, moonshot), even when the model is correctly configured with input: ["text", "image"] in models.json and the API key is properly stored in auth-profiles.json.

Error Message

throw new Error(Provider ${providerName}: "apiKey" is required when defining custom models.); 2. modelRegistry.find() returns null → "Unknown model" error 4. Error: Unknown model: bailian/qwen3.5-plus

Root Cause

The image tool uses pi-coding-agent's ModelRegistry to discover models. The ModelRegistry.validateConfig() method requires that non-built-in providers with custom models must have apiKey in the models.json config:

// pi-coding-agent/dist/core/model-registry.js:355
if (!providerConfig.apiKey) {
    throw new Error(`Provider ${providerName}: "apiKey" is required when defining custom models.`);
}

However, ensureOpenClawModelsJson() intentionally omits API keys from models.json (security best practice — keys are stored in auth-profiles.json). This causes:

  1. validateConfig() throws → custom models are discarded
  2. modelRegistry.find() returns null → "Unknown model" error
  3. Only built-in providers (openai, anthropic, etc.) remain available

Meanwhile, the regular chat completion works fine because it reads API keys from auth storage via a different code path.

Code Example

// pi-coding-agent/dist/core/model-registry.js:355
if (!providerConfig.apiKey) {
    throw new Error(`Provider ${providerName}: "apiKey" is required when defining custom models.`);
}

---

Provider mimo: "apiKey" is required when defining custom models.
RAW_BUFFERClick to expand / collapse

Description

The image tool fails with Unknown model: <provider>/<model> for any non-built-in provider (e.g. bailian, mimo, moonshot), even when the model is correctly configured with input: ["text", "image"] in models.json and the API key is properly stored in auth-profiles.json.

Root Cause

The image tool uses pi-coding-agent's ModelRegistry to discover models. The ModelRegistry.validateConfig() method requires that non-built-in providers with custom models must have apiKey in the models.json config:

// pi-coding-agent/dist/core/model-registry.js:355
if (!providerConfig.apiKey) {
    throw new Error(`Provider ${providerName}: "apiKey" is required when defining custom models.`);
}

However, ensureOpenClawModelsJson() intentionally omits API keys from models.json (security best practice — keys are stored in auth-profiles.json). This causes:

  1. validateConfig() throws → custom models are discarded
  2. modelRegistry.find() returns null → "Unknown model" error
  3. Only built-in providers (openai, anthropic, etc.) remain available

Meanwhile, the regular chat completion works fine because it reads API keys from auth storage via a different code path.

Reproduction

  1. Configure a non-built-in provider (e.g. bailian) with a vision-capable model in openclaw.json
  2. Set agents.defaults.imageModel to bailian/qwen3.5-plus
  3. Call the image tool
  4. Error: Unknown model: bailian/qwen3.5-plus

Verified by loading the ModelRegistry directly:

Provider mimo: "apiKey" is required when defining custom models.

Expected Behavior

The image tool should work with any provider that has an API key in auth storage, regardless of whether the key is also present in models.json. The validateConfig check should either:

  1. Not require apiKey when auth storage has credentials for the provider, or
  2. OpenClaw should include API keys in the generated models.json (less ideal for security)

Environment

  • OpenClaw version: latest (Node.js v22.22.1)
  • OS: macOS (Darwin 24.6.0)
  • Affected providers: all non-built-in providers (bailian, mimo, moonshot, omlx, etc.)

extent analysis

TL;DR

The image tool fails for non-built-in providers due to a missing apiKey in models.json, which is omitted for security reasons, and can be fixed by modifying the validateConfig method to check auth storage for API keys.

Guidance

  • Modify the ModelRegistry.validateConfig() method to check for API keys in auth storage instead of requiring them in models.json.
  • Update the ensureOpenClawModelsJson() function to include API keys in models.json only if necessary, while maintaining security best practices.
  • Verify the fix by loading the ModelRegistry directly and checking for the presence of custom models.
  • Test the image tool with non-built-in providers to ensure it works as expected.

Example

// Modified ModelRegistry.validateConfig() method
if (!providerConfig.apiKey && !authStorage.hasApiKey(providerName)) {
    throw new Error(`Provider ${providerName}: "apiKey" is required when defining custom models.`);
}

Notes

This fix assumes that the authStorage object has a hasApiKey method that checks for the presence of an API key for a given provider. The implementation of this method is not provided in the issue.

Recommendation

Apply workaround: Modify the validateConfig method to check auth storage for API keys, as this approach maintains security best practices while allowing the image tool to work with non-built-in providers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix image tool fails with Unknown model for non-built-in providers (validateConfig rejects missing apiKey) [1 comments, 2 participants]