{"record":{"id":"9bc2eac71bb16582","repo":"Mintplex-Labs/anything-llm","slug":"no-azure-api-key-was-set","errorCode":null,"errorMessage":"No Azure API key was set.","messagePattern":"No Azure API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/azureOpenAi/index.js","lineNumber":16,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  formatChatHistory,\n  handleDefaultStreamResponseV2,\n} = require(\"../../helpers/chat/responses\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\n\nclass AzureOpenAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI } = require(\"openai\");\n    if (!process.env.AZURE_OPENAI_ENDPOINT)\n      throw new Error(\"No Azure API endpoint was set.\");\n    if (!process.env.AZURE_OPENAI_KEY)\n      throw new Error(\"No Azure API key was set.\");\n\n    this.className = \"AzureOpenAiLLM\";\n    this.openai = new OpenAI({\n      apiKey: process.env.AZURE_OPENAI_KEY,\n      baseURL: AzureOpenAiLLM.formatBaseUrl(process.env.AZURE_OPENAI_ENDPOINT),\n    });\n    this.model =\n      modelPreference ||\n      process.env.AZURE_OPENAI_MODEL_PREF ||\n      process.env.OPEN_MODEL_PREF;\n    /* \n      Note: Azure OpenAI deployments do not expose model metadata that would allow us to\n      programmatically detect whether the deployment uses a reasoning model (o1, o1-mini, o3-mini, etc.).\n      As a result, we rely on the user to explicitly set AZURE_OPENAI_MODEL_TYPE=\"reasoning\"\n      when using reasoning models, as incorrect configuration might result in chat errors.\n    */\n    this.isOTypeModel =\n      process.env.AZURE_OPENAI_MODEL_TYPE === \"reasoning\" || false;","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/azureOpenAi/index.js#L1-L34","documentation":"Thrown by the AzureOpenAiLLM constructor when process.env.AZURE_OPENAI_KEY is falsy, immediately after the endpoint check. The OpenAI client is constructed with this key as apiKey, so without it every chat/stream call would 401. Failing in the constructor prevents deferred, harder-to-diagnose auth errors.","triggerScenarios":"Constructing AzureOpenAiLLM with AZURE_OPENAI_ENDPOINT present but AZURE_OPENAI_KEY missing/empty. Order matters: if the endpoint guard (166) passes, this one is next.","commonSituations":"Endpoint copied but key forgotten; key rotated in Azure portal and not updated here; key env var misnamed; key value contains only whitespace.","solutions":["Set `AZURE_OPENAI_KEY=<your azure key>` in .env and restart.","If using Azure Active Directory / Managed Identity instead of a key, note this provider path requires a key — switch to a key-based deployment or adapt the provider.","Re-save credentials through the UI to persist both fields.","Verify with `printenv AZURE_OPENAI_KEY` in the server's environment."],"exampleFix":"// before\n// .env\nAZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com\nAZURE_OPENAI_KEY=\n\n// after\n// .env\nAZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com\nAZURE_OPENAI_KEY=<azure-key>","handlingStrategy":"validation","validationCode":"if (!process.env.AZURE_OPENAI_KEY) {\n  throw new Error(\n    \"AZURE_OPENAI_KEY is missing. Generate one in the Azure portal (Keys and Endpoint).\"\n  );\n}\nconst llm = new AzureOpenAiLLM(embedder, modelPref);","typeGuard":"/** @param {unknown} v @returns {boolean} */\nfunction isNonEmptyKey(v) {\n  return typeof v === \"string\" && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const llm = new AzureOpenAiLLM(embedder, modelPref);\n} catch (e) {\n  if (/No Azure API key/.test(e.message)) {\n    return { ok: false, reason: \"missing-key\" };\n  }\n  throw e;\n}","preventionTips":["Validate endpoint and key together at provider-save time; don't allow partial saves.","If you intend to use Azure AD/Managed Identity, switch providers or extend this one — it requires a key.","Rotate keys in Azure and update .env promptly; stale keys surface as runtime 401s.","Restart the server after key rotation."],"tags":["config","env","authentication","azure","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}