Skip to content

Conversation

@maxious
Copy link

@maxious maxious commented Sep 27, 2025

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:

💖 Generated with Crush

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 <[email protected]>
@maxious maxious requested a review from a team as a code owner September 27, 2025 12:48
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 <[email protected]>
@andreynering
Copy link

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.

2 participants