{"record":{"id":"9c7a192a4ce5988d","repo":"Mintplex-Labs/anything-llm","slug":"no-openrouter-api-key-was-set-9c7a19","errorCode":null,"errorMessage":"No OpenRouter API key was set.","messagePattern":"No OpenRouter API key was set\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/EmbeddingEngines/openRouter/index.js","lineNumber":6,"sourceCode":"const { toChunks, reportEmbeddingProgress } = require(\"../../helpers\");\n\nclass OpenRouterEmbedder {\n  constructor() {\n    if (!process.env.OPENROUTER_API_KEY)\n      throw new Error(\"No OpenRouter API key was set.\");\n    this.className = \"OpenRouterEmbedder\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.openai = new OpenAIApi({\n      baseURL: \"https://openrouter.ai/api/v1\",\n      apiKey: process.env.OPENROUTER_API_KEY,\n      defaultHeaders: {\n        \"HTTP-Referer\": \"https://anythingllm.com\",\n        \"X-Title\": \"AnythingLLM\",\n      },\n    });\n    this.model = process.env.EMBEDDING_MODEL_PREF || \"baai/bge-m3\";\n\n    // Limit of how many strings we can process in a single pass to stay with resource or network limits\n    this.maxConcurrentChunks = 500;\n\n    // https://openrouter.ai/docs/api/reference/embeddings\n    this.embeddingMaxChunkLength = 8_191;\n  }","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/openRouter/index.js#L1-L24","documentation":"Thrown by the OpenRouterEmbedder constructor when process.env.OPENROUTER_API_KEY is falsy. The openai SDK is pointed at openrouter.ai/api/v1 with the key and identifying headers (HTTP-Referer, X-Title); without a key every request would 401, so construction aborts immediately. The model defaults to baai/bge-m3.","triggerScenarios":"Selecting the OpenRouter embedding engine while OPENROUTER_API_KEY is unset/empty; constructing `new OpenRouterEmbedder()` before env load. The check on line 6 precedes client creation.","commonSituations":"Fresh OpenRouter setup; key revoked/rotated on openrouter.ai but not in .env; secret not injected into container/CI; env var typo; OpenRouter credits exhausted so the key was deactivated.","solutions":["Set OPENROUTER_API_KEY in .env to a valid key from openrouter.ai/keys","Confirm the key is active and the account has credits","Reload AnythingLLM env after the edit"],"exampleFix":"// before\n// OPENROUTER_API_KEY unset\n\n// after\nOPENROUTER_API_KEY=sk-or-...\nEMBEDDING_MODEL_PREF=baai/bge-m3","handlingStrategy":"validation","validationCode":"function hasOpenRouterKey(env = process.env) {\n  return typeof env.OPENROUTER_API_KEY === 'string' &&\n         env.OPENROUTER_API_KEY.trim().length > 0;\n}\nif (!hasOpenRouterKey()) {\n  throw new Error('Missing OPENROUTER_API_KEY.');\n}","typeGuard":"function isOpenRouterKey(v) {\n  return typeof v === 'string' && /^sk-or-[A-Za-z0-9_-]{20,}$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Get the key from openrouter.ai/keys and keep credits topped up.","Store it via system settings so it lands in env reliably.","Validate env at boot for the selected engine."],"tags":["openrouter","embedding","config","env","auth","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}