{"record":{"id":"de74d8a63a92a8c3","repo":"Mintplex-Labs/anything-llm","slug":"error-message-de74d8","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"RetryError","httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/providers/moonshotAi.js","lineNumber":93,"sourceCode":"\n    try {\n      return await tooledStream(\n        this.client,\n        this.model,\n        messages,\n        functions,\n        eventHandler,\n        { provider: this }\n      );\n    } catch (error) {\n      console.error(error.message, 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  async complete(messages, functions = []) {\n    const useNative = this.supportsNativeToolCalling();\n\n    if (!useNative) {\n      return await UnTooled.prototype.complete.call(\n        this,\n        messages,\n        functions,\n        this.#handleFunctionCallChat.bind(this)\n      );\n    }\n\n    try {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/agents/aibitat/providers/moonshotAi.js#L75-L111","documentation":"MoonshotAiProvider.stream() wraps failures from the streaming tool-call request to https://api.moonshot.ai/v1: OpenAI RateLimitError, InternalServerError, or any APIError is rethrown as aibitat's RetryError carrying the original message; AuthenticationError (invalid MOONSHOT_AI_API_KEY) is rethrown unwrapped; other errors pass through. The full error object is printed first via console.error, so the console log is the diagnostic source. RetryError tells the agent engine the failure is retryable, though non-transient 4xx causes (bad model id) get wrapped too.","triggerScenarios":"Streaming chat.completions.create with apiKey process.env.MOONSHOT_AI_API_KEY returning 429 (Moonshot RPM/TPM tier limits — agent tool loops burst quickly), 5xx provider incidents, or 404/400 when this.model (default \"moonshot-v1-32k\") names a deprecated or non-existent model for the key's account.","commonSituations":"Moonshot renaming/retiring v1 model ids so the default stops resolving; free-tier keys hitting RPM limits as the agent fires tool-call round trips back-to-back; expired API key raising rejections on every request; transient 5xx during Moonshot maintenance windows.","solutions":["Read the console log (raw error is printed here) and the status in the message: 429 -> back off and retry, 4xx -> fix model or key, 5xx -> retry later","Verify MOONSHOT_AI_API_KEY with a direct curl to https://api.moonshot.ai/v1/models","Pin a currently valid model id (e.g. from Moonshot's model list) in the provider config instead of an old default","For repeated 429s, throttle agent tool-call concurrency or upgrade the key's rate tier"],"exampleFix":"# before\nMOONSHOT_AI_API_KEY=<key>\n# provider config model: moonshot-v1-32k (retired) -> 404 -> RetryError\n\n# after\nnew MoonshotAiProvider({ model: \"moonshot-v1-128k\" })  # id confirmed via GET /v1/models","handlingStrategy":"try-catch","validationCode":"// Pre-flight key + model\nif (!process.env.MOONSHOT_AI_API_KEY) throw new Error(\"MOONSHOT_AI_API_KEY not set\");\nconst models = await fetch(\"https://api.moonshot.ai/v1/models\", {\n  headers: { Authorization: `Bearer ${process.env.MOONSHOT_AI_API_KEY}` },\n}).then(r => r.json());\nif (!Array.isArray(models.data) || !models.data.some(m => m.id === provider.model)) throw new Error(`Unknown moonshot model ${provider.model}`);","typeGuard":"const { RetryError } = require(\"./server/utils/agents/aibitat/error.js\");\nconst isRetryError = (e) => e instanceof RetryError;","tryCatchPattern":"try {\n  return await provider.stream(messages, functions, eventHandler);\n} catch (error) {\n  if (error instanceof OpenAI.AuthenticationError) throw error; // 401: fix key, do not retry\n  if (error instanceof RetryError && /429|5\\d\\d/.test(error.message)) return withBackoff(retryStream);\n  throw error;\n}","preventionTips":["Resolve model ids from GET /v1/models instead of hardcoding; Moonshot retires old names","Stay under your key's RPM by spacing agent tool rounds","Correlate with the console log (raw error is printed here)","Alert on repeated 429s so you upgrade tiers before hard failure"],"tags":["llm-provider","moonshot","openai-sdk","retry-error","rate-limit","streaming"],"backgroundTag":"openai-api-error","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}