mem0ai/mem0 · error · Error

Azure OpenAI requires both API key and endpoint

Error message

Azure OpenAI requires both API key and endpoint

What it means

Thrown synchronously by the AzureOpenAILLM constructor when the LLM config lacks either an apiKey or modelProperties.endpoint. The Azure OpenAI client in the openai SDK requires both an endpoint (your resource URL, e.g. https://<resource>.openai.azure.com) and a credential, so the provider validates them up front rather than failing later inside a request.

Source

Thrown at mem0-ts/src/oss/src/llms/azure.ts:11

import { AzureOpenAI } from "openai";
import { LLM, LLMResponse } from "./base";
import { LLMConfig, Message } from "../types";

export class AzureOpenAILLM implements LLM {
  private client: AzureOpenAI;
  private model: string;

  constructor(config: LLMConfig) {
    if (!config.apiKey || !config.modelProperties?.endpoint) {
      throw new Error("Azure OpenAI requires both API key and endpoint");
    }

    const { endpoint, ...rest } = config.modelProperties;

    this.client = new AzureOpenAI({
      apiKey: config.apiKey,
      endpoint: endpoint as string,
      ...rest,
    });
    this.model = config.model || "gpt-5-mini";
  }

  async generateResponse(
    messages: Message[],
    responseFormat?: { type: string },
    tools?: any[],
  ): Promise<string | LLMResponse> {
    const completion = await this.client.chat.completions.create({

View on GitHub (pinned to 001c235229)

Solutions

  1. Set both required fields: config.apiKey and config.modelProperties.endpoint.
  2. Confirm the endpoint is the full Azure resource URL (https://<your-resource>.openai.azure.com) placed inside modelProperties, not at the top level.
  3. If you keep the key in an env var, pass it explicitly: apiKey: process.env.AZURE_OPENAI_API_KEY, endpoint: process.env.AZURE_OPENAI_ENDPOINT — the constructor reads no env fallbacks.
  4. Verify deployment name vs model: this check is about endpoint/key only; the model/deployment is validated later by Azure itself.

Example fix

// before
const mem = new Memory({
  llm: { provider: 'azure_openai', config: { model: 'gpt-4o', apiKey: process.env.AZURE_API_KEY } },
}); // throws: Azure OpenAI requires both API key and endpoint

// after
const mem = new Memory({
  llm: {
    provider: 'azure_openai',
    config: {
      model: 'gpt-4o',
      apiKey: process.env.AZURE_OPENAI_API_KEY,
      modelProperties: {
        endpoint: 'https://my-resource.openai.azure.com',
      },
    },
  },
});
Defensive patterns

Strategy: validation

Validate before calling

function assertAzureConfig(cfg: LLMConfig) {
  const endpoint = cfg.modelProperties?.endpoint;
  if (!cfg.apiKey || !endpoint) {
    throw new Error(`Missing ${!cfg.apiKey ? 'apiKey' : 'modelProperties.endpoint'} for Azure OpenAI`);
  }
  if (!/^https:\/\/.+\.openai\.azure\.com\/?$/.test(String(endpoint))) {
    console.warn('Azure endpoint looks unusual:', endpoint);
  }
}

Type guard

function hasAzureRequirements(cfg: LLMConfig): cfg is LLMConfig & { apiKey: string; modelProperties: { endpoint: string } } {
  return Boolean(cfg.apiKey && cfg.modelProperties?.endpoint);
}

Try / catch

try {
  const llm = new AzureOpenAILLM(config);
} catch (err) {
  if ((err as Error).message.includes('requires both API key and endpoint')) {
    throw new ConfigError('Azure OpenAI: set config.apiKey and config.modelProperties.endpoint');
  }
  throw err;
}

Prevention

When it happens

Trigger: Instantiating AzureOpenAILLM (provider 'azure_openai') with config.apiKey unset/empty, or with modelProperties.endpoint missing/undefined. Note the check is on config.modelProperties?.endpoint — passing endpoint anywhere else (for example as a top-level config field or inside a different nested object) still triggers it.

Common situations: Migrating a config from the OpenAI provider where no endpoint exists; forgetting that Azure needs the resource-specific endpoint rather than a baseURL; setting AZURE_OPENAI_ENDPOINT as an env var only (the constructor does not read env vars — it requires the explicit config field); typoing modelProperties or nesting endpoint under config.modelProperties.endpoint with a falsy value.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/b66487f64aeb0a08. Report an issue: GitHub.