Skip to content

Store additional usage details from Anthropic #1549

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

Merged

Conversation

timesler
Copy link
Contributor

@timesler timesler commented Apr 19, 2025

This change handles the two additional usage fields returned by Anthropic: cache_creation_input_tokens and cache_read_input_tokens. When prompt caching is not enabled, this change has no impact.

Currently, the providers/models system is very flexible, which has made it easy to enable Anthropic's prompt caching by providing a custom client or provider, but this part of the code _map_usage is not nicely overridable, so updating it to handle the full usage object properly.

This, or a similar, change, will be need to support prompt caching natively too, once someone gets to that.

@timesler timesler requested a review from DouweM April 26, 2025 08:10
@timesler timesler requested a review from DouweM April 29, 2025 17:07
@timesler
Copy link
Contributor Author

@DouweM it looks like the p39 test suite failed due to something unrelated to this PR (a network error when downloading a dependency). I'm not sure if it's just flakiness, but perhaps someone with the access could rerun the build?

@timesler timesler requested a review from DouweM April 30, 2025 18:07
@DouweM DouweM marked this pull request as draft April 30, 2025 19:34
@timesler timesler marked this pull request as ready for review May 1, 2025 00:23
@DouweM DouweM changed the title Handle additional usage details in Anthropic responses Store additional usage details from Anthropic May 1, 2025
@DouweM DouweM merged commit dcfa821 into pydantic:main May 1, 2025
18 checks passed
@DouweM
Copy link
Contributor

DouweM commented May 1, 2025

@timesler Thanks a ton Tim!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants