feat(aws): add explicit auth_mode option to Bedrock and AWS clients - #1902
Open
lx3133584 wants to merge 1 commit into
Open
feat(aws): add explicit auth_mode option to Bedrock and AWS clients#1902lx3133584 wants to merge 1 commit into
lx3133584 wants to merge 1 commit into
Conversation
Fixes anthropics#1893 Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The new auth_mode argument on AnthropicAWS.copy() / AsyncAnthropicAWS.copy() is currently never forwarded. It is absent from _extra_kwargs, so copy(auth_mode="sigv4") has no effect and even a plain copy() of a client created with an explicit mode falls back to the constructor default "auto". Could this use the same preserve-or-override pattern already implemented for the Mantle clients?
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.
Problem
When initializing
AnthropicBedrockMantleorAnthropicAWS, presence of ambient bearer-token environment variables (AWS_BEARER_TOKEN_BEDROCKorANTHROPIC_AWS_API_KEY) implicitly forces bearer token authentication unless static credentials are provided, preventing downstream integrations from using the default AWS credential chain with SigV4.Root Cause
resolve_auth_modeimplicitly selects API key mode whenever bearer-token env vars are set and no explicit credentials or profile arguments are passed in the constructor. There was no public parameter to explicitly select or forcesigv4orapi_keymode.Fix
auth_mode: Literal["auto", "api_key", "sigv4"]parameter toAnthropicBedrockMantle,AsyncAnthropicBedrockMantle,AnthropicAWS, andAsyncAnthropicAWS.auth_modethrough_resolve_mantle_configandresolve_auth_mode, allowing"sigv4"to bypass ambient bearer key variables and"api_key"to force bearer mode.auth_modeis preserved across clientcopy()/with_options()invocations.Testing
Added unit tests in
tests/lib/test_aws_auth.pyandtests/lib/test_bedrock_mantle.pycovering explicit auth modes and copy behavior, verified with pytest and pyright.