Mintplex-Labs/anything-llm · error

No Azure API key was set.

Error message

No Azure API key was set.

What it means

Thrown when AZURE_OPENAI_ENDPOINT is present but AZURE_OPENAI_KEY is not; the constructor checks endpoint first, so seeing this error specifically means the endpoint passed and only the credential is missing. The key authenticates every completions call against the Azure resource. Both variables must reach the process together.

Solutions

  1. Set AZURE_OPENAI_KEY (the 32-character Azure key) in provider settings or the environment
  2. Confirm the variable name is exactly AZURE_OPENAI_KEY
  3. Ensure both endpoint and key reach the same process (docker -e / env_file)
  4. Restart the server after fixing the environment

Example fix

# before
export AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com

# after
export AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com
export AZURE_OPENAI_KEY=32charazurekey...
Defensive patterns

Strategy: validation

Validate before calling

function canUseAzureOpenAI() {
  return Boolean(process.env.AZURE_OPENAI_ENDPOINT && process.env.AZURE_OPENAI_KEY);
}
if (!canUseAzureOpenAI()) {
  return res.status(503).json({ error: "Azure OpenAI provider is not configured" });
}

Try / catch

try {
  const llm = new AzureOpenAiLLM(embedder, modelPref);
} catch (e) {
  if (/No Azure API key/i.test(e.message)) {
    return res.status(503).json({ error: "Set AZURE_OPENAI_KEY for your resource" });
  }
  throw e;
}

Prevention

When it happens

Trigger: Endpoint saved but the key field left blank in provider settings; key passed under a wrong name (AZURE_OPENAI_API_KEY); key set in the dev shell but not in the service manager/container; per-instance env drift.

Common situations: Partial configuration through the UI; copy-paste of only one of the two values from the Azure portal; docker-compose env_file updated for one service but not another.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: 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 3aec848f28)