[codex] Add AWS-native authentication for Bedrock#1938
Open
HAYDEN-OAI wants to merge 12 commits into
Open
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce11aa0085
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that 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.
Summary
This adds first-class Amazon Bedrock support through the standard
OpenAIclient:The change:
BedrockOpenAIworking as a compatibility wrapperopenai/providers/bedrockfor CommonJS, ESM, browser bearer use, and JSRProvider seam
When
provideris configured, the provider owns the base URL and authentication. The client rejects conflicting top-levelapiKey,adminAPIKey,workloadIdentity, andbaseURLoptions and does not inherit ambient OpenAI credentials or headers.The provider receives the fully serialized request after subclass preparation and before every request attempt. This lets Bedrock sign the exact method, URL, headers, query, and body while refreshing credentials and signatures on retries.
withOptions()preserves the provider configuration.Bedrock routing and authentication
The provider uses the regional Mantle endpoint:
The
/openai/v1prefix is intentional. AWS confirmed that it is the OpenAI compatibility contract, while similarly named routes under/v1, includingmodels, can return different response shapes. Requests are signed with thebedrock-mantleSigV4 service name.Authentication is selected in this order:
AWS_BEARER_TOKEN_BEDROCKExplicit bearer and AWS credential modes are mutually exclusive. Passing
apiKey: nullskips an ambient Bedrock bearer token and deliberately selects AWS credentials.Bearer authentication has no additional runtime dependencies. SigV4 authentication is supported in Node.js and compatible server runtimes through these optional peer dependencies:
@aws-sdk/credential-provider-node@smithy/hash-node@smithy/signature-v4The dependencies load only when AWS credential authentication is selected. Their ESM and CommonJS resolution is module-relative rather than working-directory-relative, and the browser bundle can import the provider for bearer authentication without bundling AWS packages.
SigV4 signs the exact serialized, replayable request body and runs again for every retry. The provider also:
AuthorizationheadersRequest streaming through
UNSIGNED-PAYLOADor AWS-chunked signing is intentionally outside this first milestone. Standard JSON requests are replayable, response streaming is unaffected, and Mantle waits for the complete request body before authentication and authorization.Compatibility and packaging
BedrockOpenAIremains available withawsRegion,awsProfile,awsCredentialProvider, andbedrockTokenProvideroption names. It now delegates to the same provider implementation, including credential refresh andwithOptions()behavior.This also:
response.output_textfor ordinary, non-structured Responses API callsTesting
The tests cover provider ownership, ambient OpenAI configuration isolation, request preparation order, retry signing, bearer and AWS credential precedence, the real AWS environment credential chain with a temporary session token, credential refresh,
withOptions(), endpoint normalization, region validation, custom authorization rejection, non-replayable body rejection, browser bearer authentication, compatibility behavior, and a deterministic SigV4 fixture.The focused suites include 94 tests. V8 coverage across the ordinary and dependency-mocking suites is:
src/internal/provider.ts: 100% statements, branches, functions, and linessrc/providers/bedrock.ts: 100% statements, functions, and lines; 98.85% branchessrc/bedrock.ts: 100% statements, branches, functions, and linesLive validation is isolated from the standard test suite under
tests/live/bedrock.live.test.ts. It requires an explicit safety flag, disables retries, usesstore: false, and can exercise bearer, environment bearer, default-chain, named-profile, static, and custom-provider authentication:Set
BEDROCK_LIVE_STREAM=1to include a streaming request.AWS_BEDROCK_BASE_URLcan override the derived endpoint for live endpoint comparisons.Attribution
This builds on and substantially expands Jim's initial implementation in jim-openai/openai-node#1. Thank you, Jim, for getting the first version moving and letting us take it over.
Validation
us-east-2The full pnpm lint pipeline, including formatting, ESLint, SDK and Deno builds, TypeScript, Are The Types Wrong?, Publint, and the JSR publish dry run, passes locally.