Repository navigation
Conversation
…esolved
When AnthropicBedrock / AsyncAnthropicBedrock has no API key and boto3
cannot resolve any AWS credentials, get_auth_headers raised a bare
RuntimeError. That is not an anthropic.AnthropicError, so callers (and
frameworks wrapping the SDK, like pydantic-ai) cannot classify it as a
configuration problem without matching on the message string.
anthropic>=2 ships anthropic.CredentialsError for exactly this case
('credentials cannot be loaded from local files, config, or the
environment'); use it in the Bedrock path.
Closes anthropics#2038
This branch has not been deployed
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.
Closes #2038
When
AnthropicBedrock/AsyncAnthropicBedrockhas no API key and boto3 cannot resolve any AWS credentials,get_auth_headersraised a bareRuntimeError("could not resolve credentials from session"). That is not ananthropic.AnthropicError, so callers — and frameworks wrapping the SDK like pydantic-ai'sAnthropicModel— cannot classify it as a configuration problem without matching on the message string.anthropic>=2shipsanthropic.CredentialsError("credentials cannot be loaded from local files, config, or the environment"), which is exactly this case; use it in the Bedrock path.Change: one line in
src/anthropic/lib/bedrock/_auth.py—raise CredentialsError(...)instead ofraise RuntimeError(...), plus the import. Behavior for the resolvable-credentials path is unchanged.Test (
tests/lib/test_bedrock.py):test_missing_aws_credentials_raises_credentials_errorpatches_get_sessionto return a session with no credentials and asserts the raised error isanthropic.CredentialsErrorwith the same message.tests/lib/test_bedrock.py+tests/lib/test_aws_auth.py: 102 passed, 4 failed — the four failures aretest_region_infer_*profile/environment tests that also fail atmainwithout this change (verified on HEAD), unrelated to the credentials-error path.