{"record":{"id":"25b50a42c541c7a0","repo":"Mintplex-Labs/anything-llm","slug":"error-message","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"RetryError","httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/providers/cerebras.js","lineNumber":165,"sourceCode":"        messages,\n        functions,\n        this.getCost.bind(this),\n        { provider: this }\n      );\n\n      if (result.retryWithError) {\n        return this.complete([...messages, result.retryWithError], functions);\n      }\n\n      return result;\n    } catch (error) {\n      if (error instanceof OpenAI.AuthenticationError) throw error;\n      if (\n        error instanceof OpenAI.RateLimitError ||\n        error instanceof OpenAI.InternalServerError ||\n        error instanceof OpenAI.APIError\n      ) {\n        throw new RetryError(error.message);\n      }\n      throw error;\n    }\n  }\n\n  /**\n   * Updates the stored usage metrics from a provider response.\n   * Override in subclasses to handle provider-specific usage formats.\n   * @param {Object} usage - The usage object from the provider response\n   * @param {Object} time_info - The time info object from the provider response (Cerebras specific)\n   */\n  recordUsage(usage = {}, time_info = {}) {\n    // assume start time\n    let duration = (Date.now() - this._requestStartTime) / 1000;\n    const promptTokens = usage.prompt_tokens || 0;\n    const completionTokens = usage.completion_tokens || 0;\n    if (time_info?.completion_time) duration = time_info.completion_time;\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/providers/cerebras.js#L147-L183","documentation":"Cerebras provider's `complete()` classifies OpenAI SDK errors. `OpenAI.AuthenticationError` is re-thrown unchanged (auth failures are fatal, not retryable). `RateLimitError`, `InternalServerError`, or any other `APIError` is wrapped as `RetryError(error.message)` — the framework's signal that the failure is transient and the outer agent loop should retry the turn. Anything else (network, programming bug) is re-thrown unchanged. Cerebras is an OpenAI-compatible inference service tuned for high throughput.","triggerScenarios":"Cerebras returns 429 (tokens-per-minute or requests-per-minute ceiling hit); 5xx from the Cerebras gateway; transient APIError mid-completion (e.g. the model briefly unavailable); a bad or deprecated model slug surfaced as APIError.","commonSituations":"Cerebras free-tier TPM limit hit on a long context window; CEREBRAS_MODEL_PREF pointing at a model Cerebras rotated out; a brief Cerebras platform outage; mismatched model name against the Cerebras catalog.","solutions":["Let the framework's RetryError handling re-attempt the turn — that is the intended response to RetryError.","If it repeatedly fails with 429, lower the request rate, shorten the context, or upgrade the Cerebras tier.","Verify CEREBRAS_MODEL_PREF is a slug Cerebras currently serves (it rotates model names).","Confirm CEREBRAS_API_KEY is valid — if not, you would see AuthenticationError, not RetryError.","Check the Cerebras status page for an ongoing incident."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Budget-aware preflight: estimate tokens and skip if obviously over the Cerebras TPM limit.\nfunction wouldExceedCerebrasTpm(estimatedTokens, tpmLimit) {\n  return typeof tpmLimit === 'number' && estimatedTokens > tpmLimit * 0.9;\n}","typeGuard":"function isRetryableProviderError(e) {\n  return e instanceof OpenAI.RateLimitError\n      || e instanceof OpenAI.InternalServerError\n      || e instanceof OpenAI.APIError;\n}","tryCatchPattern":"// Outer agent loop: honor RetryError, surface auth immediately.\ntry {\n  return await provider.complete(messages, functions);\n} catch (e) {\n  if (e instanceof OpenAI.AuthenticationError) throw e;     // fatal\n  if (e instanceof RetryError) await backoffAndRetry();      // transient\n  else throw e;\n}","preventionTips":["Confirm CEREBRAS_API_KEY and a current model slug at startup.","Watch TPM/RPM; Cerebras free tier throttles aggressively on long contexts.","Treat RetryError as the framework's transient signal — do not classify it as fatal.","Differentiate auth (fatal) from rate/internal (retryable) in your outer loop."],"tags":["llm-provider","cerebras","retry","rate-limit","openai-sdk"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}