Skip to content

Conversation

a-i-joe
Copy link

@a-i-joe a-i-joe commented Jun 21, 2025

  • Updates the core interface for TokenUsage with new optional fields to contain details such as cached tokens and reasoning tokens.

  • Updates the OpenAI mapping into TokenUsage to take advantage of the new details fields.

Fixes #8405

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 21, 2025
Copy link

vercel bot commented Jun 21, 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 21, 2025 3:43am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jun 21, 2025 3:43am

@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Jun 21, 2025
@christian-bromann
Copy link
Member

Thanks @a-i-joe for the contribution 🙏 I will take this to the team and discuss if this is something we would be interested adding. Let me get back on this soon.

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

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

Hey @a-i-joe! Two things regarding this PR:

  • The TokenUsage object that you're targeting here is for legacy Generation objects that we don't surface to the user unless you're using deprecated methods like generatePrompt or call. If you want to surface these tokens from ChatOpenAI.invoke, the thing we'd want to update is the usage metadata. (we're looking to nix the Generation object in an effort to make things more clear)
  • I don't think we want to supply openai only properties on token count objects, since the implication is that we can provide it across all providers. We are working on some enhancements to message objects that will let you specify arbitrary properties per provider, so I can give you an update

I've converted the discussion post into an issue (#8906) since I do think it would be a good thing to add, but we'll likely target this in v1 off the back of the messages changes I mentioned. In the mean time, I'm going to close this PR.

@hntrl hntrl closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants