Skip to content

feat(bedrock): support Amazon Bedrock API key (bearer token) authentication#2409

Open
Winne004 wants to merge 2 commits into
567-labs:mainfrom
Winne004:feature/bedrock-api-key-auth
Open

feat(bedrock): support Amazon Bedrock API key (bearer token) authentication#2409
Winne004 wants to merge 2 commits into
567-labs:mainfrom
Winne004:feature/bedrock-api-key-auth

Conversation

@Winne004

@Winne004 Winne004 commented Jul 4, 2026

Copy link
Copy Markdown

Describe your changes

Adds support for Amazon Bedrock API keys (bearer tokens) in the Bedrock provider path of from_provider.

Previously, _build_bedrock in instructor/v2/auto_client.py accepted api_key but silently ignored it (# noqa: ARG001), only wiring up aws_access_key_id / aws_secret_access_key / aws_session_token. Bedrock is the only major provider where api_key doesn't work, which hurts ergonomics for people trying instructor with Bedrock:

client = instructor.from_provider(
    "bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
    api_key="your-bedrock-api-key",  # was silently ignored — now works
)

Implementation: when api_key is provided, it is exported as AWS_BEARER_TOKEN_BEDROCK before the boto3 client is created. This is the mechanism botocore (>= 1.39.0) natively supports for Bedrock bearer-token auth, and it's how other libraries in the ecosystem (e.g. langchain-aws) enable it. When no api_key is passed, behavior is unchanged — including picking up an AWS_BEARER_TOKEN_BEDROCK the user already exported themselves.

Changes:

  • instructor/v2/auto_client.py — honor api_key in _build_bedrock by exporting AWS_BEARER_TOKEN_BEDROCK
  • tests/v2/test_auto_client_deterministic.py — two new deterministic tests: api_key sets the bearer-token env var; no api_key leaves it unset
  • docs/integrations/bedrock.md — new "Bedrock API Key (Bearer Token) Authentication" section covering both the api_key parameter and the env var, with the boto3 version requirement and credential-precedence note

Verified locally: pytest tests/v2 → 1498 passed, 182 skipped; ruff check / ruff format clean.

Issue ticket number and link

Closes #2408

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • If it is a core feature, I have added documentation.

🤖 Generated with Claude Code

Winne004 and others added 2 commits July 4, 2026 07:02
…cation

Honor the api_key argument in from_provider("bedrock/...") by exporting
AWS_BEARER_TOKEN_BEDROCK, which botocore (>=1.39.0) reads to authenticate
Bedrock requests with a bearer token instead of SigV4 credentials.
Previously the argument was silently ignored.

Closes 567-labs#2408

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

feat(bedrock): support Amazon Bedrock API key (bearer token) authentication

1 participant