openclaw/openclaw · error · Error

Cohere model catalog response must contain models[]

Error message

Cohere model catalog response must contain models[]

What it means

Thrown by the Cohere provider catalog readRows() parser when the live model-discovery HTTP response body is missing a top-level models array. The discovery endpoint (api.cohere.com/v1/models?endpoint=chat&page_size=1000) is expected to return { models: [...] }; any other shape (error object, HTML, paginated wrapper, empty) fails fast rather than silently registering zero models.

Source

Thrown at extensions/cohere/provider-catalog.ts:15

import type { OpenAICompatibleModelDiscoveryOptions } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
import { COHERE_BASE_URL } from "./models.js";

export const COHERE_LIVE_MODEL_DISCOVERY: OpenAICompatibleModelDiscoveryOptions = {
  endpointUrl: {
    url: "https://api.cohere.com/v1/models?endpoint=chat&page_size=1000",
    requireBaseUrl: COHERE_BASE_URL,
  },
  readRows: (body) => {
    if (
      !body ||
      typeof body !== "object" ||
      !Array.isArray((body as { models?: unknown }).models)
    ) {
      throw new Error("Cohere model catalog response must contain models[]");
    }
    return (body as { models: unknown[] }).models.flatMap((row) => {
      if (!row || typeof row !== "object" || Array.isArray(row)) {
        return [];
      }
      const record = row as Record<string, unknown>;
      const modelId = typeof record.name === "string" ? record.name.trim() : "";
      return modelId ? [{ ...record, id: modelId, active: record.is_deprecated !== true }] : [];
    });
  },
};

View on GitHub (pinned to 01804a7531)

Solutions

  1. Verify the Cohere API key is valid and has access to the models endpoint.
  2. Confirm the discovery URL still uses endpoint=chat&page_size=1000 and that Cohere has not changed the response contract.
  3. Inspect the raw API response (status code + body) to identify whether it is an auth error, rate limit, or schema change.
  4. If the API contract changed, update readRows() to match the new shape or pin a compatible API version.
Defensive patterns

Strategy: validation

Validate before calling

async function cohereModelsReachable(apiKey) {
  const res = await fetch("https://api.cohere.com/v1/models?endpoint=chat&page_size=1000", {
    headers: { Authorization: `Bearer ${apiKey}` },
  });
  const body = await res.json().catch(() => null);
  return res.ok && Array.isArray(body?.models);
}

Type guard

function isCohereModelsResponse(body) {
  return !!body && typeof body === "object" && !Array.isArray(body) && Array.isArray(body.models);
}

Prevention

When it happens

Trigger: Cohere API returned an error envelope (e.g. { message: 'unauthorized' }) instead of a models list. API version change altered the response shape. Auth token invalid so the endpoint returned a JSON error object. Rate-limit or maintenance response lacking the models field.

Common situations: Expired or invalid Cohere API key causing an auth-error JSON body. Cohere API schema evolution. Network proxy returning a different envelope. Endpoint URL modified or the query param (endpoint=chat) dropped.

Related errors


AI-assisted analysis of openclaw/openclaw@01804a7531 (2026-08-12). Data as JSON: /api/errors/678615dc4b020497. Report an issue: GitHub.