Skip to content

Conversation

keremnalbant
Copy link
Contributor

Add mapping for cache_read_input_tokens and cache_creation_input_tokens for ChatVertexAI class.

Fixes #8319

Copy link

vercel bot commented Jun 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jun 11, 2025 11:00pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jun 11, 2025 11:00pm

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs labels Jun 6, 2025
@keremnalbant
Copy link
Contributor Author

A pretty quick win to monitor usage metadata for prompt caching.

cc @jacoblee93

output_tokens: usage?.output_tokens ?? 0,
total_tokens: (usage?.input_tokens ?? 0) + (usage?.output_tokens ?? 0),
cache_read_input_tokens: usage?.cache_read_input_tokens ?? 0,
cache_creation_input_tokens: usage?.cache_creation_input_tokens ?? 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the usageMetadata object should be changed to meet the definitions of UsageMetadata, which I think was added since this function was created.

As such, the cache_read and cache_creation values should be set in the usageMetadata.input_token_details object.

This would have the Vertex+Anthropic support use the same standard the rest of LangChainJS is using.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense tho, thanks for the heads up @afirstenberg! Updated the PR.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 9, 2025
@afirstenberg
Copy link
Contributor

#lgtm

@hntrl
Copy link
Member

hntrl commented Jun 12, 2025

@keremnalbant thank you!

@hntrl hntrl merged commit 211e57e into langchain-ai:main Jun 12, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ChatVertexAI] Anthropic models doesn't show prompt caching usage metadata

3 participants