ai: add custom-header support to Bedrock provider#5178
Merged
badlogic merged 1 commit intoMay 29, 2026
Conversation
Honour StreamOptions.headers in the Bedrock provider by attaching a Smithy build-step middleware that merges caller headers into the request before SigV4 signing. Reserved headers (x-amz-*, authorization, host) are silently skipped to preserve signing and the bearer-token auth path. No-op when no headers are supplied. Updates the StreamOptions.headers JSDoc to drop the Bedrock caveat.
|
This is a great addition, I can maybe stop hand rolling my Bedrock provider! Will check it out and feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Honour
StreamOptions.headersin the AWS Bedrock provider.d2be648addedheadersto every provider except Bedrock, deferred with "Bedrock not supported (uses AWS SDK auth)". This closes that gap soheadersis meaningful on all six routes.Why
Corporate / proxy gateways fronting Bedrock often want per-request HTTP-header tagging for cost attribution, audit, or routing (e.g. an
X-*tenant or cost tag on the wire). Today callers can attach those to Anthropic / OpenAI / OpenAI-Responses / Google / Google-Vertex viaoptions.headers, but the Bedrock route is a blind spot. The "uses AWS SDK auth" note is accurate for the auth header itself; it does not preclude attaching additional custom headers alongside it.How
streamBedrock, after constructingBedrockRuntimeClient, attach a Smithybuild-step middleware that mergesoptions.headersintorequest.headers.buildstep (notfinalizeRequest) so the injected headers are covered by the SigV4 signature. Headers added after signing would be rejected by AWS.x-amz-*,authorization, andhost(case-insensitive) so a caller can't desync SigV4 or strip the Bearer token from feat(bedrock): support Bearer token auth for Converse API #3125.headersis empty/undefined — the middleware is only attached when there is at least one header, so there is zero overhead on the common path.streamSimpleBedrockalready forwardsheadersviabuildBaseOptions; kept as-is and covered by a regression test.StreamOptions.headersJSDoc to drop the Bedrock caveat and document the new behaviour and the reserved-header guard.The middleware reuses the same
BedrockRuntimeClient.middlewareStackinjection pattern previously used on this client in #3125.Tests
New
packages/ai/test/bedrock-custom-headers.test.ts, mocking@aws-sdk/client-bedrock-runtimein the style ofbedrock-endpoint-resolution.test.ts(no real AWS credentials):request.headers, registered on thebuildstep withpriority: "low";authorization/x-amz-*left untouched (case-insensitive) while an allowed header is added;headersisundefinedor{}, plus a structural pass-through when the request has noheaders;streamSimpleBedrockforwardsheadersend-to-end.npm run checkis clean.Suggested changelog entry (for a maintainer to add under
### Added— I have not touchedCHANGELOG.md)Honour
StreamOptions.headersin the AWS Bedrock provider via a Smithy build-step middleware, with a reserved-header guard (x-amz-*/authorization/host).closes #5123