Skip to content

[open-swe] feat: Improve token usage tracking documentation with LLM and chat model approaches #8528

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 5 commits into
base: main
Choose a base branch
from

Conversation

open-swe[bot]
Copy link

@open-swe open-swe bot commented Jul 17, 2025

Fixes #8491

Overview

This PR enhances the token usage tracking documentation by:

  • Clarifying the difference between LLM and chat model token usage tracking
  • Providing clear guidance on accessing token usage for different model types
  • Adding new example files to demonstrate direct and callback-based approaches

Key Changes

  • Updated docs/core_docs/docs/how_to/llm_token_usage_tracking.mdx:

    • Added comprehensive explanation of LLM vs Chat model token usage
    • Restructured content to provide clear guidance
    • Added info box explaining token usage differences
  • Created new example file examples/src/models/llm/token_usage_tracking_direct.ts:

    • Demonstrates direct token usage tracking for LLMs
    • Shows how to access llmOutput.tokenUsage
  • Updated examples/src/models/llm/token_usage_tracking.ts:

    • Refocused as alternative callback-based approach
    • Added explanatory comments

Rationale

The documentation now provides clear, comprehensive guidance on token usage tracking for both LLMs and chat models, addressing potential confusion about different tracking methods.

Testing

  • Verified documentation accuracy
  • Confirmed example files run without errors
  • Ensured clear explanations of token usage approaches

Resolves the original request to improve token usage tracking documentation.

@open-swe open-swe bot added the open-swe label Jul 17, 2025
Copy link

vercel bot commented Jul 17, 2025

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

Name Status Preview Comments Updated (UTC)
langchainjs-docs 🛑 Canceled (Inspect) 💬 Add feedback Jul 17, 2025 5:44pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jul 17, 2025 5:44pm

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

Successfully merging this pull request may close these issues.

Update the how to track tokens doc to recommend usage_metadata
0 participants