Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions intercept/messages/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ func (i *interceptionBase) withAWSBedrockOptions(ctx context.Context, cfg *aibco
}

var out []option.RequestOption
out = append(out, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) {
if ua := req.Header.Get("User-Agent"); ua != "" {
req.Header.Set("User-Agent", ua+" sdk-ua-app-id/APN_1.1%2Fpc_cdfmjwn8i6u8l9fwz8h82e4w3%24")
}
return next(req)
}))
out = append(out, bedrock.WithConfig(awsCfg))

// If a custom base URL is set, override the default endpoint constructed by the bedrock middleware.
Expand Down
12 changes: 12 additions & 0 deletions internal/integrationtest/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func TestAnthropicMessages(t *testing.T) {
require.Len(t, promptUsages, 1)
assert.Equal(t, "read the foo file", promptUsages[0].Prompt)

// Verify PRM attribution is NOT present on non-Bedrock Anthropic requests.
received := upstream.receivedRequests()
require.Len(t, received, 1)
ua := received[0].Header.Get("User-Agent")
assert.NotContains(t, ua, "sdk-ua-app-id",
"PRM attribution should not be present on non-Bedrock requests")

bridgeServer.Recorder.VerifyAllInterceptionsEnded(t)
})
}
Expand Down Expand Up @@ -308,6 +315,11 @@ func TestAWSBedrockIntegration(t *testing.T) {
require.False(t, gjson.GetBytes(received[0].Body, "model").Exists(), "model should be stripped from body")
require.False(t, gjson.GetBytes(received[0].Body, "stream").Exists(), "stream should be stripped from body")

// Verify PRM attribution is appended to the User-Agent header.
ua := received[0].Header.Get("User-Agent")
require.Contains(t, ua, "sdk-ua-app-id/APN_1.1%2Fpc_cdfmjwn8i6u8l9fwz8h82e4w3%24",
"expected AWS PRM attribution in User-Agent header")

interceptions := bridgeServer.Recorder.RecordedInterceptions()
require.Len(t, interceptions, 1)
require.Equal(t, interceptions[0].Model, bedrockCfg.Model)
Expand Down
Loading