Hello everyone, is there anyway to get a detailed ...
# agents
a
Hello everyone, is there anyway to get a detailed summary for my usage like this
Copy code
{
  "total_tokens": 275,
  "input_tokens": 127,
  "output_tokens": 148,
  "input_token_details": {
    "cached_tokens": 384,
    "text_tokens": 119,
    "audio_tokens": 8,
    "cached_tokens_details": {
      "text_tokens": 128,
      "audio_tokens": 256
    }
  },
  "output_token_details": {
    "text_tokens": 36,
    "audio_tokens": 112
  }
}
the
get_summary
function return a brief summary i want detailed to help me calculate the cost for every session, any ideas? thanks in advance
b
You need to run a function that uses the usage summary when the session ends (possibly
on_shutdown
hook). For LLM costs, you can write something like this:
Copy code
cached_input_tokens = usage_summary.llm_prompt_cached_tokens
regular_input_tokens = usage_summary.llm_prompt_tokens - cached_input_tokens

regular_input_cost = regular_input_tokens * LLM_INPUT_PRICE
cached_input_cost = cached_input_tokens * LLM_CACHED_INPUT_PRICE
output_cost = usage_summary.llm_completion_tokens * LLM_OUTPUT_PRICE

llm_cost = regular_input_cost + cached_input_cost + output_cost
You can do the same for SST and TTS, depending on your provider's pricing.
a
I'm using gpt-realtime so it has different price for text and audio input and output, that's why i want a detailed summary.
c
The on metrics collected event handler will return all the relevant details I've opened a PR to add these token counts to Opentelemetry so a platform like Langfuse will show the costs of each call and session automatically, if that's approved