{"record":{"id":"c0d53c0ab0fa4471","repo":"mem0ai/mem0","slug":"azure-openai-requires-both-api-key-and-endpoint","errorCode":null,"errorMessage":"Azure OpenAI requires both API key and endpoint","messagePattern":"Azure OpenAI requires both API key and endpoint","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/azure.ts","lineNumber":12,"sourceCode":"import { AzureOpenAI } from \"openai\";\nimport { Embedder } from \"./base\";\nimport { EmbeddingConfig } from \"../types\";\n\nexport class AzureOpenAIEmbedder implements Embedder {\n  private client: AzureOpenAI;\n  private model: string;\n  private embeddingDims: number | undefined;\n\n  constructor(config: EmbeddingConfig) {\n    if (!config.apiKey || !config.modelProperties?.endpoint) {\n      throw new Error(\"Azure OpenAI requires both API key and endpoint\");\n    }\n\n    const { endpoint, ...rest } = config.modelProperties;\n\n    this.client = new AzureOpenAI({\n      apiKey: config.apiKey,\n      endpoint: endpoint as string,\n      ...rest,\n    });\n    this.model = config.model || \"text-embedding-3-small\";\n    this.embeddingDims = config.embeddingDims;\n  }\n\n  async embed(text: string): Promise<number[]> {\n    const response = await this.client.embeddings.create({\n      model: this.model,\n      input: text,\n      ...(this.embeddingDims !== undefined && {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/azure.ts#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Nest the endpoint correctly and supply the key: { apiKey, model: 'text-embedding-3-small', modelProperties: { endpoint: 'https://<resource>.openai.azure.com/' } }","Verify both values are non-empty strings at startup if sourced from env (process.env.AZURE_API_KEY, AZURE_ENDPOINT)","Use the Azure resource's full HTTPS endpoint from Azure Portal -> Resource -> Keys and Endpoint"],"exampleFix":"// before\nembedder: { provider: 'azure_openai', config: { apiKey, model: 'text-embedding-3-small' } }\n\n// after\nembedder: {\n  provider: 'azure_openai',\n  config: {\n    apiKey,\n    model: 'text-embedding-3-small',\n    modelProperties: { endpoint: 'https://my-resource.openai.azure.com/' },\n  },\n}","handlingStrategy":"validation","validationCode":"const AZURE_API_KEY = process.env.AZURE_API_KEY;\nconst AZURE_ENDPOINT = process.env.AZURE_ENDPOINT;\nif (!AZURE_API_KEY || !AZURE_ENDPOINT) {\n  throw new Error('Azure embedder requires AZURE_API_KEY and AZURE_ENDPOINT');\n}\n// pass modelProperties: { endpoint: AZURE_ENDPOINT }","typeGuard":"const hasAzureEmbedConfig = (\n  c: EmbeddingConfig,\n): c is EmbeddingConfig & { apiKey: string; modelProperties: { endpoint: string } } =>\n  typeof c.apiKey === 'string' && c.apiKey.length > 0 &&\n  typeof c.modelProperties?.endpoint === 'string' &&\n  (c.modelProperties.endpoint as string).startsWith('https://');","tryCatchPattern":null,"preventionTips":["Copy the endpoint verbatim from Azure Portal -> Keys and Endpoint; it must sit under modelProperties.endpoint","Add startup env assertions for AZURE_API_KEY and AZURE_ENDPOINT in every environment","A unit test constructing AzureOpenAIEmbedder from your production env vars catches config drift in CI"],"tags":["azure","openai","embeddings","validation","config"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}