diff --git a/core/providers/anthropic/utils.go b/core/providers/anthropic/utils.go index a0ff905568..1dbbbedb08 100644 --- a/core/providers/anthropic/utils.go +++ b/core/providers/anthropic/utils.go @@ -235,6 +235,13 @@ func getRequestBodyForResponses(ctx *schemas.BifrostContext, request *schemas.Bi } } } + + // delete fallbacks field + jsonBody, err = providerUtils.DeleteJSONField(jsonBody, "fallbacks") + if err != nil { + return nil, providerUtils.NewBifrostOperationError(schemas.ErrProviderRequestMarshal, err, providerName) + } + return jsonBody, nil } diff --git a/core/providers/anthropic/utils_test.go b/core/providers/anthropic/utils_test.go index f778468971..e9d7172e42 100644 --- a/core/providers/anthropic/utils_test.go +++ b/core/providers/anthropic/utils_test.go @@ -1474,6 +1474,39 @@ func TestAnthropicToolUnmarshalJSON_MCPToolset(t *testing.T) { }) } +func TestGetRequestBodyForResponses_RawBodyStripsFallbacks(t *testing.T) { + rawBody := []byte(`{"model":"claude-sonnet-4-5","max_tokens":1024,"messages":[{"role":"user","content":"hello"}],"fallbacks":["claude-haiku-4-5"],"temperature":0.7}`) + + ctx := schemas.NewBifrostContext(nil, time.Time{}) + ctx.SetValue(schemas.BifrostContextKeyUseRawRequestBody, true) + + request := &schemas.BifrostResponsesRequest{ + Provider: schemas.Anthropic, + Model: "claude-sonnet-4-5", + RawRequestBody: rawBody, + } + + result, bifrostErr := getRequestBodyForResponses(ctx, request, schemas.Anthropic, false, nil) + if bifrostErr != nil { + t.Fatalf("unexpected error: %v", bifrostErr) + } + + if providerUtils.GetJSONField(result, "fallbacks").Exists() { + t.Error("expected 'fallbacks' to be absent from raw-body output") + } + + // Other fields must survive the round-trip + if !providerUtils.GetJSONField(result, "model").Exists() { + t.Error("expected 'model' to be present") + } + if !providerUtils.GetJSONField(result, "max_tokens").Exists() { + t.Error("expected 'max_tokens' to be present") + } + if !providerUtils.GetJSONField(result, "temperature").Exists() { + t.Error("expected 'temperature' to be present") + } +} + func TestApplyMCPToolsetConfigToBifrostTool(t *testing.T) { t.Run("allowlist pattern merges correctly", func(t *testing.T) { bifrostTool := &schemas.ResponsesTool{