Skip to content

Allow proper type on AnthropicProvider when using Bedrock #2490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

akoshel
Copy link

@akoshel akoshel commented Aug 9, 2025

Resolves:
#2215

Summary:
Upgrades AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.

Copy link
Contributor

hyperlint-ai bot commented Aug 9, 2025

PR Change Summary

Upgraded AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.

  • Upgraded AnthropicProvider to support AsyncAnthropic.
  • Upgraded AnthropicModel to support AsyncAnthropicBedrock.
  • Modified evaluation timing in documentation.

Modified Files

  • docs/evals.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

Comment on lines 54 to 58
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,
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to not complicate things here.

The user can just pass the client when using Bedrock.

except ImportError as _import_error: # pragma: no cover
raise ImportError(
'Please install the `anthropic` package to use the Anthropic provider, '
'you can use the `anthropic` optional group — `pip install "pydantic-ai-slim[anthropic]"`'
) from _import_error

from typing_extensions import TypeAlias
Copy link
Member

Choose a reason for hiding this comment

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

Please move this import up (before the try..except).


class AnthropicProvider(Provider[AsyncAnthropic]):
ASYNC_ANTHROPIC_CLIENT: TypeAlias = Union[AsyncAnthropic, AsyncAnthropicBedrock]
Copy link
Member

Choose a reason for hiding this comment

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

Is it really union what we want?

Suggested change
ASYNC_ANTHROPIC_CLIENT: TypeAlias = Union[AsyncAnthropic, AsyncAnthropicBedrock]
AsyncAnthropicClient = TypeVar("AsyncAnthropicClient", AsyncAnthropic, AsyncAnthropicBedrock)

Does this work?

Copy link
Member

Choose a reason for hiding this comment

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

Don't use full uppercase for type aliases, that's for constants. 🙏

Copy link
Author

Choose a reason for hiding this comment

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

microsoft/pyright#10777
I started with TypeVar but typecheckers don't allow this

@Kludex Kludex changed the title Issue 2215 Allow proper type on AnthropicProvider when using Bedrock Aug 11, 2025
@@ -153,7 +154,7 @@ def __init__(
model_name: The name of the Anthropic model to use. List of model names available
[here](https://docs.anthropic.com/en/docs/about-claude/models).
provider: The provider to use for the Anthropic API. Can be either the string 'anthropic' or an
instance of `Provider[AsyncAnthropic]`. If not provided, the other parameters will be used.
instance of `Provider[ASYNC_ANTHROPIC_CLIENT]`. If not provided, the other parameters will be used.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
instance of `Provider[ASYNC_ANTHROPIC_CLIENT]`. If not provided, the other parameters will be used.
instance of `Provider[AsyncAnthropicClient]`. If not provided, the other parameters will be used.

Comment on lines +63 to +67
aws_secret_key: AWS secret access key for Bedrock authentication.
aws_access_key: AWS access key ID for Bedrock authentication.
aws_region: AWS region for Bedrock service.
aws_profile: AWS profile name for Bedrock authentication.
aws_session_token: AWS session token for temporary credentials.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aws_secret_key: AWS secret access key for Bedrock authentication.
aws_access_key: AWS access key ID for Bedrock authentication.
aws_region: AWS region for Bedrock service.
aws_profile: AWS profile name for Bedrock authentication.
aws_session_token: AWS session token for temporary credentials.

@@ -35,7 +34,6 @@

test_infer_provider_params = [
('anthropic', AnthropicProvider, 'ANTHROPIC_API_KEY'),
('cohere', CohereProvider, 'CO_API_KEY'),
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this?

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