{"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":"Error","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/azureOpenAi/index.js#L137-L173","documentation":"Thrown by AzureOpenAiLLM.getChatCompletion when `this.model` is falsy at call time. this.model is resolved in the constructor from modelPreference arg, else AZURE_OPENAI_MODEL_PREF, else OPEN_MODEL_PREF — if all are empty, this.model is undefined and the chat call is blocked because Azure needs an explicit deployment name (it cannot infer one).","triggerScenarios":"Calling getChatCompletion after constructing the provider with no model preference and neither AZURE_OPENAI_MODEL_PREF nor OPEN_MODEL_PREF set in env. The constructor does not throw on missing model (only endpoint/key), so this surfaces lazily on first chat.","commonSituations":"Azure provider configured with endpoint+key but model/deployment field left blank; deployment created in Azure but its name not entered; env var typo (e.g. AZURE_OPENAI_MODEL instead of AZURE_OPENAI_MODEL_PREF); relying on OPEN_MODEL_PREF but that is also unset.","solutions":["Set `AZURE_OPENAI_MODEL_PREF=<deployment-name>` in .env to the name of a chat deployment in your Azure resource (not the base model name).","Pass modelPreference explicitly when constructing the provider for a per-workspace model.","If relying on the OPEN_MODEL_PREF fallback, ensure it is set to a valid Azure deployment name.","Restart the server so the constructor re-reads the env."],"exampleFix":"// before\n// .env\nAZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com\nAZURE_OPENAI_KEY=...\n// no model pref\n\n// after\nAZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com\nAZURE_OPENAI_KEY=...\nAZURE_OPENAI_MODEL_PREF=gpt-35-turbo-deploy","handlingStrategy":"validation","validationCode":"// Resolve the effective model the same way the constructor does\nconst model =\n  modelPref ||\n  process.env.AZURE_OPENAI_MODEL_PREF ||\n  process.env.OPEN_MODEL_PREF;\nif (!model) {\n  throw new Error(\n    \"No Azure deployment name configured. Set AZURE_OPENAI_MODEL_PREF to a chat deployment name.\"\n  );\n}\nconst llm = new AzureOpenAiLLM(embedder, model);","typeGuard":"/** @param {unknown} m @returns {boolean} */\nfunction hasChatModel(m) {\n  return typeof m === \"string\" && m.trim().length > 0;\n}","tryCatchPattern":"try {\n  const res = await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/No AZURE_OPENAI_MODEL_PREF/.test(e.message)) {\n    return { ok: false, reason: \"missing-model\", hint: \"Create a deployment and set AZURE_OPENAI_MODEL_PREF.\" };\n  }\n  throw e;\n}","preventionTips":["Treat model selection as mandatory for Azure (unlike providers with a safe default).","Surface the deployment name in the workspace model picker so it's visible.","Validate that the deployment exists in Azure at provider-save time via a minimal API call.","Remember the value is the deployment name, not the base model name."],"tags":["config","model","azure","runtime","precondition"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}