Skip to content

Conversation

@Vidit-Ostwal
Copy link
Contributor

@Vidit-Ostwal Vidit-Ostwal commented Jan 4, 2026

Fixes #4170

Screenshot 2026-01-04 at 11 06 09

Note

Introduces consistent token usage accounting across sync/async and streaming/non-streaming LiteLLM paths, with callback logging and event emission.

  • In llm.py, extract usage from LiteLLM responses and stream chunks, call _track_token_usage_internal(usage_info), and invoke _handle_streaming_callbacks(...) in streaming flow; mirror usage tracking for _handle_non_streaming_response and _ahandle_non_streaming_response after completion calls
  • Async streaming handler _ahandle_streaming_response now captures usage_info, logs success callbacks, and updates internal counters before emitting completion events
  • Adds tests in tests/test_llm.py to validate _token_usage updates for call/acall in both streaming and non-streaming modes
  • Adds VCR cassettes for the new tests: test_usage_info_* (streaming and non-streaming, sync and async)

Written by Cursor Bugbot for commit 104075a. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Collaborator

@lorenzejay lorenzejay left a comment

Choose a reason for hiding this comment

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

Lovely ! Can you add a couple tests showing this with

llm.call
llm.acall?

Copy link
Collaborator

@lorenzejay lorenzejay left a comment

Choose a reason for hiding this comment

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

tested and LGTM

@lorenzejay lorenzejay merged commit 1c4f44a into crewAIInc:main Jan 7, 2026
42 of 74 checks passed
@Vidit-Ostwal Vidit-Ostwal deleted the vo/fix/add-usage-metrics branch January 8, 2026 14:35
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.

[BUG] get_token_usage_summary() Not being called while using litellm

2 participants