From fee238a045b94db4a706fb0f468b3edc3ec329f6 Mon Sep 17 00:00:00 2001 From: Crong Date: Thu, 2 Apr 2026 06:11:33 +0700 Subject: [PATCH] fix(provider): use native Anthropic SDK for anthropic protocol with API key When using the "anthropic" protocol with an API key (non-OAuth), the factory incorrectly created an OpenAI-compatible HTTPProvider instead of the native Anthropic SDK provider (ClaudeProvider). This caused requests to be sent in OpenAI /v1/chat/completions format to the Anthropic API. Now uses NewClaudeProviderWithBaseURL which sends requests via the native Anthropic Messages API format. --- pkg/providers/factory_provider.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pkg/providers/factory_provider.go b/pkg/providers/factory_provider.go index fb5191bf8..cfd516ee4 100644 --- a/pkg/providers/factory_provider.go +++ b/pkg/providers/factory_provider.go @@ -266,22 +266,11 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err } return provider, modelID, nil } - // Use API key with HTTP API - apiBase := cfg.APIBase - if apiBase == "" { - apiBase = "https://api.anthropic.com/v1" - } + // Use API key with native Anthropic SDK (not OpenAI-compatible HTTPProvider) if cfg.APIKey() == "" { return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model) } - return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( - cfg.APIKey(), - apiBase, - cfg.Proxy, - cfg.MaxTokensField, - cfg.RequestTimeout, - cfg.ExtraBody, - ), modelID, nil + return NewClaudeProviderWithBaseURL(cfg.APIKey(), cfg.APIBase), modelID, nil case "anthropic-messages": // Anthropic Messages API with native format (HTTP-based, no SDK)