busy-lunch-15701
11/28/2025, 4:01 AMtall-airline-16756
11/28/2025, 4:01 AMtall-airline-16756
11/28/2025, 4:02 AMbusy-lunch-15701
11/28/2025, 4:03 AM@dataclass
class UsageSummary:
llm_prompt_tokens: int = 0
llm_prompt_cached_tokens: int = 0
llm_input_audio_tokens: int = 0
llm_input_cached_audio_tokens: int = 0
llm_input_text_tokens: int = 0
llm_input_cached_text_tokens: int = 0
llm_input_image_tokens: int = 0
llm_input_cached_image_tokens: int = 0
llm_completion_tokens: int = 0
llm_output_audio_tokens: int = 0
llm_output_image_tokens: int = 0
llm_output_text_tokens: int = 0
tts_characters_count: int = 0
tts_audio_duration: float = 0.0
stt_audio_duration: float = 0.0
this class in pythontall-airline-16756
11/28/2025, 4:04 AMUsageSummary dataclass and how to use them for cost calculations without double-counting.
• llm_prompt_tokens
Total text tokens sent as the LLM prompt. Use this for billing LLM input tokens.
• llm_prompt_cached_tokens
Portion of llm_prompt_tokens satisfied from cache. Subtract these from billed prompt tokens if your billing discounts cached usage.
• llm_input_audio_tokens
Tokens produced from audio inputs (e.g., STT → tokens). This is a modality-specific breakdown of input tokens.
• llm_input_cached_audio_tokens
Cached portion of llm_input_audio_tokens. Treat like other cached counts when computing billed audio-derived tokens.
• llm_input_text_tokens
Tokens from direct text inputs (modality-specific). This plus audio/image input tokens can sum to the prompt breakdown but are not additional to llm_prompt_tokens if that field is present.
• llm_input_cached_text_tokens
Cached portion of llm_input_text_tokens. Subtract if cache reduces billable tokens.
• llm_input_image_tokens
Tokens derived from image inputs (vision features). Modality-specific portion of input tokens.
• llm_input_cached_image_tokens
Cached portion of llm_input_image_tokens.
• llm_completion_tokens
Tokens produced by the LLM as its response (output). Use this for billing LLM output tokens.
• llm_output_audio_tokens
Portion of llm_completion_tokens that is rendered as audio (e.g., passed to TTS). This is a breakdown of completion tokens by output modality.
• llm_output_image_tokens
Portion of llm_completion_tokens that correspond to image output or descriptions.
• llm_output_text_tokens
Portion of llm_completion_tokens that are text output.
• tts_characters_count
Number of characters sent to the TTS service for synthesis. Use this for TTS character-based billing.
• tts_audio_duration
Total seconds of audio produced by TTS. Use this for any duration-based TTS billing or accounting.
• stt_audio_duration
Total seconds of audio processed by STT. Use this for STT/ASR billing measured in seconds.
Guidance to avoid double-counting
• For LLM billing, compute billed LLM tokens as:
◦ billed_prompt_tokens = llm_prompt_tokens - llm_prompt_cached_tokens (if cache reduces cost)
◦ billed_completion_tokens = llm_completion_tokens
◦ total_billed_llm_tokens = billed_prompt_tokens + billed_completion_tokens
Do NOT also add the modality-specific llm_input_*_tokens or llm_output_*_tokens to this total because those are breakdowns of the prompt/completion totals.
• If you do not have `llm_prompt_tokens`/`llm_completion_tokens` available and only have modality fields, sum the modality inputs for prompt and modality outputs for completion, subtract cached modality tokens where applicable.
• For TTS/STT billing, use tts_characters_count (characters) and tts_audio_duration (seconds) or stt_audio_duration (seconds) per your billing rules. Do not convert TTS characters back into LLM tokens and add them to LLM token totals — TTS is billed separately by characters/duration.
If you want, paste a real UsageSummary example and tell me which provider rates you’re using (LLM tokens rate, TTS characters rate, STT sec rate). I’ll compute a sample cost and show exactly where double-counting could happen.
Sources: Observability data hooks | LiveKit docs | Vision | LiveKit Docs | LiveKit Cloud billing | LiveKit docs