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
- Set GEMINI_EMBEDDING_API_KEY to a key created in Google AI Studio (https://aistudio.google.com/apikey)
- If using Docker, add it to the environment block of docker-compose.yml (or pass -e) and recreate the container
- Fully restart the server after editing .env so the new value is loaded
- 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
- Add a startup config check that fails the process with a list of all missing embedding env vars instead of crashing on first use
- Keep embedding credentials next to LLM credentials in the same .env so one review covers both
- Run docker-compose config (or a printenv step in CI) to assert required variables exist before deploy
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
- No Groq API key was set.
- No Mistral API key was set.
- GenericOpenAI must have a valid base path to use for the…
- LiteLLM must have a valid base path to use for the api.
- LMStudio must have a valid model set.
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)