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 by the AzureOpenAIEmbedder constructor when either config.apiKey or config.modelProperties.endpoint is missing. Azure OpenAI is addressed per-resource via the endpoint URL and authenticated with the key — unlike openai.com, there is no default endpoint, so both are mandatory. Fails fast at Memory/embedder construction.

Source

Thrown at mem0-ts/src/oss/src/embeddings/azure.ts:12

import { AzureOpenAI } from "openai";
import { Embedder } from "./base";
import { EmbeddingConfig } from "../types";

export class AzureOpenAIEmbedder implements Embedder {
  private client: AzureOpenAI;
  private model: string;
  private embeddingDims: number | undefined;

  constructor(config: EmbeddingConfig) {
    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 || "text-embedding-3-small";
    this.embeddingDims = config.embeddingDims;
  }

  async embed(text: string): Promise<number[]> {
    const response = await this.client.embeddings.create({
      model: this.model,
      input: text,
      ...(this.embeddingDims !== undefined && {

View on GitHub (pinned to 001c235229)

Solutions

  1. Nest the endpoint correctly and supply the key: { apiKey, model: 'text-embedding-3-small', modelProperties: { endpoint: 'https://<resource>.openai.azure.com/' } }
  2. Verify both values are non-empty strings at startup if sourced from env (process.env.AZURE_API_KEY, AZURE_ENDPOINT)
  3. Use the Azure resource's full HTTPS endpoint from Azure Portal -> Resource -> Keys and Endpoint

Example fix

// before
embedder: { provider: 'azure_openai', config: { apiKey, model: 'text-embedding-3-small' } }

// after
embedder: {
  provider: 'azure_openai',
  config: {
    apiKey,
    model: 'text-embedding-3-small',
    modelProperties: { endpoint: 'https://my-resource.openai.azure.com/' },
  },
}
Defensive patterns

Strategy: validation

Validate before calling

const AZURE_API_KEY = process.env.AZURE_API_KEY;
const AZURE_ENDPOINT = process.env.AZURE_ENDPOINT;
if (!AZURE_API_KEY || !AZURE_ENDPOINT) {
  throw new Error('Azure embedder requires AZURE_API_KEY and AZURE_ENDPOINT');
}
// pass modelProperties: { endpoint: AZURE_ENDPOINT }

Type guard

const hasAzureEmbedConfig = (
  c: EmbeddingConfig,
): c is EmbeddingConfig & { apiKey: string; modelProperties: { endpoint: string } } =>
  typeof c.apiKey === 'string' && c.apiKey.length > 0 &&
  typeof c.modelProperties?.endpoint === 'string' &&
  (c.modelProperties.endpoint as string).startsWith('https://');

Prevention

When it happens

Trigger: EmbeddingConfig with apiKey set but modelProperties absent (or endpoint typo'd as 'baseUrl'/'url' instead of 'endpoint'); endpoint present but apiKey left to an env var that is unset; passing modelProperties: {} while assuming the SDK reads AZURE_OPENAI_ENDPOINT itself.

Common situations: Porting the OpenAI embedder config to Azure and keeping the flat shape; mixing up field names — the endpoint must live under modelProperties.endpoint, not the top level; env vars AZURE_API_KEY defined in dev but not in the deployed environment.

Related errors


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