{"record":{"id":"ac14960f91d2d69b","repo":"DayuanJiang/next-ai-draw-io","slug":"azure-requires-either-azure-base-url-or-azure-reso","errorCode":null,"errorMessage":"Azure requires either AZURE_BASE_URL or AZURE_RESOURCE_NAME to be set. Please set one in your .env.local file.","messagePattern":"Azure requires either AZURE_BASE_URL or AZURE_RESOURCE_NAME to be set\\. Please set one in your \\.env\\.local file\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/ai-providers.ts","lineNumber":678,"sourceCode":"            )\n        }\n    } else {\n        // Use custom env var name if provided, otherwise use default\n        const requiredVar = customApiKeyEnv || PROVIDER_ENV_VARS[provider]\n        if (requiredVar && !process.env[requiredVar]) {\n            throw new Error(\n                `${requiredVar} environment variable is required for ${provider} provider. ` +\n                    `Please set it in your .env.local file.`,\n            )\n        }\n    }\n\n    // Azure requires either AZURE_BASE_URL or AZURE_RESOURCE_NAME in addition to API key\n    if (provider === \"azure\") {\n        const hasBaseUrl = !!process.env.AZURE_BASE_URL\n        const hasResourceName = !!process.env.AZURE_RESOURCE_NAME\n        if (!hasBaseUrl && !hasResourceName) {\n            throw new Error(\n                `Azure requires either AZURE_BASE_URL or AZURE_RESOURCE_NAME to be set. ` +\n                    `Please set one in your .env.local file.`,\n            )\n        }\n    }\n}\n\n/**\n * Get the AI model based on environment variables\n *\n * Environment variables:\n * - AI_PROVIDER: The provider to use (bedrock, openai, anthropic, google, azure, ollama, openrouter, aihubmix, deepseek, siliconflow, sglang, gateway, modelscope)\n * - AI_MODEL: The model ID/name for the selected provider\n *\n * Provider-specific env vars:\n * - OPENAI_API_KEY: OpenAI API key\n * - OPENAI_BASE_URL: Custom OpenAI-compatible endpoint (optional)\n * - ANTHROPIC_API_KEY: Anthropic API key","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/ai-providers.ts#L660-L696","documentation":"Azure provider needs a base URL: either AZURE_BASE_URL directly or AZURE_RESOURCE_NAME (used to construct https://<name>.openai.azure.com) in addition to the API key.","triggerScenarios":"Provider azure with AZURE_API_KEY set but neither AZURE_BASE_URL nor AZURE_RESOURCE_NAME present.","commonSituations":"Copying Azure OpenAI key setup from older docs, forgetting the resource name, or renaming the resource without updating env.","solutions":["Set AZURE_RESOURCE_NAME=your-resource (simplest) or AZURE_BASE_URL=https://your-resource.openai.azure.com in .env.local","Confirm the resource name matches your Azure OpenAI resource","Restart the server after editing env"],"exampleFix":"# before\nAI_PROVIDER=azure\nAZURE_API_KEY=...\n\n# after\nAI_PROVIDER=azure\nAZURE_API_KEY=...\nAZURE_RESOURCE_NAME=my-azure-openai-resource","handlingStrategy":"validation","validationCode":"const azureOk = !!process.env.AZURE_BASE_URL || !!process.env.AZURE_RESOURCE_NAME\nif (provider === 'azure' && !azureOk) failFast('Azure needs AZURE_BASE_URL or AZURE_RESOURCE_NAME')","typeGuard":null,"tryCatchPattern":"try { getAIModel() } catch (e) { if ((e as Error).message.includes('AZURE_BASE_URL')) showAzureSetupGuide() }","preventionTips":["Document Azure's dual env options in .env.example","Use AZURE_RESOURCE_NAME for standard azure.com endpoints","Verify the resource name against the Azure portal"],"tags":["env-var","azure","credentials","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}