[codex] Add AWS-native authentication for Bedrock#1938
Open
HAYDEN-OAI wants to merge 14 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".
|
When can we expect this in Pi (such that we can start using OpenAI Models via Bedrock?) |
apcha-oai
reviewed
Jun 22, 2026
apcha-oai
reviewed
Jun 22, 2026
apcha-oai
reviewed
Jun 22, 2026
apcha-oai
approved these changes
Jun 22, 2026
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 and a dedicated AWS entrypoint:The change:
BedrockOpenAIcompatibility class unchangedProvider 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 when switching from the OpenAI route to a provider.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.
Provider factories capture immutable configuration, while every
OpenAIclient gets fresh runtime state. An opaque provider registry prevents arbitrary JavaScript objects from impersonating providers and uses aglobalThissymbol plusWeakMapso providers work across duplicate CommonJS and ESM module instances without retaining discarded configurations.withOptions()preserves provider-owned headers when cloning the same provider. It drops inherited OpenAI organization, project, and custom headers only when crossing from the core OpenAI route to a provider or switching provider objects.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.The AWS entrypoint selects authentication 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.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.Packaging
Bearer authentication is available from
openai/providers/bedrockwithout AWS dependencies. This keeps normalopenaiimports, the legacyBedrockOpenAIclass, and browser bearer bundles independent from AWS packages.AWS credential authentication is available from
openai/providers/bedrock/aws. It uses normal static imports so Vite, Webpack, Vercel-style file tracing, and other serverless packagers can discover:@aws-sdk/credential-provider-node@smithy/hash-node@smithy/signature-v4These remain optional peer dependencies for the package as a whole, but are required before importing the
/awsentrypoint. If one is absent, import fails immediately with the runtime's normal module-not-found error.The AWS subpath is exported from npm and JSR. The standalone Bedrock guide remains in the repository rather than being added to build distributions, consistent with other provider guides.
Compatibility
The existing
BedrockOpenAIclass remains bearer-only and available for current applications. New AWS-authenticated applications should usenew OpenAI({ provider: bedrock(...) })fromopenai/providers/bedrock/aws.The shared Responses parser also restores the SDK-synthesized
output_textconvenience property when a raw streamed final response omits it. The underlying distinction between raw wire response types and SDK-enriched response types is broader schema work and is not expanded in this PR.Testing
The focused suites cover provider ownership, ambient OpenAI configuration isolation, same-provider cloning, request preparation order, retry signing, bearer and AWS credential precedence, the real AWS environment credential chain with a temporary session token, credential refresh, endpoint normalization, region validation, custom authorization rejection, non-replayable body rejection, browser bearer authentication, dependency isolation, compatibility behavior, and a deterministic SigV4 fixture clearly marked with AWS documentation test credentials.
V8 coverage across the four provider implementation modules is:
Live validation remains 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
noExternalacross OpenAI, AWS SDK, and Smithy packagesus-east-2