fix(provider/anthropic): normalize model ID dots to dashes before API call
The Anthropic API expects hyphens in model IDs (e.g. claude-sonnet-4-6), but config files use dots (claude-sonnet-4.6). The dot-to-dash normalization only existed in the SDK-based provider, so API-key and anthropic-messages paths sent the dotted name and got a 404. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Pavel Anni <panni@redhat.com>
This commit is contained in:
parent
f2addff099
commit
46a97d3256
3 changed files with 9 additions and 3 deletions
|
|
@ -161,8 +161,11 @@ func buildRequestBody(
|
||||||
return nil, fmt.Errorf("max_tokens is required in options")
|
return nil, fmt.Errorf("max_tokens is required in options")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize model ID: Anthropic API uses hyphens (claude-sonnet-4-6),
|
||||||
|
// but config may use dots (claude-sonnet-4.6).
|
||||||
|
apiModel := strings.ReplaceAll(model, ".", "-")
|
||||||
result := map[string]any{
|
result := map[string]any{
|
||||||
"model": model,
|
"model": apiModel,
|
||||||
"max_tokens": int64(maxTokens),
|
"max_tokens": int64(maxTokens),
|
||||||
"messages": []any{},
|
"messages": []any{},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,9 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
|
||||||
), modelID, nil
|
), modelID, nil
|
||||||
|
|
||||||
case "anthropic":
|
case "anthropic":
|
||||||
|
// Normalize model ID: Anthropic API uses hyphens (claude-sonnet-4-6),
|
||||||
|
// but config may use dots (claude-sonnet-4.6).
|
||||||
|
modelID = strings.ReplaceAll(modelID, ".", "-")
|
||||||
if cfg.AuthMethod == "oauth" || cfg.AuthMethod == "token" {
|
if cfg.AuthMethod == "oauth" || cfg.AuthMethod == "token" {
|
||||||
// Use OAuth credentials from auth store
|
// Use OAuth credentials from auth store
|
||||||
provider, err := createClaudeAuthProvider()
|
provider, err := createClaudeAuthProvider()
|
||||||
|
|
|
||||||
|
|
@ -236,8 +236,8 @@ func TestCreateProviderFromConfig_Anthropic(t *testing.T) {
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
||||||
}
|
}
|
||||||
if modelID != "claude-sonnet-4.6" {
|
if modelID != "claude-sonnet-4-6" {
|
||||||
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4.6")
|
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4-6")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue