Skip to content

Handle None input_tokens from Anthropic SDK #1674

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

Closed

Conversation

timesler
Copy link
Contributor

@timesler timesler commented May 9, 2025

With version 0.51.0 of the Anthropic Python SDK, Anthropic models in Pydantic AI no longer work with streaming due to how we unpack the input_tokens field. Previously we assumed that getattr(response_usage, 'input_tokens', 0) would always be an int, which is no longer true

I have not added a test case for this, since the current tests already capture the bug and fail when the current version of Anthropic SDK is installed (a win for the awesome test coverage!!)

@timesler
Copy link
Contributor Author

timesler commented May 9, 2025

@DouweM FYI

@samuelcolvin
Copy link
Member

Thanks so much for this.

I didn't see this, until I was reviewing the original PR, this is replaced by #1686 which uprev's the version of anthropic we're using and adds tests.

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