{"record":{"id":"b1c5fbeec8ec8422","repo":"Mintplex-Labs/anything-llm","slug":"no-azure-openai-model-pref-env-defined-this-must","errorCode":null,"errorMessage":"No AZURE_OPENAI_MODEL_PREF ENV defined. This must the name of a deployment on your Azure account for an LLM chat model like GPT-3.5.","messagePattern":"No AZURE_OPENAI_MODEL_PREF ENV defined\\. This must the name of a deployment on your Azure account for an LLM chat model like GPT-3\\.5\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/azureOpenAi/index.js","lineNumber":155,"sourceCode":"    attachments = [], // This is the specific attachment for only this prompt\n  }) {\n    const prompt = {\n      role: this.isOTypeModel ? \"user\" : \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [\n      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = [], { temperature = 0.7 }) {\n    if (!this.model)\n      throw new Error(\n        \"No AZURE_OPENAI_MODEL_PREF ENV defined. This must the name of a deployment on your Azure account for an LLM chat model like GPT-3.5.\"\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions.create({\n        messages,\n        model: this.model,\n        ...(this.isOTypeModel ? {} : { temperature }),\n      })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    return {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/azureOpenAi/index.js#L137-L173","documentation":"getChatCompletion refuses to run when this.model is falsy. The constructor builds the model from modelPreference || AZURE_OPENAI_MODEL_PREF || OPEN_MODEL_PREF; if every source is empty the field stays undefined and this guard fires on the first completion. For Azure the value must be the deployment name created on the resource (Azure AI Foundry/portal), which may differ from the public model id.","triggerScenarios":"Azure provider credentials saved but the model preference never selected; AZURE_OPENAI_MODEL_PREF unset and OPEN_MODEL_PREF cleared after a migration; container redeploy without the env; deployment named differently from the model id it serves.","commonSituations":"Assuming the model id (\"gpt-4o\") works when the deployment was named \"gpt-4o-deployment\"; env loss on container recreation; completing provider setup but skipping the model dropdown; region mismatches between endpoint and deployment.","solutions":["Set the model preference in the Azure provider settings to your exact Azure deployment name","Or export AZURE_OPENAI_MODEL_PREF=<deployment-name>","Confirm the deployment exists on the resource backing the endpoint","Restart the server after env changes"],"exampleFix":"# before\nexport AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com\nexport AZURE_OPENAI_KEY=32charkey...\n\n# after - add the deployment name\nexport AZURE_OPENAI_MODEL_PREF=gpt-4o-deployment","handlingStrategy":"validation","validationCode":"function azureModelConfigured(modelPreference) {\n  return Boolean(modelPreference || process.env.AZURE_OPENAI_MODEL_PREF || process.env.OPEN_MODEL_PREF);\n}\nif (!azureModelConfigured(modelPreference)) {\n  return res.status(503).json({ error: \"No Azure model/deployment selected\" });\n}\nawait llm.getChatCompletion(messages);","typeGuard":null,"tryCatchPattern":"try {\n  await llm.getChatCompletion(messages);\n} catch (e) {\n  if (/AZURE_OPENAI_MODEL_PREF/i.test(e.message)) {\n    return res.status(503).json({ error: \"Select an Azure deployment name in provider settings\" });\n  }\n  throw e;\n}","preventionTips":["Remember Azure wants the deployment name, not the model id","Complete provider setup end-to-end: endpoint, key, and model preference","After container redeploys, verify AZURE_OPENAI_MODEL_PREF survived"],"tags":["azure-openai","model","environment","chat-completion"],"backgroundTag":"missing-model-configuration","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}