{"record":{"id":"2d9c6e584fc6c182","repo":"mastra-ai/mastra","slug":"azure-gateway-invalid-config","errorCode":"AZURE_GATEWAY_INVALID_CONFIG","errorMessage":"resourceName is required for Azure OpenAI gateway","messagePattern":"resourceName is required for Azure OpenAI gateway","errorType":"validation","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/llm/model/gateways/azure.ts","lineNumber":181,"sourceCode":"      return Reflect.get(target, property, receiver);\n    },\n  });\n}\n\nexport class AzureOpenAIGateway extends MastraModelGateway {\n  readonly id = 'azure-openai';\n  readonly name = 'azure-openai';\n  private tokenCache = new InMemoryServerCache();\n  private entraIdTokenRequests = new Map<string, Promise<CachedToken>>();\n\n  constructor(private config: AzureOpenAIGatewayConfig) {\n    super();\n    this.validateConfig();\n  }\n\n  private validateConfig(): void {\n    if (!this.config.resourceName) {\n      throw new MastraError({\n        id: 'AZURE_GATEWAY_INVALID_CONFIG',\n        domain: 'LLM',\n        category: 'UNKNOWN',\n        text: 'resourceName is required for Azure OpenAI gateway',\n      });\n    }\n\n    if (!this.config.apiKey && this.config.authentication?.type !== 'entraId') {\n      throw new MastraError({\n        id: 'AZURE_GATEWAY_INVALID_CONFIG',\n        domain: 'LLM',\n        category: 'UNKNOWN',\n        text: 'apiKey or Entra ID authentication is required for Azure OpenAI gateway',\n      });\n    }\n\n    if (this.config.authentication?.type === 'entraId' && !this.config.authentication.credential) {\n      throw new MastraError({","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/llm/model/gateways/azure.ts#L163-L199","documentation":"The Azure OpenAI gateway's validateConfig, run from the constructor, requires config.resourceName to construct endpoint URLs. If resourceName is missing, a MastraError with id AZURE_GATEWAY_INVALID_CONFIG is thrown immediately when the gateway object is instantiated.","triggerScenarios":"Constructing the Azure OpenAI gateway class (constructor calls validateConfig) with a config object that omits the resourceName property.","commonSituations":"Setting only apiKey or deployment info but forgetting resourceName; loading config from env where the Azure resource name variable is unset; renaming config fields after a version change.","solutions":["Add resourceName to the gateway config, e.g. new AzureOpenAIGateway({ resourceName: 'my-azure-resource', apiKey: ... }).","Set the corresponding env variable and read it into the config (e.g. process.env.AZURE_RESOURCE_NAME), verifying it is non-empty before construction.","If using a full endpoint URL elsewhere, extract the hostname as resourceName or check the current gateway config schema for the accepted field names."],"exampleFix":"// before\nconst gateway = new AzureOpenAIGateway({ apiKey: process.env.AZURE_API_KEY });\n// after\nconst gateway = new AzureOpenAIGateway({\n  resourceName: process.env.AZURE_RESOURCE_NAME,\n  apiKey: process.env.AZURE_API_KEY,\n});","handlingStrategy":"validation","validationCode":"function assertAzureGatewayConfig(config: { resourceName?: string }): void {\n  if (!config.resourceName) {\n    throw new Error('Azure OpenAI gateway requires a non-empty resourceName');\n  }\n}","typeGuard":"function hasAzureResourceName(\n  config: unknown,\n): config is { resourceName: string } {\n  return typeof config === 'object' && config !== null &&\n    typeof (config as any).resourceName === 'string' && (config as any).resourceName.length > 0;\n}","tryCatchPattern":"try {\n  const gateway = new AzureOpenAIGateway(config);\n} catch (e) {\n  if ((e as any).id === 'AZURE_GATEWAY_INVALID_CONFIG') {\n    throw new Error('Azure gateway misconfigured: set AZURE_RESOURCE_NAME and pass it as resourceName', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Load and assert AZURE_RESOURCE_NAME env at startup before constructing gateways.","Validate the whole gateway config object with a schema (e.g. Zod) before construction.","Keep resourceName and endpoint config in one shared config module so it cannot be omitted."],"tags":["azure","configuration","gateway","missing-config"],"backgroundTag":"missing-required-config","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}