Mintplex-Labs/anything-llm · critical · Error

No Azure API key was set.

Error message

No Azure API key was set.

What it means

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.

Source

Thrown at server/utils/AiProviders/azureOpenAi/index.js:16

const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const {
  formatChatHistory,
  handleDefaultStreamResponseV2,
} = require("../../helpers/chat/responses");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");

class AzureOpenAiLLM {
  constructor(embedder = null, modelPreference = null) {
    const { OpenAI } = require("openai");
    if (!process.env.AZURE_OPENAI_ENDPOINT)
      throw new Error("No Azure API endpoint was set.");
    if (!process.env.AZURE_OPENAI_KEY)
      throw new Error("No Azure API key was set.");

    this.className = "AzureOpenAiLLM";
    this.openai = new OpenAI({
      apiKey: process.env.AZURE_OPENAI_KEY,
      baseURL: AzureOpenAiLLM.formatBaseUrl(process.env.AZURE_OPENAI_ENDPOINT),
    });
    this.model =
      modelPreference ||
      process.env.AZURE_OPENAI_MODEL_PREF ||
      process.env.OPEN_MODEL_PREF;
    /* 
      Note: Azure OpenAI deployments do not expose model metadata that would allow us to
      programmatically detect whether the deployment uses a reasoning model (o1, o1-mini, o3-mini, etc.).
      As a result, we rely on the user to explicitly set AZURE_OPENAI_MODEL_TYPE="reasoning"
      when using reasoning models, as incorrect configuration might result in chat errors.
    */
    this.isOTypeModel =
      process.env.AZURE_OPENAI_MODEL_TYPE === "reasoning" || false;

View on GitHub (pinned to 526360e320)

Solutions

  1. Set `AZURE_OPENAI_KEY=<your azure key>` in .env and restart.
  2. 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.
  3. Re-save credentials through the UI to persist both fields.
  4. Verify with `printenv AZURE_OPENAI_KEY` in the server's environment.

Example fix

// before
// .env
AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com
AZURE_OPENAI_KEY=

// after
// .env
AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com
AZURE_OPENAI_KEY=<azure-key>
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.AZURE_OPENAI_KEY) {
  throw new Error(
    "AZURE_OPENAI_KEY is missing. Generate one in the Azure portal (Keys and Endpoint)."
  );
}
const llm = new AzureOpenAiLLM(embedder, modelPref);

Type guard

/** @param {unknown} v @returns {boolean} */
function isNonEmptyKey(v) {
  return typeof v === "string" && v.trim().length > 0;
}

Try / catch

try {
  const llm = new AzureOpenAiLLM(embedder, modelPref);
} catch (e) {
  if (/No Azure API key/.test(e.message)) {
    return { ok: false, reason: "missing-key" };
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Endpoint copied but key forgotten; key rotated in Azure portal and not updated here; key env var misnamed; key value contains only whitespace.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/9bc2eac71bb16582. Report an issue: GitHub.