Mintplex-Labs/anything-llm · critical · Error

No Gemini API key was set.

Error message

No Gemini API key was set.

What it means

Thrown by the GeminiEmbedder constructor when the GEMINI_EMBEDDING_API_KEY environment variable is empty or unset. AnythingLLM builds this class the moment the Gemini embedding engine is selected, so instantiation fails before any embedding request is made. The key is used against Google's OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai/), so it must be a Google AI Studio API key.

Solutions

  1. Set GEMINI_EMBEDDING_API_KEY to a key created in Google AI Studio (https://aistudio.google.com/apikey)
  2. If using Docker, add it to the environment block of docker-compose.yml (or pass -e) and recreate the container
  3. Fully restart the server after editing .env so the new value is loaded
  4. Confirm the exact spelling GEMINI_EMBEDDING_API_KEY (GEMINI_API_KEY is a different variable this class does not read)

Example fix

# before (env)
# no embedding key set, EMBEDDING_ENGINE=gemini

# after
GEMINI_EMBEDDING_API_KEY=AIza...
EMBEDDING_MODEL_PREF=gemini-embedding-001
Defensive patterns

Strategy: validation

Validate before calling

function assertGeminiEmbedderConfigured() {
  if (!process.env.GEMINI_EMBEDDING_API_KEY) {
    throw new Error("Missing GEMINI_EMBEDDING_API_KEY — create one at https://aistudio.google.com/apikey");
  }
}
assertGeminiEmbedderConfigured();
const { GeminiEmbedder } = require("./server/utils/EmbeddingEngines/gemini");
const embedder = new GeminiEmbedder();

Try / catch

try {
  const embedder = new GeminiEmbedder();
} catch (e) {
  if (e.message === "No Gemini API key was set.") {
    // fail fast with an actionable config message; do not retry — construction is deterministic
  }
  throw e;
}

Prevention

When it happens

Trigger: Selecting Gemini as the embedding engine in system settings or setting EMBEDDING_ENGINE=gemini without defining GEMINI_EMBEDDING_API_KEY; starting the container without the variable in docker-compose/.env; a typo in the variable name (e.g. GEMINI_API_KEY) so the check sees nothing; .env edited after the process already started so the value was never loaded.

Common situations: Fresh installs where the admin configured the LLM provider but forgot the embedding provider key; Docker deployments missing the -e GEMINI_EMBEDDING_API_KEY flag; teams that copy .env.example and leave the embedding section commented out.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: source

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

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

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

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 20f6d3546c)