Skip to content

[codex] Add AWS Bedrock credential authentication#687

Merged
HAYDEN-OAI merged 12 commits into
mainfrom
dev/hayden/sdk-79-bedrock-aws-credentials
Jul 22, 2026
Merged

[codex] Add AWS Bedrock credential authentication#687
HAYDEN-OAI merged 12 commits into
mainfrom
dev/hayden/sdk-79-bedrock-aws-credentials

Conversation

@HAYDEN-OAI

@HAYDEN-OAI HAYDEN-OAI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Linear: SDK-79

Summary

This adds first-class Amazon Bedrock support through a dedicated bedrock.NewClient constructor that returns the standard OpenAI Go client.

The change:

  • uses the AWS SDK for Go v2 credential chain, including environment credentials, shared credentials and config files, named profiles, SSO and assume-role profiles, web identity, and workload roles
  • supports explicit static or temporary AWS credentials, refreshable credential providers, and existing Bedrock bearer credentials
  • signs the final serialized request with SigV4 service bedrock-mantle on every request attempt
  • adds Bedrock documentation and a Responses API example

Authentication and routing

Authentication is selected in this order:

  1. an explicit bearer credential or token provider
  2. explicit static AWS credentials, a named profile, or an AWS credentials provider
  3. AWS_BEARER_TOKEN_BEDROCK
  4. the standard AWS credential chain

Region resolution uses AWSRegion, then AWS_REGION, AWS_DEFAULT_REGION, and the AWS SDK region chain. The default endpoint is https://bedrock-mantle.{region}.api.aws/openai/v1, with BaseURL and AWS_BEDROCK_BASE_URL overrides.

The /openai/v1 prefix is intentional and matches the approved Node and Python provider implementations. AWS confirmed that it is the OpenAI compatibility contract; the generic /v1 route is a different API surface and is not interchangeable.

The provider does not inherit ambient OPENAI_* credentials, routing, or custom headers. It rejects custom authorization and cross-origin credential forwarding, disables automatic redirects for signed requests, requires replayable SigV4 request bodies, and redacts AWS session tokens from debug logs. SigV4 requires an *http.Client so redirect suppression is enforceable; callers can still customize its transport.

Request lifecycle

A small internal request-finalization seam runs after all client- and method-level options have been applied. Bedrock uses it to place authentication closest to the wire, so user middleware mutations are covered by the signature and retries receive fresh timestamps and refreshed credentials.

Response streaming remains supported. Unsupported Bedrock features remain server-owned and surface through the standard OpenAI client error path.

Testing

Coverage includes:

  • real ~/.aws/credentials and ~/.aws/config resolution
  • default and named profiles
  • temporary session credentials and expiring credential refresh
  • the shared cross-SDK deterministic SigV4 fixture
  • fresh signatures on retries
  • client- and method-level middleware ordering
  • OpenAI environment isolation
  • custom authorization and cross-origin rejection
  • non-replayable request bodies
  • redirect suppression and custom-doer rejection
  • sensitive-header redaction
  • provider option conflicts, malformed AWS configuration, and malformed regions
  • bearer rotation and credential, signer, and body-replay failure paths
  • composable request-finalizer registration

Validation run:

  • ./scripts/test
  • ./scripts/lint
  • go vet ./...
  • go test -cover ./bedrock (97.4% statement coverage)

@HAYDEN-OAI
HAYDEN-OAI marked this pull request as ready for review June 22, 2026 18:26
@HAYDEN-OAI
HAYDEN-OAI requested a review from a team as a code owner June 22, 2026 18:26

@jliccini jliccini left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bedrock endpoint and configuration-safety review.

Comment thread bedrock/auth.go Outdated
Comment thread bedrock/auth.go
Comment thread bedrock/auth.go Outdated

@jliccini jliccini left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining Go API and lifecycle review notes.

Comment thread bedrock/auth.go Outdated
Comment thread bedrock/auth.go Outdated
Comment thread internal/requestconfig/requestconfig.go Outdated
Comment thread bedrock/auth.go Outdated
Comment thread go.mod
@HAYDEN-OAI
HAYDEN-OAI requested a review from jliccini June 22, 2026 23:23
@openai-sdks

openai-sdks Bot commented Jul 14, 2026

Copy link
Copy Markdown

OkTest Summary

237/237 SDK tests passed in 7.184s for Go SDK PR #687.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 105ms
tests/chat-completions-create.test.ts ✅ Passed 164ms
tests/chat-completions-stream.test.ts ✅ Passed 87ms
tests/files-content-binary.test.ts ✅ Passed 119ms
tests/files-create-multipart.test.ts ✅ Passed 102ms
tests/files-list-pagination.test.ts ✅ Passed 109ms
tests/initialize-config.test.ts ✅ Passed 109ms
tests/instance-isolation.test.ts ✅ Passed 81ms
tests/models-list.test.ts ✅ Passed 119ms
tests/responses-background-lifecycle.test.ts ✅ Passed 132ms
tests/responses-body-method-errors.test.ts ✅ Passed 263ms
tests/responses-cancel-timeout.test.ts ✅ Passed 226ms
tests/responses-cancel.test.ts ✅ Passed 115ms
tests/responses-compact-retries.test.ts ✅ Passed 159ms
tests/responses-compact.test.ts ✅ Passed 167ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 92ms
tests/responses-create-advanced.test.ts ✅ Passed 119ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.044s
tests/responses-create-errors.test.ts ✅ Passed 158ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 85ms
tests/responses-create-retries.test.ts ✅ Passed 187ms
tests/responses-create-stream-failures.test.ts ✅ Passed 98ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 186ms
tests/responses-create-stream-wire.test.ts ✅ Passed 1.756s
tests/responses-create-stream.test.ts ✅ Passed 84ms
tests/responses-create-terminal-states.test.ts ✅ Passed 163ms
tests/responses-create-timeout.test.ts ✅ Passed 184ms
tests/responses-create.test.ts ✅ Passed 115ms
tests/responses-delete.test.ts ✅ Passed 124ms
tests/responses-input-items-errors.test.ts ✅ Passed 125ms
tests/responses-input-items-list.test.ts ✅ Passed 132ms
tests/responses-input-items-options.test.ts ✅ Passed 110ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 227ms
tests/responses-input-tokens-count.test.ts ✅ Passed 161ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.395s
tests/responses-not-found-errors.test.ts ✅ Passed 157ms
tests/responses-parse.test.ts ✅ Passed 122ms
tests/responses-retrieve-retries.test.ts ✅ Passed 151ms
tests/responses-retrieve.test.ts ✅ Passed 175ms
tests/responses-stored-method-errors.test.ts ✅ Passed 398ms
tests/retry-behavior.test.ts ✅ Passed 2.979s
tests/sdk-error-shape.test.ts ✅ Passed 192ms

View OkTest run #29952039196

SDK merge (4074c6ef7b3a) · head (04dce828889c) · base (e113b0c4d7ae) · OkTest (d2b5921fc22a)

@HAYDEN-OAI
HAYDEN-OAI enabled auto-merge (squash) July 21, 2026 03:19

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting updates before merge. The request-finalizer ordering, per-attempt signing, body replay, credential caching, environment isolation, and test coverage are all thoughtfully implemented, but two validated issues need to be fixed: bearer credentials can cross an origin boundary through Go's default redirect handling, and fully explicit AWS configuration can still be broken by unrelated ambient AWS config files.

Please also address—or make an explicit documented contract decision on—the two Go developer-experience follow-ups below: SkipAuth rejects the standard explicit API-key option, and permanent provider policy errors are retried with backoff.

I reproduced the two blocking issues with focused tests. Targeted race tests and go vet passed, and the affected packages also passed after merging current main into this head.

Comment thread bedrock/auth.go Outdated
Comment thread bedrock/auth.go
Comment thread bedrock/auth.go Outdated
Comment thread bedrock/auth.go
Copilot AI review requested due to automatic review settings July 21, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class Amazon Bedrock support by introducing a dedicated bedrock.NewClient constructor that configures the existing OpenAI Go client to use Bedrock’s OpenAI-compatible API with SigV4 (or bearer token) authentication and AWS SDK v2 credential resolution.

Changes:

  • Introduces the bedrock package, including SigV4 signing (bedrock-mantle) and AWS credential/region/base-URL resolution with safety checks.
  • Adds an internal request-finalization hook (WithRequestFinalizer) plus a deterministic “no retry” error marker to support provider auth applied closest to the wire and to avoid retrying policy/setup failures.
  • Updates docs/examples and improves debug header redaction to include X-Amz-Security-Token.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
README.md Documents Bedrock usage, routing, auth modes, and links to a full example.
option/middleware.go Redacts x-amz-security-token in debug logging.
option/middleware_test.go Adds regression test ensuring AWS session tokens are redacted without mutating originals.
internal/requestconfig/requestconfig.go Adds request finalizers + deterministic no-retry errors; updates retry decision to consider deterministic errors.
internal/requestconfig/requestconfig_test.go Tests finalizer composition/order relative to other options.
client.go Allows provider-owned clients to skip inheriting ambient OPENAI_* environment defaults.
go.mod / go.sum Adds AWS SDK v2 dependencies for Bedrock support.
examples/go.mod / examples/go.sum Updates examples module deps for AWS SDK v2.
examples/bedrock/main.go Adds a runnable Responses API example targeting Bedrock.
bedrock/bedrock.go Defines Bedrock Config and NewClient constructor returning the standard OpenAI client.
bedrock/auth.go Implements auth selection, AWS config loading, SigV4/bearer middleware, redirect suppression, replayable-body enforcement, and safe error wrapping.
bedrock/auth_test.go Adds tests for credential/config resolution, signing fixtures, retries re-signing, middleware ordering, redirect suppression, and env isolation.
bedrock/auth_additional_test.go Adds additional tests for failure modes, safety checks, and helper behaviors.
bedrock/example_test.go Adds Go doc examples (currently problematic due to panics on missing env/config).
bedrock/testdata/sigv4.json Adds deterministic cross-SDK SigV4 signing fixture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bedrock/example_test.go
Comment thread bedrock/example_test.go
Comment thread bedrock/example_test.go
@HAYDEN-OAI
HAYDEN-OAI disabled auto-merge July 21, 2026 18:26
Copilot AI review requested due to automatic review settings July 21, 2026 18:40
jbeckwith-oai
jbeckwith-oai previously approved these changes Jul 21, 2026

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed c42880b. The four requested issues are addressed: bearer and SigV4 clients now share redirect protection, complete explicit AWS configuration no longer loads unrelated ambient config, SkipAuth supports the standard explicit gateway credential options, and deterministic provider-policy failures bypass retries while transient provider failures remain retryable. I also checked the self-contained executable examples. Full tests, repository lint/build, go vet, targeted race tests, and current GitHub checks are green. Approving.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 5 comments.

Comment thread bedrock/auth.go
Comment thread bedrock/auth.go
Comment thread bedrock/auth.go
Comment thread bedrock/auth.go
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 18:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 1 comment.

Comment thread README.md
Copilot AI review requested due to automatic review settings July 21, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 1 comment.

Comment thread internal/requestconfig/requestconfig.go
Copilot AI review requested due to automatic review settings July 21, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 1 comment.

Comment thread internal/requestconfig/requestconfig.go
Copilot AI review requested due to automatic review settings July 22, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 1 comment.

Comment thread bedrock/auth.go
jbeckwith-oai
jbeckwith-oai previously approved these changes Jul 22, 2026

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head (479c078) comprehensively. I found no substantive issues. I validated the Bedrock auth flows, request retry/body lifecycle changes, configuration isolation, error paths, generated/manual API boundaries, docs, and examples. Local checks passed: full go test ./... against an isolated Steady mock, targeted race tests, go vet ./..., ./scripts/lint, gofmt/diff cleanliness, and go mod tidy -diff plus tests across root/examples/consumer/tools. CI is green, including CodeQL, breaking-change detection, and govulncheck.

@HAYDEN-OAI
HAYDEN-OAI enabled auto-merge (squash) July 22, 2026 19:31
@HAYDEN-OAI
HAYDEN-OAI removed the request for review from jliccini July 22, 2026 19:31
Copilot AI review requested due to automatic review settings July 22, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 1 comment.

Comment thread bedrock/auth.go

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the exact merge head 04dce82. No substantive issues found. The Bedrock authentication, request-finalizer, retry, and request-body lifecycle implementation is byte-for-byte unchanged from the previously approved head. I inspected the merge resolution and full current PR diff: the dependency conflicts correctly preserve the AWS additions while incorporating main’s Azure/security updates, and generated/manual boundaries remain intact. Local checks passed: full go test ./... against an isolated Steady server, targeted race tests, go vet ./..., ./scripts/lint, examples and external-consumer tests, gofmt/diff cleanliness, and go mod tidy -diff across all four modules. Current CI, CodeQL, govulncheck, breaking-change detection, Go support policy, and OkTest 237/237 are green.

@HAYDEN-OAI
HAYDEN-OAI merged commit c31fc6b into main Jul 22, 2026
18 checks passed
@HAYDEN-OAI
HAYDEN-OAI deleted the dev/hayden/sdk-79-bedrock-aws-credentials branch July 22, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants