{"record":{"id":"14ac8ef9517ca3db","repo":"Mintplex-Labs/anything-llm","slug":"e-message-14ac8e","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/gemini/index.js","lineNumber":390,"sourceCode":"      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature: temperature,\n        })\n        .catch((e) => {\n          console.error(e);\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: result.output.usage.prompt_tokens || 0,\n        completion_tokens: result.output.usage.completion_tokens || 0,\n        total_tokens: result.output.usage.total_tokens || 0,\n        outputTps: result.output.usage.completion_tokens / result.duration,\n        duration: result.duration,\n        model: this.model,","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/gemini/index.js#L372-L408","documentation":"Not a distinct error — the message is whatever the OpenAI SDK raised against Google's Gemini OpenAI-compatible endpoint. The `.catch((e) => { console.error(e); throw new Error(e.message); })` wrapper logs the full error then re-throws only e.message, discarding the SDK error class (RateLimitError, BadRequestError, etc.) and the original stack.","triggerScenarios":"this.openai.chat.completions.create({ model, messages, temperature }) rejecting: invalid model id (e.g. a gemma variant needing NO_SYSTEM_PROMPT_MODELS handling), 429 quota, 401 bad key, 400 from sending a system prompt to a model that rejects it, or a malformed message payload.","commonSituations":"Quota exhausted on the free tier; using a Gemma model that does not accept system-role messages; deprecated/renamed Gemini model id; regional availability; key revoked after rollout.","solutions":["Inspect the console.error output (it still prints the full SDK error) for status code and type","If 429, wait and/or enable billing/quota in Google AI Studio","If using a Gemma model, ensure system prompts are stripped (NO_SYSTEM_PROMPT_MODELS path)","Confirm GEMINI_LLM_MODEL_PREF is a currently valid model id"],"exampleFix":"// before\n.catch((e) => { console.error(e); throw new Error(e.message); })\n\n// after\n.catch((e) => { console.error(e); throw e; })","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const msg = e.message;\n  if (/quota|429/i.test(msg)) throw new RateLimitError(msg);\n  if (/401|invalid_api_key/i.test(msg)) throw new AuthError(msg);\n  if (/system role.*not supported|gemma/i.test(msg)) {\n    // strip system prompt for NO_SYSTEM_PROMPT_MODELS and retry\n  }\n  throw e;\n}","preventionTips":["Re-throw the original SDK error to keep its type and status code","Strip system-role messages for Gemma models (NO_SYSTEM_PROMPT_MODELS) before sending","Watch quota headers and back off proactively"],"tags":["gemini","openai-sdk","error-wrapping","chat-completion","authentication"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}