diff --git a/pkg/providers/anthropic_messages/provider.go b/pkg/providers/anthropic_messages/provider.go index 6a1c473dd..39b274ff2 100644 --- a/pkg/providers/anthropic_messages/provider.go +++ b/pkg/providers/anthropic_messages/provider.go @@ -162,7 +162,7 @@ func buildRequestBody( } result := map[string]any{ - "model": model, + "model": strings.ReplaceAll(model, ".", "-"), "max_tokens": int64(maxTokens), "messages": []any{}, } diff --git a/pkg/providers/anthropic_messages/provider_test.go b/pkg/providers/anthropic_messages/provider_test.go index 39bc48117..4c7b19568 100644 --- a/pkg/providers/anthropic_messages/provider_test.go +++ b/pkg/providers/anthropic_messages/provider_test.go @@ -117,6 +117,26 @@ func TestBuildRequestBody(t *testing.T) { }, }, }, + { + name: "normalizes dotted anthropic model ID", + messages: []Message{ + {Role: "user", Content: "Hello"}, + }, + model: "claude-sonnet-4.6", + options: map[string]any{ + "max_tokens": 8192, + }, + want: map[string]any{ + "model": "claude-sonnet-4-6", + "max_tokens": int64(8192), + "messages": []any{ + map[string]any{ + "role": "user", + "content": "Hello", + }, + }, + }, + }, { name: "missing max_tokens returns error", messages: []Message{ diff --git a/pkg/providers/factory_provider.go b/pkg/providers/factory_provider.go index 962e6ae19..7b249c315 100644 --- a/pkg/providers/factory_provider.go +++ b/pkg/providers/factory_provider.go @@ -218,6 +218,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err if cfg.APIKey() == "" { return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model) } + modelID = strings.ReplaceAll(modelID, ".", "-") return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout( cfg.APIKey(), apiBase, diff --git a/pkg/providers/factory_provider_test.go b/pkg/providers/factory_provider_test.go index f1fe02cc2..6e271d4a6 100644 --- a/pkg/providers/factory_provider_test.go +++ b/pkg/providers/factory_provider_test.go @@ -282,7 +282,7 @@ func TestGetDefaultAPIBase_Mimo(t *testing.T) { } } -func TestCreateProviderFromConfig_Anthropic(t *testing.T) { +func TestCreateProviderFromConfig_AnthropicAPIKeyNormalizesDottedModelID(t *testing.T) { cfg := &config.ModelConfig{ ModelName: "test-anthropic", Model: "anthropic/claude-sonnet-4.6", @@ -296,8 +296,8 @@ func TestCreateProviderFromConfig_Anthropic(t *testing.T) { if provider == nil { t.Fatal("CreateProviderFromConfig() returned nil provider") } - if modelID != "claude-sonnet-4.6" { - t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4.6") + if modelID != "claude-sonnet-4-6" { + t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4-6") } }