How to calculate token used from openAI while usin...
# ask-ai
p
How to calculate token used from openAI while using MultimodalAgent
t
Thanks for reaching out, Parth. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To calculate the tokens used while using OpenAI's MultimodalAgent, you can refer to the following metrics: • Input Tokens: The number of tokens in the prompt, tracked as
promptTokens
. • Output Tokens: Includes both audio and text tokens, tracked as
audioTokens
and
textTokens
respectively. • Total Tokens: The sum of all tokens used, tracked as
totalTokens
. Additionally, the
ModelUsage
interface provides a detailed breakdown of input and output tokens, including: • `input_tokens`: Total input tokens • `input_token_details`: Breakdown of input tokens (audio, text, cached) • `output_tokens`: Total output tokens • `output_token_details`: Breakdown of output tokens (audio, text) • `total_tokens`: Sum of all tokens used Performance metrics like
tokensPerSecond
and
ttft
(time to first token) are also tracked for further analysis. Sources: MultimodalLLMMetrics | LiveKit Agents | MultimodalLLMMetrics | LiveKit Agents | ModelUsage | LiveKit Agents
p
can you provide the code exmaple of above
t
Unfortunately, I couldn't locate a specific code example for calculating tokens used by OpenAI's MultimodalAgent. However, you can use the metrics provided by the
MultimodalLLMMetrics
and
ModelUsage
interfaces to track and calculate token usage programmatically. If you have access to the implementation, you can retrieve values like
promptTokens
,
audioTokens
,
textTokens
, and
totalTokens
from these interfaces. If you need further assistance or a detailed example, please let me know, and I can escalate this to a human specialist for more support.