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 <noreply@anthropic.com>
This commit is contained in:
parent
29d4019e62
commit
9907fae594
1 changed files with 2 additions and 12 deletions
|
|
@ -120,21 +120,11 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
|
||||||
}
|
}
|
||||||
return provider, modelID, nil
|
return provider, modelID, nil
|
||||||
}
|
}
|
||||||
// Use API key with HTTP API
|
// Use API key with Anthropic Messages API
|
||||||
apiBase := cfg.APIBase
|
|
||||||
if apiBase == "" {
|
|
||||||
apiBase = "https://api.anthropic.com/v1"
|
|
||||||
}
|
|
||||||
if cfg.APIKey == "" {
|
if cfg.APIKey == "" {
|
||||||
return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model)
|
return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model)
|
||||||
}
|
}
|
||||||
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
|
return NewClaudeProviderWithBaseURL(cfg.APIKey, cfg.APIBase), modelID, nil
|
||||||
cfg.APIKey,
|
|
||||||
apiBase,
|
|
||||||
cfg.Proxy,
|
|
||||||
cfg.MaxTokensField,
|
|
||||||
cfg.RequestTimeout,
|
|
||||||
), modelID, nil
|
|
||||||
|
|
||||||
case "antigravity":
|
case "antigravity":
|
||||||
return NewAntigravityProvider(), modelID, nil
|
return NewAntigravityProvider(), modelID, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue