Mintplex-Labs/anything-llm · warning · Error

Cerebras:cacheContextWindows - ${res.statusText}

Error message

Cerebras:cacheContextWindows - ${res.statusText}

What it means

Thrown inside the static `CerebrasLLM.cacheContextWindows` when the public models endpoint `https://api.cerebras.ai/public/v1/models` returns a non-2xx status. The promise chain checks `res.ok` and throws with the response statusText. It is caught locally by the outer .catch which only logs (#slog), so the throw does not propagate to callers — context windows simply stay empty/uncached.

Source

Thrown at server/utils/AiProviders/cerebras/index.js:71

  /**
   * Cache the context windows for the LMStudio models.
   * This is done once and then cached for the lifetime of the server. This is absolutely necessary to ensure that the context windows are correct.
   *
   * This is a convenience to ensure that the context windows are correct and that the user
   * does not have to manually set the context window for each model.
   * @param {boolean} force - Force the cache to be refreshed.
   * @returns {Promise<void>} - A promise that resolves when the cache is refreshed.
   */
  static async cacheContextWindows(force = false) {
    try {
      // Skip if we already have cached context windows and we're not forcing a refresh
      if (Object.keys(CerebrasLLM.modelContextWindows).length > 0 && !force)
        return;

      await fetch("https://api.cerebras.ai/public/v1/models")
        .then((res) => {
          if (!res.ok)
            throw new Error(`Cerebras:cacheContextWindows - ${res.statusText}`);
          return res.json();
        })
        .then(({ data: models }) => {
          models.forEach((model) => {
            if (!model.limits.max_context_length) return;
            if (isNaN(model.limits.max_context_length)) return;
            CerebrasLLM.modelContextWindows[model.id] =
              model.limits.max_context_length;
          });
        })
        .catch((e) => {
          CerebrasLLM.#slog(`Error caching context windows`, e);
          return;
        });

      CerebrasLLM.#slog(`Context windows cached for all models!`);
    } catch (e) {
      CerebrasLLM.#slog(`Error caching context windows`, e);

View on GitHub (pinned to 526360e320)

Solutions

  1. Treat as transient — retry the request that triggered cacheContextWindows; the static cache retries on next construction (or pass force=true).
  2. Verify reachability: `curl -i https://api.cerebras.ai/public/v1/models` from the server host.
  3. If behind a proxy, ensure it allows the public Cerebras host and returns JSON, not a block page.
  4. If persistent, update AnythingLLM's Cerebras provider to the current public models path.

Example fix

// before
if (!res.ok)
  throw new Error(`Cerebras:cacheContextWindows - ${res.statusText}`);

// after - keep response body for diagnostics
if (!res.ok) {
  const body = await res.text().catch(() => "");
  throw new Error(
    `Cerebras:cacheContextWindows - ${res.status} ${res.statusText} ${body.slice(0,200)}`
  );
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Optional pre-check of reachability before triggering cacheContextWindows
async function cerebrosModelsReachable() {
  const res = await fetch("https://api.cerebras.ai/public/v1/models", {
    method: "GET",
    signal: AbortSignal.timeout(5000),
  });
  return res.ok;
}

Type guard

/** @param {unknown} e @returns {boolean} */
function isCerebrasStatusError(e) {
  return e instanceof Error &&
    /Cerebras:cacheContextWindows/.test(e.message);
}

Try / catch

// cacheContextWindows swallows this internally; only relevant if you call fetch yourself.
try {
  await CerebrasLLM.cacheContextWindows(true);
} catch (e) {
  // Degrade gracefully — context-window sizing falls back to defaults.
  logger.warn("Cerebras context-window cache unavailable; using defaults", e.message);
}

Prevention

When it happens

Trigger: First construction of any CerebrasLLM instance triggers cacheContextWindows; if the public models endpoint returns 4xx/5xx (e.g. 503 during a Cerebras outage, 404 if the public path moved, or a network proxy returning a non-2xx), this throws. The throw is logged, not bubbled, so users see degraded context-window sizing rather than a hard failure.

Common situations: Cerebras public models endpoint temporarily down; corporate proxy returning an error page (200 with HTML or a 4xx); DNS/routing issue; the public path changed and the SDK hasn't been updated; rate-limited on the public endpoint.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/0842a1874af44f3f. Report an issue: GitHub.