Mintplex-Labs/anything-llm · error · Error

e.message

Error message

e.message

What it means

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.

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 526360e320)

Solutions

  1. Inspect the console.error output (it still prints the full SDK error) for status code and type
  2. If 429, wait and/or enable billing/quota in Google AI Studio
  3. If using a Gemma model, ensure system prompts are stripped (NO_SYSTEM_PROMPT_MODELS path)
  4. Confirm GEMINI_LLM_MODEL_PREF is a currently valid model id

Example fix

// before
.catch((e) => { console.error(e); throw new Error(e.message); })

// after
.catch((e) => { console.error(e); throw e; })
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await llm.getChatCompletion(messages, { temperature });
} catch (e) {
  const msg = e.message;
  if (/quota|429/i.test(msg)) throw new RateLimitError(msg);
  if (/401|invalid_api_key/i.test(msg)) throw new AuthError(msg);
  if (/system role.*not supported|gemma/i.test(msg)) {
    // strip system prompt for NO_SYSTEM_PROMPT_MODELS and retry
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/14ac8ef9517ca3db. Report an issue: GitHub.