Skip to content

feat(bedrock): support AWS_BEARER_TOKEN_BEDROCK env var - #1080

Closed
davidmhewitt wants to merge 4 commits into
anthropics:mainfrom
davidmhewitt:david/support-bedrock-bearer-auth
Closed

feat(bedrock): support AWS_BEARER_TOKEN_BEDROCK env var#1080
davidmhewitt wants to merge 4 commits into
anthropics:mainfrom
davidmhewitt:david/support-bedrock-bearer-auth

Conversation

@davidmhewitt

Copy link
Copy Markdown

Fixes #1079

Comment thread src/anthropic/lib/bedrock/_auth.py Outdated
Comment thread src/anthropic/lib/bedrock/_auth.py Outdated
profile: str | None,
data: str | None,
) -> dict[str, str]:
bedrock_bearer = os.getenv("AWS_BEARER_TOKEN_BEDROCK")

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.

I think adding api_key as a client argument and defaulting to that environment variable would be better than only supporting it through the environment variable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure, I've added it as the last argument to to the client constructor to preserve the existing ordering. Let me know if that makes sense, given the _strict_response_validation arg (and associated comment) above it.

Comment thread tests/lib/test_bedrock.py Outdated
Comment thread tests/lib/test_bedrock.py
Comment thread tests/lib/test_bedrock.py Outdated
@karpetrosyan

karpetrosyan commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

LGTM! Note that it also needs ruff format. Could you please run/commit it?

karpetrosyan
karpetrosyan previously approved these changes Dec 9, 2025
Comment thread src/anthropic/lib/bedrock/_client.py

@RobertCraigie RobertCraigie 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.

Do you know why the AWS naming around this functionality is inconsistent? i.e. why is the env var "bearer token" but the actual value is an "api key"?

@davidmhewitt

Copy link
Copy Markdown
Author

Do you know why the AWS naming around this functionality is inconsistent? i.e. why is the env var "bearer token" but the actual value is an "api key"?

Not sure!

I would guess they called it API key on the user-facing docs side to be consistent with other LLM providers that use that terminology. Then someone implementing the feature in the SDK decided to name the env var in the way that describes the way the token is transported 🤷‍♂️

I'd be happy to rename all the variables/params to one or the other here if it helps

@davidmhewitt
davidmhewitt force-pushed the david/support-bedrock-bearer-auth branch from 8c2088d to 1beed86 Compare December 15, 2025 06:09
@devstein

devstein commented Jan 3, 2026

Copy link
Copy Markdown

@davidmhewitt thank you for contributing this! I would love to see this merged.

@RiccardoRubini

Copy link
Copy Markdown

Thanks a lot @davidmhewitt. This is a very needed feature. Hope it will be merged soon

@fritz-astronomer

Copy link
Copy Markdown

Thanks! Would also love to see this merged.

@karpetrosyan

Copy link
Copy Markdown
Contributor

@RobertCraigie Friendly ping on this! We could also rename api_key to aws_bearer_token to match AWS naming, instead of adapting their naming to match ours

@maxa-adrian-blandin

maxa-adrian-blandin commented Apr 8, 2026

Copy link
Copy Markdown

Thanks! Could it be approved and merged? :)

EDIT: for anyone that might stumble on this PR, it's now supported.
See

def __init__(
self,
aws_secret_key: str | None = None,
aws_access_key: str | None = None,
aws_region: str | None = None,
aws_profile: str | None = None,
aws_session_token: str | None = None,
api_key: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
http_client: httpx.Client | None = None,
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
# if the API responds with invalid data for the expected schema.
#
# This parameter may be removed or changed in the future.
# If you rely on this feature, please open a GitHub issue
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
if api_key is None:
api_key = os.environ.get("AWS_BEARER_TOKEN_BEDROCK")

@localden

Copy link
Copy Markdown
Collaborator

Thank you for the PR - this was already addressed on main - see src/anthropic/lib/bedrock/_client.py:161. Closing as resolved.

@localden localden closed this Apr 28, 2026
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.

AnthropicBedrock: AWS_BEARER_TOKEN_BEDROCK env var not supported

9 participants