openclaw - ✅(Solved) Fix HTTP /v1/chat/completions fails: provider?.models?.some is not a function [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#66744Fetched 2026-04-15 06:24:34
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×2referenced ×2

Error Message

[model-catalog] Failed to load model catalog: TypeError: provider?.models?.some is not a function
[openai-compat] chat completion failed: TypeError: provider?.models?.some is not a function

Root Cause

The HTTP /v1/chat/completions endpoint returns {"error":{"message":"internal error","type":"api_error"}} on every request. Root cause is a TypeError in the model-catalog subsystem.

Fix Action

Workaround

Using WebSocket access (Telegram/CLI). HTTP API needed for programmatic integrations.

PR fix notes

PR #66761: fix(models): guard provider.models against non-array values (#66744)

Description (problem / solution / changelog)

Summary

  • Fixes #66744
  • HTTP `/v1/chat/completions` crashed with `provider?.models?.some is not a function` when the gateway was configured with runtime-constructed providers (e.g. openrouter plugin) that surface `provider.models` as a non-array value.
  • Optional chaining on `.some(...)` does not guard against non-array intermediates — it only short-circuits on null/undefined. Wrap the access in `Array.isArray(...)` so the lookup falls through to the provider-key default instead of throwing.

Why narrow

I intentionally did not touch the upstream plugin that surfaces a non-array `models` — that's a separate, broader fix. This change just stops the current call site from taking down HTTP chat completions for every request, which is the user-visible regression in the issue.

Test plan

  • `pnpm vitest run src/agents/models-config.providers.policy.lookup.test.ts` — 7/7 pass (4 existing + 3 new regression cases)
  • `pnpm check` (via pre-commit) — green
  • Existing google-generative-ai routing for array-shaped `models` still passes

AI-assisted disclosure

  • AI-assisted (Claude)
  • Testing: fully tested — regression coverage for object-map `models`, undefined `models`, and fall-through behavior.
  • Prompt context: issue #66744 stack trace plus reads of `src/agents/models-config.providers.policy.lookup.ts` and its existing test file.
  • I understand what the code does.

Changed files

  • src/agents/models-config.providers.policy.lookup.test.ts (modified, +36/-0)
  • src/agents/models-config.providers.policy.lookup.ts (modified, +6/-1)

PR #66779: fix: guard against non-array models in provider lookup

Description (problem / solution / changelog)

Summary

Fixes TypeError provider?.models?.some is not a function on HTTP /v1/chat/completions endpoint.

Root Cause

resolveProviderPluginLookupKey() in src/agents/models-config.providers.policy.lookup.ts used optional chaining provider?.models?.some(), which only guards against provider or models\* being undefined. When a runtime-constructed provider (e.g., openrouter plugin) has models* defined as a non-array value, `.some()* is not a function and crashes.

Fix

Changed to Array.isArray(provider?.models) && provider.models.some(...)\* to explicitly verify models* is an array before calling array methods.

Test Plan

  • HTTP `/v1/chat/completions* endpoint works with multiple providers configured
  • Unit tests pass

Closes openclaw#66744

Changed files

  • src/agents/models-config.providers.policy.lookup.ts (modified, +2/-1)

Code Example

[model-catalog] Failed to load model catalog: TypeError: provider?.models?.some is not a function
[openai-compat] chat completion failed: TypeError: provider?.models?.some is not a function
RAW_BUFFERClick to expand / collapse

Bug Description

The HTTP /v1/chat/completions endpoint returns {"error":{"message":"internal error","type":"api_error"}} on every request. Root cause is a TypeError in the model-catalog subsystem.

Error

[model-catalog] Failed to load model catalog: TypeError: provider?.models?.some is not a function
[openai-compat] chat completion failed: TypeError: provider?.models?.some is not a function

Environment

  • OpenClaw: 2026.4.14 (323493f) and 2026.4.9
    • OS: Windows 10.0.26200
      • Node.js: v24.13.1
        • Gateway: bind=lan, port=18789, auth=token, chatCompletions enabled

Steps to Reproduce

  1. Configure gateway with multiple providers (custom/ollama, openai, openrouter, groq)
    1. Enable the openrouter plugin
    1. Start gateway
    1. POST to /v1/chat/completions with valid Bearer token and model: "openclaw/main"
    1. Returns internal error every time

Key Observations

  • WebSocket-based access works perfectly (Telegram, Slack, CLI)
    • Only HTTP /v1/chat/completions is affected
      • All providers in openclaw.json have models as proper arrays (verified programmatically)
        • Error occurs in model-catalog subsystem suggesting a runtime-constructed provider (possibly openrouter plugin) returns models as non-array
          • Consistent across restarts and version updates

Expected

HTTP chat completions should work like WebSocket chat.

Workaround

Using WebSocket access (Telegram/CLI). HTTP API needed for programmatic integrations.

extent analysis

TL;DR

The most likely fix is to ensure that the models property of all providers, including those constructed at runtime like the openrouter plugin, is an array to prevent the TypeError in the model-catalog subsystem.

Guidance

  • Verify that the openrouter plugin correctly returns its models as an array, as the error suggests a non-array value is being passed to the some function.
  • Check the implementation of the model-catalog subsystem to ensure it handles providers with non-array models properties gracefully, potentially by adding a type check or normalization step.
  • Inspect the openclaw.json configuration file to confirm that all providers, including custom ones, have their models defined as arrays, even though the issue mentions this has been programmatically verified.
  • Consider adding logging or debugging statements to the model-catalog subsystem to capture more information about the provider causing the error, which could help in pinpointing the exact issue.

Example

No specific code example can be provided without knowing the exact implementation details of the openrouter plugin or the model-catalog subsystem. However, a general example of ensuring an object property is an array might look like:

if (!Array.isArray(provider.models)) {
  provider.models = [provider.models]; // or handle the case appropriately
}

This is purely speculative and would need adjustment based on the actual codebase.

Notes

The issue seems to be related to how providers are handled, especially those added at runtime. Ensuring consistency in how models are represented across all providers will be key to resolving this issue.

Recommendation

Apply a workaround by modifying the openrouter plugin or the model-catalog subsystem to ensure all providers return their models as arrays, as this directly addresses the reported TypeError. Upgrading to a fixed version is not mentioned as an option in the provided issue context.

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 - ✅(Solved) Fix HTTP /v1/chat/completions fails: provider?.models?.some is not a function [2 pull requests, 1 participants]