Skip to content

fix(genai): include audio usage token details#1864

Open
vismaytiwari wants to merge 1 commit into
langchain-ai:mainfrom
vismaytiwari:vismaytiwari/genai/audio-usage-metadata
Open

fix(genai): include audio usage token details#1864
vismaytiwari wants to merge 1 commit into
langchain-ai:mainfrom
vismaytiwari:vismaytiwari/genai/audio-usage-metadata

Conversation

@vismaytiwari

Copy link
Copy Markdown

Description

Fixes #1821.

This maps audio token counts from Google GenAI usage metadata into LangChain usage metadata. The response converter already reads aggregate token counts, but it ignored prompt_tokens_details and candidates_tokens_details, so TTS/audio responses lost their audio token breakdown.

Relevant issues

Fixes #1821

Type

🐛 Bug Fix

Changes(optional)

  • Add a small helper to sum token counts for a requested response modality.
  • Include AUDIO counts in input_token_details.audio and output_token_details.audio when present.
  • Add a regression test covering audio token details from a mocked GenerateContentResponse.

Testing(optional)

  • uv run pytest tests/unit_tests/test_chat_models.py::test_response_to_result_includes_audio_usage_metadata
  • uv run pytest tests/unit_tests/test_chat_models.py -k audio
  • make test from libs/genai
  • make lint from libs/genai

Note(optional)

I used Codex to help inspect the issue, implement the targeted change, and run the local validation commands. I reviewed the resulting diff before opening this PR.

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.

feat(genai): surface audio token counts in UsageMetadata for TTS models

1 participant