Claude Code with Azure OpenAI Setup
Using Claude Code in projects that also rely on Azure OpenAI requires careful configuration of API keys, endpoints, and model routing. This guide covers how to set up Claude Code alongside Azure OpenAI services, manage multiple AI providers, and build workflows that leverage both platforms effectively.
The Problem
Many enterprise teams use Azure OpenAI for production inference (GPT-4, embeddings, completions) while wanting Claude Code for development assistance. Managing two sets of API credentials, keeping model references consistent, and avoiding accidental cross-contamination of keys creates friction. Developers need a clean separation between their coding assistant and their application’s AI backend.
Quick Solution
- Set up Azure OpenAI credentials as environment variables for your application:
export AZURE_OPENAI_API_KEY="your-azure-openai-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"
export AZURE_OPENAI_DEPLOYMENT="gpt-4"
export AZURE_OPENAI_API_VERSION="2024-10-21"
- Keep Claude Code’s Anthropic API key separate:
export ANTHROPIC_API_KEY="your-anthropic-key"
- Create a
.envfile for your application (not for Claude Code):
# .env - Application AI config (Azure OpenAI)
AZURE_OPENAI_API_KEY=your-azure-openai-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=gpt-4
AZURE_OPENAI_API_VERSION=2024-10-21
- Add
.envto your.gitignoreto prevent credential leaks:
echo ".env" >> .gitignore
- Document the dual-provider setup in CLAUDE.md so Claude Code understands the architecture.
How It Works
Claude Code uses the Anthropic API for its own operation and has no direct interaction with Azure OpenAI. The separation is architectural: Claude Code is your development tool, while Azure OpenAI is your application’s AI backend.
When Claude Code reads your codebase, it sees Azure OpenAI SDK calls, endpoint configurations, and deployment names. By documenting these in CLAUDE.md, Claude Code understands the distinction and can help you write, debug, and optimize your Azure OpenAI integration code without confusing its own API context.
For teams using Claude Code with an Anthropic API key alongside Azure OpenAI in production, the key insight is environment isolation. Your application reads from .env or Azure Key Vault. Claude Code reads from its own configuration. The two never overlap.
Common Issues
API key confusion: Claude Code may suggest using OPENAI_API_KEY when your setup uses AZURE_OPENAI_API_KEY. Add explicit notes in CLAUDE.md about which environment variable names your project uses.
SDK version mismatch: Azure OpenAI SDK versions change frequently. If Claude Code suggests API calls that fail, specify the exact SDK version in your CLAUDE.md so it generates compatible code.
Endpoint format errors: Azure OpenAI endpoints follow the pattern https://{resource}.openai.azure.com/openai/deployments/{deployment}/chat/completions?api-version={version}. Claude Code may default to the standard OpenAI format. Document the exact URL pattern.
Example CLAUDE.md Section
# AI Provider Architecture
## Development Tool (Claude Code)
- Uses Anthropic API via ANTHROPIC_API_KEY
- Not part of the application runtime
## Application AI Backend (Azure OpenAI)
- Endpoint: https://acme-ai.openai.azure.com
- Deployment: gpt-4-turbo (model: gpt-4-1106-preview)
- Embedding deployment: text-embedding-3-large
- API Version: 2024-10-21
- SDK: @azure/openai v2.1.0
## Code Patterns
- All Azure OpenAI calls go through src/lib/ai-client.ts
- Use AzureOpenAI class, NOT OpenAI class
- Always pass deployment name, not model name
- Retry with exponential backoff on 429 errors
- Token counting uses tiktoken with cl100k_base encoding
Best Practices
- Never mix API keys in the same config file. Keep Anthropic credentials for Claude Code separate from Azure OpenAI credentials for your application.
- Pin SDK versions. Azure OpenAI SDK changes can break your code. Lock versions in
package.jsonand note them in CLAUDE.md. - Use Azure Key Vault for production secrets. Do not hardcode Azure OpenAI keys. Reference Key Vault in your deployment configuration and document this pattern for Claude Code.
- Document the deployment-model mapping. Azure OpenAI uses deployment names, not model names. Map these explicitly so Claude Code generates correct API calls.
- Test with both providers independently. Use separate test scripts for Azure OpenAI integration tests and keep Claude Code development assistance separate.
Related Reading
- Anthropic API Error 429 Rate Limit
- Claude Code MCP Server Setup
- Best Way to Use Claude Code for Debugging Sessions
Built by theluckystrike. More at zovo.one