From 9907fae594380db488c72583c7242991443d9778 Mon Sep 17 00:00:00 2001 From: echowxsy Date: Fri, 27 Feb 2026 18:15:53 +0800 Subject: [PATCH] fix: use Anthropic SDK provider for anthropic protocol with API key The anthropic protocol case in CreateProviderFromConfig incorrectly used NewHTTPProviderWithMaxTokensFieldAndRequestTimeout (OpenAI-compatible HTTP provider) when an API key was provided. This sent OpenAI-format requests to Anthropic-compatible endpoints, causing 404 errors. Switch to NewClaudeProviderWithBaseURL which uses the official Anthropic SDK and sends proper Anthropic Messages API format requests. This fixes model_list entries like: {"model": "anthropic/glm-4.7", "api_base": "https://api.z.ai/api/anthropic/v1"} Co-Authored-By: Claude Opus 4.6 --- pkg/providers/factory_provider.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pkg/providers/factory_provider.go b/pkg/providers/factory_provider.go index 53f7a08a0..384a29af5 100644 --- a/pkg/providers/factory_provider.go +++ b/pkg/providers/factory_provider.go @@ -120,21 +120,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 Anthropic Messages API 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, - ), modelID, nil + return NewClaudeProviderWithBaseURL(cfg.APIKey, cfg.APIBase), modelID, nil case "antigravity": return NewAntigravityProvider(), modelID, nil