strong-pizza-31661
08/02/2025, 3:25 PMtall-airline-16756
08/02/2025, 3:25 PMtall-airline-16756
08/02/2025, 3:25 PMUsageCollector class to track and summarize usage metrics, then apply the pricing rates from your API providers.
Steps to Calculate Costs:
1. Initialize the UsageCollector: Use the UsageCollector class to collect metrics across your API calls.
2. Attach the UsageCollector: Configure your agent session to use the collector for tracking metrics.
3. Retrieve Usage Summary: After processing API calls, get the usage summary to access metrics like prompt tokens, completion tokens, characters processed, and audio duration.
4. Apply Pricing Rates: Use your API provider's pricing rates to calculate costs based on the collected metrics. For example:
◦ GPT-4: Calculate costs using prompt and completion tokens.
◦ ElevenLabs: Calculate costs using the number of characters processed.
◦ Other APIs: Use their specific metrics (e.g., audio duration for STT).
1. Sum the Costs: Add up the individual costs to get the total API cost.
If you need detailed code examples or further assistance, let me know!