feat(bedrock): add bearer token authentication support#240
Open
maxious wants to merge 1 commit intoanthropics:mainfrom
Open
feat(bedrock): add bearer token authentication support#240maxious wants to merge 1 commit intoanthropics:mainfrom
maxious wants to merge 1 commit intoanthropics:mainfrom
Conversation
Adds `WithBearerToken(token, region)` function to enable API key-based authentication with AWS Bedrock as an alternative to AWS credential-based authentication. This streamlines Bedrock access in corporate environments where teams need to use Claude without managing AWS credentials, IAM roles, or account-level permissions. Bearer tokens can be provided directly or via the `AWS_BEARER_TOKEN_BEDROCK` environment variable. When a bearer token is present, the middleware bypasses AWS SigV4 signing and uses standard `Authorization: Bearer` headers instead. Includes comprehensive tests and example programs demonstrating both streaming and non-streaming usage with bearer tokens. References: - https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html - https://aws.amazon.com/blogs/machine-learning/accelerate-ai-development-with-amazon-bedrock-api-keys/ - aws/aws-sdk-go-v2#3159 💖 Generated with Crush Co-Authored-By: Crush <crush@charm.land>
maxious
added a commit
to maxious/crush
that referenced
this pull request
Sep 27, 2025
Adds support for authenticating with AWS Bedrock using bearer tokens via the AWS_BEARER_TOKEN_BEDROCK environment variable. This provides a simpler authentication method compared to full AWS credentials, particularly useful in corporate environments. Implementation: - Detects when AWS_BEARER_TOKEN_BEDROCK is set and passes it as API key - Bypasses the anthropic SDK's SigV4 middleware for bearer tokens - Sets Bedrock base URL directly and uses Authorization header - Falls back to SigV4 auth when AWS credentials are provided instead - Maintains full backwards compatibility with existing credential auth Changes: - Updated hasAWSCredentials() to check for AWS_BEARER_TOKEN_BEDROCK - Modified Bedrock provider config to pass bearer token with "Bearer " prefix - Enhanced anthropic client to skip bedrock middleware for bearer tokens - Added test coverage for bearer token authentication - Updated README with bearer token documentation and usage examples Bearer tokens are particularly useful in corporate environments where teams need access to Bedrock without managing AWS credentials, IAM roles, or account-level permissions. This streamlines AI development workflows by allowing API key-based access similar to other LLM providers. Note: This is a temporary workaround until the anthropic SDK adds native bearer token support. An upstream PR has been submitted to add this functionality: anthropics/anthropic-sdk-go#240 References: - aws/aws-sdk-go-v2#3159 - https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html - https://aws.amazon.com/blogs/machine-learning/accelerate-ai-development-with-amazon-bedrock-api-keys/ 💘 Generated with Crush Co-Authored-By: Crush <crush@charm.land>
2 tasks
|
I opened a similar PR: |
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.
Adds
WithBearerToken(token, region)function to enable API key-based authentication with AWS Bedrock as an alternative to AWS credential-based authentication. This streamlines Bedrock access in corporate environments where teams need to use Claude without managing AWS credentials, IAM roles, or account-level permissions.Bearer tokens can be provided directly or via the
AWS_BEARER_TOKEN_BEDROCKenvironment variable. When a bearer token is present, the middleware bypasses AWS SigV4 signing and uses standardAuthorization: Bearerheaders instead.Includes comprehensive tests and example programs demonstrating both streaming and non-streaming usage with bearer tokens.
References:
💖 Generated with Crush