Mintplex-Labs/anything-llm · error
No AZURE_OPENAI_MODEL_PREF ENV defined. This must the name…
Error message
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.
What it means
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.
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
Example fix
# before export AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com export AZURE_OPENAI_KEY=32charkey... # after - add the deployment name export AZURE_OPENAI_MODEL_PREF=gpt-4o-deployment
Defensive patterns
Strategy: validation
Validate before calling
function azureModelConfigured(modelPreference) {
return Boolean(modelPreference || process.env.AZURE_OPENAI_MODEL_PREF || process.env.OPEN_MODEL_PREF);
}
if (!azureModelConfigured(modelPreference)) {
return res.status(503).json({ error: "No Azure model/deployment selected" });
}
await llm.getChatCompletion(messages); Try / catch
try {
await llm.getChatCompletion(messages);
} catch (e) {
if (/AZURE_OPENAI_MODEL_PREF/i.test(e.message)) {
return res.status(503).json({ error: "Select an Azure deployment name in provider settings" });
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ApiPie chat: is not valid for chat completion!
- No Azure API endpoint was set.
- No Azure API key was set.
- AnthropicLLM::getChatCompletion failed to communicate with…
- " " is not a valid URL. Check your settings for the Azure…
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/b1c5fbeec8ec8422.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/azureOpenAi/index.js:155
attachments = [], // This is the specific attachment for only this prompt
}) {
const prompt = {
role: this.isOTypeModel ? "user" : "system",
content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
};
return [
prompt,
...formatChatHistory(chatHistory, this.#generateContent),
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
}
async getChatCompletion(messages = [], { temperature = 0.7 }) {
if (!this.model)
throw new Error(
"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."
);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions.create({
messages,
model: this.model,
...(this.isOTypeModel ? {} : { temperature }),
})
);
if (
!result.output.hasOwnProperty("choices") ||
result.output.choices.length === 0
)
return null;
return {View on GitHub (pinned to 3aec848f28)