From c6bb463837ec8c41261604e416aeab023663ba09 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 29 Jan 2026 20:23:41 +0200 Subject: feat: add native Anthropic API provider support - Implement new anthropicClient with full Client interface - Add Streamer interface for token-by-token streaming via SSE - Add Anthropic Messages API v1 integration with proper headers - Support claude-3-5-sonnet-20241022 as default model - Add configuration via [anthropic] TOML section - Add environment variable overrides (HEXAI_ANTHROPIC_*) - Support both HEXAI_ANTHROPIC_API_KEY and ANTHROPIC_API_KEY fallback - Integrate Anthropic key handling in LSP, CLI, and llmutils - Update provider factory to support 'anthropic' provider name - Add 11 comprehensive unit tests for Anthropic client - Update config.toml.example with [anthropic] section - Update NewFromConfig() signature to accept anthropicAPIKey parameter - All 51 internal LLM tests pass (11 new Anthropic tests + 40 existing) Anthropic models can be accessed via: [anthropic] model = "claude-3-5-sonnet-20241022" base_url = "https://api.anthropic.com/v1" temperature = 0.2 or environment: export HEXAI_PROVIDER="anthropic" export HEXAI_ANTHROPIC_API_KEY="your-key" Amp-Thread-ID: https://ampcode.com/threads/T-019c0af1-f215-72cf-9940-b014b1a9576b Co-authored-by: Amp --- internal/llmutils/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'internal/llmutils') diff --git a/internal/llmutils/client.go b/internal/llmutils/client.go index 2f3da55..53fca9c 100644 --- a/internal/llmutils/client.go +++ b/internal/llmutils/client.go @@ -24,6 +24,9 @@ func NewClientFromApp(cfg appconfig.App) (llm.Client, error) { CopilotBaseURL: cfg.CopilotBaseURL, CopilotModel: cfg.CopilotModel, CopilotTemperature: cfg.CopilotTemperature, + AnthropicBaseURL: cfg.AnthropicBaseURL, + AnthropicModel: cfg.AnthropicModel, + AnthropicTemperature: cfg.AnthropicTemperature, } oaKey := os.Getenv("HEXAI_OPENAI_API_KEY") if strings.TrimSpace(oaKey) == "" { @@ -37,5 +40,9 @@ func NewClientFromApp(cfg appconfig.App) (llm.Client, error) { if strings.TrimSpace(cpKey) == "" { cpKey = os.Getenv("COPILOT_API_KEY") } - return llm.NewFromConfig(llmCfg, oaKey, orKey, cpKey) + anKey := os.Getenv("HEXAI_ANTHROPIC_API_KEY") + if strings.TrimSpace(anKey) == "" { + anKey = os.Getenv("ANTHROPIC_API_KEY") + } + return llm.NewFromConfig(llmCfg, oaKey, orKey, cpKey, anKey) } -- cgit v1.2.3