Add Azure Anthropic support

This commit is contained in:
2026-03-01 19:00:03 +00:00
parent 88fe79e457
commit b5f21f385a
4 changed files with 57 additions and 6 deletions

View File

@@ -14,3 +14,8 @@ providers:
api_key: "YOUR_OPENAI_API_KEY"
model: "gpt-4o-mini"
endpoint: "https://api.openai.com"
# Azure-hosted Anthropic (Microsoft Foundry) - optional, overrides anthropic if set
# azureanthropic:
# api_key: "YOUR_AZURE_ANTHROPIC_API_KEY"
# endpoint: "https://your-resource.services.ai.azure.com/anthropic"
# model: "claude-sonnet-4-5-20250514"

View File

@@ -32,6 +32,14 @@ type ProvidersConfig struct {
Anthropic ProviderConfig `yaml:"anthropic"`
OpenAI ProviderConfig `yaml:"openai"`
AzureOpenAI AzureOpenAIConfig `yaml:"azureopenai"`
AzureAnthropic AzureAnthropicConfig `yaml:"azureanthropic"`
}
// AzureAnthropicConfig contains Azure-specific settings for Anthropic (Microsoft Foundry).
type AzureAnthropicConfig struct {
APIKey string `yaml:"api_key"`
Endpoint string `yaml:"endpoint"`
Model string `yaml:"model"`
}
// ProviderConfig contains shared provider configuration fields.
@@ -83,6 +91,17 @@ func (cfg *Config) applyEnvOverrides() {
if v := os.Getenv("AZURE_OPENAI_API_VERSION"); v != "" {
cfg.Providers.AzureOpenAI.APIVersion = v
}
// Azure Anthropic (Microsoft Foundry) overrides
if v := os.Getenv("AZURE_ANTHROPIC_API_KEY"); v != "" {
cfg.Providers.AzureAnthropic.APIKey = v
}
if v := os.Getenv("AZURE_ANTHROPIC_ENDPOINT"); v != "" {
cfg.Providers.AzureAnthropic.Endpoint = v
}
if v := os.Getenv("AZURE_ANTHROPIC_MODEL"); v != "" {
cfg.Providers.AzureAnthropic.Model = v
}
}
func overrideAPIKey(cfg *ProviderConfig, envKey string) {

View File

@@ -15,12 +15,14 @@ import (
const Name = "anthropic"
// Provider implements the Anthropic SDK integration.
// It supports both direct Anthropic API and Azure-hosted (Microsoft Foundry) endpoints.
type Provider struct {
cfg config.ProviderConfig
client *anthropic.Client
azure bool
}
// New constructs a Provider from configuration.
// New constructs a Provider for the direct Anthropic API.
func New(cfg config.ProviderConfig) *Provider {
var client *anthropic.Client
if cfg.APIKey != "" {
@@ -33,6 +35,29 @@ func New(cfg config.ProviderConfig) *Provider {
}
}
// NewAzure constructs a Provider targeting Azure-hosted Anthropic (Microsoft Foundry).
// The Azure endpoint uses api-key header auth and a base URL like
// https://<resource>.services.ai.azure.com/anthropic.
func NewAzure(azureCfg config.AzureAnthropicConfig) *Provider {
var client *anthropic.Client
if azureCfg.APIKey != "" && azureCfg.Endpoint != "" {
c := anthropic.NewClient(
option.WithBaseURL(azureCfg.Endpoint),
option.WithAPIKey("unused"),
option.WithAuthToken(azureCfg.APIKey),
)
client = &c
}
return &Provider{
cfg: config.ProviderConfig{
APIKey: azureCfg.APIKey,
Model: azureCfg.Model,
},
client: client,
azure: true,
}
}
func (p *Provider) Name() string { return Name }
// Generate routes the Open Responses request to Anthropic's API.

View File

@@ -31,7 +31,9 @@ func NewRegistry(cfg config.ProvidersConfig) (*Registry, error) {
if cfg.Google.APIKey != "" {
reg.providers[googleprovider.Name] = googleprovider.New(cfg.Google)
}
if cfg.Anthropic.APIKey != "" {
if cfg.AzureAnthropic.APIKey != "" && cfg.AzureAnthropic.Endpoint != "" {
reg.providers[anthropicprovider.Name] = anthropicprovider.NewAzure(cfg.AzureAnthropic)
} else if cfg.Anthropic.APIKey != "" {
reg.providers[anthropicprovider.Name] = anthropicprovider.New(cfg.Anthropic)
}
if cfg.AzureOpenAI.APIKey != "" && cfg.AzureOpenAI.Endpoint != "" {