[codex] Add AWS Bedrock provider authentication#3398
Draft
HAYDEN-OAI wants to merge 5 commits into
Draft
Conversation
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
OpenAIandAsyncOpenAIclientsfrom openai.providers import bedrockandOpenAI(provider=bedrock(...))BedrockOpenAI,AsyncBedrockOpenAI, and the legacy module client as compatibility facades over the same provider implementationThis supersedes the earlier client-specific implementation while retaining its useful AWS authentication foundation. Thanks to Jim Blomo for the original draft and auth work: jim-openai#1.
Provider architecture
Provider configs are created only by OpenAI-owned factories and remain opaque to callers. The base client continues to own resources, request construction, retries, streaming, response parsing, and errors; the provider runtime supplies its base URL and lifecycle hooks for request-option transforms, final-request authentication, and response normalization.
When
provideris configured, top-levelapi_key,admin_api_key,workload_identity, andbase_urlare rejected so authentication and routing have one clear owner. OpenAI-specific credential and routing environment variables are ignored. Provider configuration surviveswith_options(), can be replaced with another provider, or can be removed when switching back to normal OpenAI credentials.Response normalization runs before retry and status handling, and request authentication runs against the fully built request on every attempt.
Bedrock authentication and safety
The Bedrock provider supports:
SigV4 uses the
bedrock-mantleservice name and the/openai/v1endpoint contract. Every retry rebuilds and signs the final request with fresh credentials and time. Request bodies are hashed exactly; one-shot bodies are rejected for SigV4, andUNSIGNED-PAYLOADand AWS-chunked streaming are intentionally outside this milestone.Both bearer and SigV4 authentication are bound to the configured origin. Custom
Authorizationheaders are rejected, custom HTTPX auth cannot replace provider auth, canonical endpoint/signing-region mismatches are rejected, and automatic redirects are disabled for SigV4. Secret values are excluded from provider and compatibility-state representations, and temporary AWS session headers remain redacted from logs.Async AWS credential construction, refresh, and signing are moved off the event-loop thread. Botocore remains lazy and optional for bearer-only users, with
openai[bedrock]providing the AWS dependencies.Compatibility
BedrockOpenAIandAsyncBedrockOpenAItranslate their existing options intobedrock(...). Their mutableapi_key, routing, subclass, module-client, and chainedwith_options()behavior is preserved by resynchronizing the provider runtime rather than maintaining a second wire-auth implementation.Environment bearer credentials retain the legacy capture behavior in the compatibility clients, while the new public provider refreshes
AWS_BEARER_TOKEN_BEDROCKper attempt and across clones.Validation
pytest -q -n 0 -p no:benchmark tests/lib tests/test_module_client.py tests/test_utils/test_logging.py— 261 passedruff check .ruff format --checkFull-repository Mypy in this local environment still reports two unrelated existing Pydantic override-signature errors in
src/openai/_models.py; the changed files are clean.Remaining validation