{"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/gemini/index.js#L372-L408","documentation":"GeminiLLM.getChatCompletion wraps the OpenAI-compatible chat completion call in a .catch that logs the original error to console and rethrows new Error(e.message). This is a passthrough of the underlying SDK error: typical causes are 400 INVALID_ARGUMENT (unsupported parameter or unsupported model for the OpenAI-compat layer), 429 quota exhaustion, 401/403 key problems, or 404 for a deprecated model id. The console.error means the full structured error (status, code) is visible in server logs even though only the message propagates.","triggerScenarios":"chat.completions.create against generativelanguage.googleapis.com/v1beta/openai/ failing: e.g. temperature outside allowed range for a thinking model, model id like a retired gemini-1.x, free-tier rate limit (429 RESOURCE_EXHAUSTED), or invalid API key. Note the class routes experimental models to a v1beta endpoint and some models (gemma list) can't take a system prompt.","commonSituations":"Google deprecated/renamed the pinned model (e.g. old gemini-pro ids); free tier quota hit at peak; key restricted by API key settings (referrer/IP restrictions); using a gemini model variant that rejects the system-role message the prompt builder always prepends.","solutions":["Check the server console — the original error with HTTP status is logged just above; fix per status (429=quota/billing, 401=key, 404=model gone)","Update the model to a current id (default here is gemini-2.0-flash-lite) via workspace pref or GEMINI_LLM_MODEL_PREF","If 429, enable billing or wait for the quota window; check Google AI Studio quotas","If the inner message mentions system role / system_instruction, switch away from the gemma no-system-prompt models or adjust the prompt construction"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages);\n} catch (err) {\n  // message is Gemini's raw error; the full object was console.error'd server-side\n  if (/429|RESOURCE_EXHAUSTED|quota/i.test(err.message)) return respond(\"Gemini quota hit — retry later.\");\n  if (/404|not found/i.test(err.message)) return respond(\"Model retired — pick a current Gemini model.\");\n  if (/401|403|API key/i.test(err.message)) return respond(\"Invalid GEMINI_API_KEY.\");\n  throw err;\n}","preventionTips":["Check server logs for the structured error (status/code) logged right before the rethrow","Pin current model ids and review them when Google deprecates models","Stay under free-tier RPM or enable billing; back off on 429 rather than retrying immediately"],"tags":["gemini","openai-compat","api-error-passthrough","quota"],"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-23T08:17:48.524Z"}