diff --git a/env.example b/env.example index 8ec6d43..616243e 100644 --- a/env.example +++ b/env.example @@ -41,9 +41,13 @@ AI_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0 # GOOGLE_THINKING_LEVEL=high # Optional: Gemini 3 thinking level (low/high) # Azure OpenAI Configuration +# Configure endpoint using ONE of these methods: +# 1. AZURE_RESOURCE_NAME - SDK constructs: https://{name}.openai.azure.com/openai/v1{path} +# 2. AZURE_BASE_URL - SDK appends /v1{path} to your URL +# If both are set, AZURE_BASE_URL takes precedence. # AZURE_RESOURCE_NAME=your-resource-name # AZURE_API_KEY=... -# AZURE_BASE_URL=https://your-resource.openai.azure.com # Optional: Custom endpoint (overrides resourceName) +# AZURE_BASE_URL=https://your-resource.openai.azure.com/openai # Alternative: Custom endpoint # AZURE_REASONING_EFFORT=low # Optional: Azure reasoning effort (low, medium, high) # AZURE_REASONING_SUMMARY=detailed diff --git a/lib/ai-providers.ts b/lib/ai-providers.ts index 3fafe94..b98dc1e 100644 --- a/lib/ai-providers.ts +++ b/lib/ai-providers.ts @@ -572,10 +572,15 @@ export function getAIModel(overrides?: ClientOverrides): ModelConfig { case "azure": { const apiKey = overrides?.apiKey || process.env.AZURE_API_KEY const baseURL = overrides?.baseUrl || process.env.AZURE_BASE_URL - if (baseURL || overrides?.apiKey) { + const resourceName = process.env.AZURE_RESOURCE_NAME + // Azure requires either baseURL or resourceName to construct the endpoint + // resourceName constructs: https://{resourceName}.openai.azure.com/openai/v1{path} + if (baseURL || resourceName || overrides?.apiKey) { const customAzure = createAzure({ apiKey, + // baseURL takes precedence over resourceName per SDK behavior ...(baseURL && { baseURL }), + ...(!baseURL && resourceName && { resourceName }), }) model = customAzure(modelId) } else {