{"record":{"id":"b66487f64aeb0a08","repo":"mem0ai/mem0","slug":"azure-openai-requires-both-api-key-and-endpoint-b66487","errorCode":null,"errorMessage":"Azure OpenAI requires both API key and endpoint","messagePattern":"Azure OpenAI requires both API key and endpoint","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/azure.ts","lineNumber":11,"sourceCode":"import { AzureOpenAI } from \"openai\";\nimport { LLM, LLMResponse } from \"./base\";\nimport { LLMConfig, Message } from \"../types\";\n\nexport class AzureOpenAILLM implements LLM {\n  private client: AzureOpenAI;\n  private model: string;\n\n  constructor(config: LLMConfig) {\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 || \"gpt-5-mini\";\n  }\n\n  async generateResponse(\n    messages: Message[],\n    responseFormat?: { type: string },\n    tools?: any[],\n  ): Promise<string | LLMResponse> {\n    const completion = await this.client.chat.completions.create({","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/azure.ts#L1-L29","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set both required fields: config.apiKey and config.modelProperties.endpoint.","Confirm the endpoint is the full Azure resource URL (https://<your-resource>.openai.azure.com) placed inside modelProperties, not at the top level.","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.","Verify deployment name vs model: this check is about endpoint/key only; the model/deployment is validated later by Azure itself."],"exampleFix":"// before\nconst mem = new Memory({\n  llm: { provider: 'azure_openai', config: { model: 'gpt-4o', apiKey: process.env.AZURE_API_KEY } },\n}); // throws: Azure OpenAI requires both API key and endpoint\n\n// after\nconst mem = new Memory({\n  llm: {\n    provider: 'azure_openai',\n    config: {\n      model: 'gpt-4o',\n      apiKey: process.env.AZURE_OPENAI_API_KEY,\n      modelProperties: {\n        endpoint: 'https://my-resource.openai.azure.com',\n      },\n    },\n  },\n});","handlingStrategy":"validation","validationCode":"function assertAzureConfig(cfg: LLMConfig) {\n  const endpoint = cfg.modelProperties?.endpoint;\n  if (!cfg.apiKey || !endpoint) {\n    throw new Error(`Missing ${!cfg.apiKey ? 'apiKey' : 'modelProperties.endpoint'} for Azure OpenAI`);\n  }\n  if (!/^https:\\/\\/.+\\.openai\\.azure\\.com\\/?$/.test(String(endpoint))) {\n    console.warn('Azure endpoint looks unusual:', endpoint);\n  }\n}","typeGuard":"function hasAzureRequirements(cfg: LLMConfig): cfg is LLMConfig & { apiKey: string; modelProperties: { endpoint: string } } {\n  return Boolean(cfg.apiKey && cfg.modelProperties?.endpoint);\n}","tryCatchPattern":"try {\n  const llm = new AzureOpenAILLM(config);\n} catch (err) {\n  if ((err as Error).message.includes('requires both API key and endpoint')) {\n    throw new ConfigError('Azure OpenAI: set config.apiKey and config.modelProperties.endpoint');\n  }\n  throw err;\n}","preventionTips":["Keep Azure config in one typed object with endpoint nested under modelProperties.","Read env vars explicitly — this constructor has no env fallback.","Add a startup config lint that validates every provider config before the server accepts traffic."],"tags":["azure","openai","llm","config","typescript","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}