Mintplex-Labs/anything-llm · error · Error
No AZURE_OPENAI_MODEL_PREF ENV defined. This must the name o
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
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).
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 526360e320)
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.
Example fix
// before // .env AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com AZURE_OPENAI_KEY=... // no model pref // after AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com AZURE_OPENAI_KEY=... AZURE_OPENAI_MODEL_PREF=gpt-35-turbo-deploy
Defensive patterns
Strategy: validation
Validate before calling
// Resolve the effective model the same way the constructor does
const model =
modelPref ||
process.env.AZURE_OPENAI_MODEL_PREF ||
process.env.OPEN_MODEL_PREF;
if (!model) {
throw new Error(
"No Azure deployment name configured. Set AZURE_OPENAI_MODEL_PREF to a chat deployment name."
);
}
const llm = new AzureOpenAiLLM(embedder, model); Type guard
/** @param {unknown} m @returns {boolean} */
function hasChatModel(m) {
return typeof m === "string" && m.trim().length > 0;
} Try / catch
try {
const res = await llm.getChatCompletion(messages, { temperature });
} catch (e) {
if (/No AZURE_OPENAI_MODEL_PREF/.test(e.message)) {
return { ok: false, reason: "missing-model", hint: "Create a deployment and set AZURE_OPENAI_MODEL_PREF." };
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No Azure API endpoint was set.
- ApiPie chat: ${this.model} is not valid for chat completion!
- No Azure API key was set.
- "${azureOpenAiEndpoint}" is not a valid URL. Check your sett
- No Azure API endpoint was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/b1c5fbeec8ec8422.
Report an issue: GitHub.