Mintplex-Labs/anything-llm · error · RetryError

Gemini error

Error message

Gemini error: ${this._lastErrorMessage}

What it means

Surfaced inside the Gemini provider's stream catch block after #logAPIError records the upstream failure: the stored _lastErrorMessage is prefixed with 'Gemini error:' to attribute the failure to the Gemini API rather than a local issue. It fires whenever the Gemini/Underlying OpenAI-compatible call throws mid-stream (auth, rate limit, server, or network errors); auth errors are rethrown, others are converted into a failed textResponse.

Solutions

  1. Read the recorded Gemini error message for the root cause.
  2. Verify the Gemini API key, model name, and quota, then retry.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: The Gemini API returned an error during a chat or streaming request.

Common situations: This error is raised at runtime in server/utils/agents/aibitat/providers/gemini.js. It occurs when the required configuration for this provider is missing or invalid (unset environment variables, empty API key or base path), when the external service is unreachable or returns an unexpected response, or when invalid input reaches the call site. To prevent it, validate the relevant provider settings and environment variables at startup and confirm the service is reachable before this code path executes.


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/8cf39d491d159b64. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/agents/aibitat/providers/gemini.js:362

      return {
        textResponse: completion.content,
        functionCall: null,
        cost: this.getCost(),
        uuid: msgUUID,
      };
    } catch (error) {
      this.#logAPIError(error);
      const errorMsg = this._lastErrorMessage
        ? `Gemini error: ${this._lastErrorMessage}`
        : error.message;
      this._lastErrorMessage = null;
      if (error instanceof OpenAI.AuthenticationError) throw error;
      if (
        error instanceof OpenAI.RateLimitError ||
        error instanceof OpenAI.InternalServerError ||
        error instanceof OpenAI.APIError // Also will catch AuthenticationError!!!
      ) {
        throw new RetryError(errorMsg);
      }

      throw error;
    }
  }

  /**
   * Create a completion based on the received messages.
   *
   * @param messages A list of messages to send to the Gemini API.
   * @param functions
   * @returns The completion.
   */
  async complete(messages, functions = []) {
    if (!this.supportsToolCalling)
      throw new Error(`Gemini: ${this.model} does not support tool calling.`);
    this.providerLog("Gemini.complete - will process this chat completion.");
    this.resetUsage();

View on GitHub (pinned to 20f6d3546c)