feat: expose raw usage metadata in LLMTokenUsage for Gemini Live and OpenAI Realtime#44
Open
nihal0514 wants to merge 1 commit into
Open
feat: expose raw usage metadata in LLMTokenUsage for Gemini Live and OpenAI Realtime#44nihal0514 wants to merge 1 commit into
nihal0514 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request extends the core metrics layer to capture and pass through the rich multimodal usage metadata from both the Gemini Live and OpenAI Realtime speech-to-speech services.
Why is this needed?
Currently, the standard
LLMTokenUsagemetrics schema captures basic token fields (prompt, completion, cache_read, etc.) but strips away key modality breakdowns (such as audio-input, audio-output, tool-use, images, and videos). To perform accurate, granular multimodal cost-tracking and telemetry (e.g. via cost aggregators), we need access to the rich raw metadata structure returned by these providers.Changes Made
src/pipecat/metrics/metrics.py: Added an optionalraw_usage_metadatadictionary field to theLLMTokenUsageschema.src/pipecat/services/google/gemini_live/llm.py: Captured the completeusage_metadataobject from the Gemini Live response (including modal details like TEXT, AUDIO, IMAGE, VIDEO, tools, and cache) and attached it underraw_usage_metadata.src/pipecat/services/openai/realtime/llm.py: Captured and attached the fullusageresponse payload from the OpenAI Realtime event.