feat(bedrock): support Amazon Bedrock API key (bearer token) authentication#2409
Open
Winne004 wants to merge 2 commits into
Open
feat(bedrock): support Amazon Bedrock API key (bearer token) authentication#2409Winne004 wants to merge 2 commits into
Winne004 wants to merge 2 commits into
Conversation
…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>
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.
Describe your changes
Adds support for Amazon Bedrock API keys (bearer tokens) in the Bedrock provider path of
from_provider.Previously,
_build_bedrockininstructor/v2/auto_client.pyacceptedapi_keybut silently ignored it (# noqa: ARG001), only wiring upaws_access_key_id/aws_secret_access_key/aws_session_token. Bedrock is the only major provider whereapi_keydoesn't work, which hurts ergonomics for people trying instructor with Bedrock:Implementation: when
api_keyis provided, it is exported asAWS_BEARER_TOKEN_BEDROCKbefore 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 noapi_keyis passed, behavior is unchanged — including picking up anAWS_BEARER_TOKEN_BEDROCKthe user already exported themselves.Changes:
instructor/v2/auto_client.py— honorapi_keyin_build_bedrockby exportingAWS_BEARER_TOKEN_BEDROCKtests/v2/test_auto_client_deterministic.py— two new deterministic tests:api_keysets the bearer-token env var; noapi_keyleaves it unsetdocs/integrations/bedrock.md— new "Bedrock API Key (Bearer Token) Authentication" section covering both theapi_keyparameter and the env var, with the boto3 version requirement and credential-precedence noteVerified locally:
pytest tests/v2→ 1498 passed, 182 skipped;ruff check/ruff formatclean.Issue ticket number and link
Closes #2408
Checklist before requesting a review
🤖 Generated with Claude Code