{"record":{"id":"0842a1874af44f3f","repo":"Mintplex-Labs/anything-llm","slug":"cerebras-cachecontextwindows-res-statustext","errorCode":null,"errorMessage":"Cerebras:cacheContextWindows - ${res.statusText}","messagePattern":"Cerebras:cacheContextWindows - (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/utils/AiProviders/cerebras/index.js","lineNumber":71,"sourceCode":"  /**\n   * Cache the context windows for the LMStudio models.\n   * 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.\n   *\n   * This is a convenience to ensure that the context windows are correct and that the user\n   * does not have to manually set the context window for each model.\n   * @param {boolean} force - Force the cache to be refreshed.\n   * @returns {Promise<void>} - A promise that resolves when the cache is refreshed.\n   */\n  static async cacheContextWindows(force = false) {\n    try {\n      // Skip if we already have cached context windows and we're not forcing a refresh\n      if (Object.keys(CerebrasLLM.modelContextWindows).length > 0 && !force)\n        return;\n\n      await fetch(\"https://api.cerebras.ai/public/v1/models\")\n        .then((res) => {\n          if (!res.ok)\n            throw new Error(`Cerebras:cacheContextWindows - ${res.statusText}`);\n          return res.json();\n        })\n        .then(({ data: models }) => {\n          models.forEach((model) => {\n            if (!model.limits.max_context_length) return;\n            if (isNaN(model.limits.max_context_length)) return;\n            CerebrasLLM.modelContextWindows[model.id] =\n              model.limits.max_context_length;\n          });\n        })\n        .catch((e) => {\n          CerebrasLLM.#slog(`Error caching context windows`, e);\n          return;\n        });\n\n      CerebrasLLM.#slog(`Context windows cached for all models!`);\n    } catch (e) {\n      CerebrasLLM.#slog(`Error caching context windows`, e);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/cerebras/index.js#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Treat as transient — retry the request that triggered cacheContextWindows; the static cache retries on next construction (or pass force=true).","Verify reachability: `curl -i https://api.cerebras.ai/public/v1/models` from the server host.","If behind a proxy, ensure it allows the public Cerebras host and returns JSON, not a block page.","If persistent, update AnythingLLM's Cerebras provider to the current public models path."],"exampleFix":"// before\nif (!res.ok)\n  throw new Error(`Cerebras:cacheContextWindows - ${res.statusText}`);\n\n// after - keep response body for diagnostics\nif (!res.ok) {\n  const body = await res.text().catch(() => \"\");\n  throw new Error(\n    `Cerebras:cacheContextWindows - ${res.status} ${res.statusText} ${body.slice(0,200)}`\n  );\n}","handlingStrategy":"try-catch","validationCode":"// Optional pre-check of reachability before triggering cacheContextWindows\nasync function cerebrosModelsReachable() {\n  const res = await fetch(\"https://api.cerebras.ai/public/v1/models\", {\n    method: \"GET\",\n    signal: AbortSignal.timeout(5000),\n  });\n  return res.ok;\n}","typeGuard":"/** @param {unknown} e @returns {boolean} */\nfunction isCerebrasStatusError(e) {\n  return e instanceof Error &&\n    /Cerebras:cacheContextWindows/.test(e.message);\n}","tryCatchPattern":"// cacheContextWindows swallows this internally; only relevant if you call fetch yourself.\ntry {\n  await CerebrasLLM.cacheContextWindows(true);\n} catch (e) {\n  // Degrade gracefully — context-window sizing falls back to defaults.\n  logger.warn(\"Cerebras context-window cache unavailable; using defaults\", e.message);\n}","preventionTips":["Treat the public models endpoint as best-effort; never block construction on it.","Ensure outbound HTTPS to api.cerebras.ai is allowed by proxies/firewalls.","Log but don't fail when the cache can't refresh — feature should degrade, not break.","Retry the cache refresh on a schedule (e.g. next construction) rather than spamming."],"tags":["network","api","cerebras","caching","degraded"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}