Mintplex-Labs/anything-llm · critical · Error

No Gemini API key was set.

Error message

No Gemini API key was set.

What it means

Thrown in the GeminiEmbedder constructor when process.env.GEMINI_EMBEDDING_API_KEY is falsy. Note the specific var name includes the EMBEDDING segment; it is separate from a general Gemini LLM key. The embedder targets Google's OpenAI-compatible endpoint https://generativelanguage.googleapis.com/v1beta/openai/.

Source

Thrown at server/utils/EmbeddingEngines/gemini/index.js:10

const { toChunks, reportEmbeddingProgress } = require("../../helpers");

const MODEL_MAP = {
  "gemini-embedding-001": 2048,
};

class GeminiEmbedder {
  constructor() {
    if (!process.env.GEMINI_EMBEDDING_API_KEY)
      throw new Error("No Gemini API key was set.");

    this.className = "GeminiEmbedder";
    const { OpenAI: OpenAIApi } = require("openai");
    this.model = process.env.EMBEDDING_MODEL_PREF || "gemini-embedding-001";
    this.openai = new OpenAIApi({
      apiKey: process.env.GEMINI_EMBEDDING_API_KEY,
      // Even models that are v1 in gemini API can be used with v1beta/openai/ endpoint and nobody knows why.
      baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
    });

    this.maxConcurrentChunks = 4;

    // https://ai.google.dev/gemini-api/docs/models/gemini#text-embedding-and-embedding
    this.embeddingMaxChunkLength = MODEL_MAP[this.model] || 2_048;
    this.log(
      `Initialized with ${this.model} - Max Size: ${this.embeddingMaxChunkLength}` +
        (this.outputDimensions
          ? ` - Output Dimensions: ${this.outputDimensions}`

View on GitHub (pinned to 526360e320)

Solutions

  1. Set GEMINI_EMBEDDING_API_KEY (exact name, with the _EMBEDDING_ segment) to a Google AI Studio / Generative Language API key.
  2. Ensure the key has access to the Generative Language API and is not IP/referrer-restricted for server use.
  3. Optionally set EMBEDDING_MODEL_PREF (defaults to gemini-embedding-001) and restart the process.
  4. Verify the var is loaded in the running process.
Defensive patterns

Strategy: validation

Validate before calling

function assertGeminiEmbedEnv() {
  if (!process.env.GEMINI_EMBEDDING_API_KEY) {
    throw new Error('Missing env GEMINI_EMBEDDING_API_KEY (note the _EMBEDDING_ segment)');
  }
}
assertGeminiEmbedEnv();

Try / catch

try {
  new GeminiEmbedder();
} catch (e) {
  if (/gemini api key/i.test(e.message)) { /* surface config error */ }
  throw e;
}

Prevention

When it happens

Trigger: Constructing GeminiEmbedder while GEMINI_EMBEDDING_API_KEY is unset; reusing GEMINI_API_KEY (LLM) name instead of GEMINI_EMBEDDING_API_KEY; API key restricted to an API that excludes the Generative Language API.

Common situations: Setting GEMINI_API_KEY for chat but forgetting the EMBEDDING-specific var; Google API key with HTTP referrer/IP restrictions that block the server; key disabled in Google Cloud Console; test env missing the secret.

Related errors


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