Add Azure OpenAI support with automatic provider routing
From the PR description
Summary
This PR adds support for Azure OpenAI as an alternative LLM provider, allowing users to route OpenAI API calls through their own Azure tenancy for data sovereignty. The implementation includes automatic provider detection and routing based on environment configuration.
Key Changes
Azure OpenAI Integration: Added complete Azure OpenAI Chat Completions API implementation with streaming and tool calling support
- New
streamAzure()function handles streaming chat completions with tool use - New
completeAzureText()function handles non-streaming text completion - Proper accumulation and parsing of tool call deltas from Azure's streaming format
- New
Shared Utilities: Extracted common functionality used by both providers
- Moved
apiKey()function to support bothOPENAI_API_KEYandAZURE_OPENAI_API_KEY - Moved
extractSseJson()helper for parsing Server-Sent Events (used by both implementations)
- Moved
Provider Routing: Added automatic dispatch layer
- New
getAzureConfig()detects Azure configuration from environment variables - Refactored public exports (
streamOpenAI,completeOpenAIText) to dispatch to Azure or standard OpenAI based on configuration - Renamed internal functions (
streamOpenAIResponses,completeOpenAIResponsesText) to clarify they handle standard OpenAI
- New
Configuration: Enhanced
.env.examplewith comprehensive documentation- Added detailed comments explaining database, storage, and LLM provider options
- Documented Azure OpenAI setup with instructions for Azure Portal configuration
- Clarified that Azure configuration takes precedence over standard OpenAI when set
Implementation Details
- Azure configuration requires three environment variables:
AZURE_OPENAI_ENDPOINT,AZURE_OPENAI_DEPLOYMENT, andAZURE_OPENAI_API_KEY - Optional
AZURE_OPENAI_API_VERSIONdefaults to2024-08-01-preview - Tool calls are accumulated from streaming deltas and normalized to match the standard interface
- Error handling includes proper HTTP status code propagation for debugging
- The implementation maintains full feature parity with standard OpenAI (streaming, tool use, system prompts)
Our analysis
Add Azure OpenAI as an alternative LLM provider — read the full analysis →
Think the analysis missed something the PR description covers?
Capture this PR into my fork
Download a Markdown prompt that tells Claude how to port every
commit in this PR into your working tree. Run it via
claude -p < capture-pull-1.md from
inside the repo you want the changes in.