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 GeminiLLM constructor when process.env.GEMINI_API_KEY is unset. Gemini is reached through Google's OpenAI-compatible endpoint (v1beta/openai/), which still requires the Gemini API key as the bearer token. Without it the OpenAI client cannot authenticate and the provider refuses to construct.
Source
Thrown at server/utils/AiProviders/gemini/index.js:30
const { defaultGeminiModels, v1BetaModels } = require("./defaultModels");
const { safeJsonParse } = require("../../http");
const cacheFolder = path.resolve(
process.env.STORAGE_DIR
? path.resolve(process.env.STORAGE_DIR, "models", "gemini")
: path.resolve(__dirname, `../../../storage/models/gemini`)
);
const NO_SYSTEM_PROMPT_MODELS = [
"gemma-3-1b-it",
"gemma-3-4b-it",
"gemma-3-12b-it",
"gemma-3-27b-it",
];
class GeminiLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.GEMINI_API_KEY)
throw new Error("No Gemini API key was set.");
this.className = "GeminiLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.model =
modelPreference ||
process.env.GEMINI_LLM_MODEL_PREF ||
"gemini-2.0-flash-lite";
const isExperimental = this.isExperimentalModel(this.model);
this.openai = new OpenAIApi({
apiKey: process.env.GEMINI_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.limits = {
history: this.promptWindowLimit() * 0.15,
system: this.promptWindowLimit() * 0.15,View on GitHub (pinned to 526360e320)
Solutions
- Create a key at Google AI Studio (aistudio.google.com) and put GEMINI_API_KEY=... in .env
- Restart AnythingLLM so process.env picks up the new key
- Confirm the key works with a direct curl to the Gemini OpenAI endpoint before configuring AnythingLLM
- If running in Docker, pass -e GEMINI_API_KEY or use an env file
Example fix
// before // .env: (no GEMINI vars beyond maybe a model pref) // after // .env: // GEMINI_API_KEY=AIzaSy... // GEMINI_LLM_MODEL_PREF=gemini-2.0-flash-lite
Defensive patterns
Strategy: validation
Validate before calling
function hasGeminiKey() {
return Boolean(process.env.GEMINI_API_KEY);
}
if (!hasGeminiKey()) {
throw new ConfigError('Create a key in Google AI Studio and set GEMINI_API_KEY.');
} Prevention
- Validate the key with a cheap /models call at startup
- Store secrets via a secrets manager rather than raw .env in production
- Surface missing-key as a UI banner, not a runtime crash
When it happens
Trigger: Constructing `new GeminiLLM(embedder, modelPreference)` while GEMINI_API_KEY is absent from process.env — fires at provider selection when the user chose Gemini but supplied no key.
Common situations: .env missing the GEMINI_API_KEY line; key revoked or never created in Google AI Studio; key stored in a different env source not loaded by AnythingLLM; Docker deployment without the env passthrough.
Related errors
- No Gitee AI API key was set.
- No Groq API key was set.
- No Foundry Base Path was set.
- GenericOpenAI must have a valid base path to use for the api
- KoboldCPP must have a valid base path to use for the api.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/01cacab46a8b5d79.
Report an issue: GitHub.