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.
This commit is contained in:
parent
415abc8cd4
commit
fee238a045
1 changed files with 2 additions and 13 deletions
|
|
@ -266,22 +266,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 native Anthropic SDK (not OpenAI-compatible HTTPProvider)
|
||||||
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,
|
|
||||||
cfg.ExtraBody,
|
|
||||||
), modelID, nil
|
|
||||||
|
|
||||||
case "anthropic-messages":
|
case "anthropic-messages":
|
||||||
// Anthropic Messages API with native format (HTTP-based, no SDK)
|
// Anthropic Messages API with native format (HTTP-based, no SDK)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue