Mintplex-Labs/anything-llm · error · Error
e.message
Error message
e.message
What it means
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.
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
Defensive patterns
Strategy: try-catch
Try / catch
try {
return await llm.getChatCompletion(messages);
} catch (err) {
// message is Gemini's raw error; the full object was console.error'd server-side
if (/429|RESOURCE_EXHAUSTED|quota/i.test(err.message)) return respond("Gemini quota hit — retry later.");
if (/404|not found/i.test(err.message)) return respond("Model retired — pick a current Gemini model.");
if (/401|403|API key/i.test(err.message)) return respond("Invalid GEMINI_API_KEY.");
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Gemini Failed to embed
- e.message
- e.message
- e.message
- GenericOpenAI must have a valid base path to use for the…
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/14ac8ef9517ca3db.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/gemini/index.js:390
...formatChatHistory(chatHistory, this.#generateContent),
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature: temperature,
})
.catch((e) => {
console.error(e);
throw new Error(e.message);
})
);
if (
!result.output.hasOwnProperty("choices") ||
result.output.choices.length === 0
)
return null;
return {
textResponse: result.output.choices[0].message.content,
metrics: {
prompt_tokens: result.output.usage.prompt_tokens || 0,
completion_tokens: result.output.usage.completion_tokens || 0,
total_tokens: result.output.usage.total_tokens || 0,
outputTps: result.output.usage.completion_tokens / result.duration,
duration: result.duration,
model: this.model,View on GitHub (pinned to 3aec848f28)