Add Azure OpenAI support with automatic provider routing

🟢 open · #1 · theincyber/mike ← theincyber/mike · opened 11d ago by theincyber · self · +734-202 across 13 files · ↗ on GitHub

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
  • Shared Utilities: Extracted common functionality used by both providers

    • Moved apiKey() function to support both OPENAI_API_KEY and AZURE_OPENAI_API_KEY
    • Moved extractSseJson() helper for parsing Server-Sent Events (used by both implementations)
  • 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
  • Configuration: Enhanced .env.example with 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, and AZURE_OPENAI_API_KEY
  • Optional AZURE_OPENAI_API_VERSION defaults to 2024-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)

https://claude.ai/code/session_01MEw5xdUkuCBmxKvTxUbjDV

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.

⬇ Download capture-pull-1.md