i want to calculate the cost of calls and show it ...
# ask-ai
c
i want to calculate the cost of calls and show it to end user, how to calculate it? is there a ready api or something to get cost?
✅ 1
t
Thanks for reaching out, Abbass. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about calculating call costs and whether there’s a ready API to get cost data. Short answer • There isn’t a dedicated API that returns call costs. • You can calculate costs yourself using call duration (start/end timestamps) plus the per-minute rates for the relevant call type (US local, toll-free, SIP, etc.), and factoring in any included minutes on your plan. How to implement this (practical steps) 1. Determine call type for each call ◦ Examples: US local inbound, US toll-free inbound, third‑party SIP (inbound/outbound). Different call types use different per‑minute rates. 1. Capture accurate duration ◦ Use call start and end timestamps (or agent session/connection minutes) to compute duration in minutes. Round/ceiling per your billing rules (e.g., charge by whole minutes or fractional minutes). 1. Apply pricing rules ◦ Multiply billable minutes by the appropriate per‑minute rate: ▪︎ US local inbound minutes: $0.01/min after included allotment ▪︎ US toll-free inbound minutes: $0.02/min ▪︎ Third‑party SIP minutes: $0.004/min (volume tiers apply) ◦ Subtract included minutes for the account/plan before applying overage rates (e.g., if plan includes N minutes). 1. Add any other fees if applicable ◦ If you have additional platform or session fees (agent session minutes shown separately), include those per your billing model. 1. Display to the end user ◦ Show a running estimate during the call (recompute each minute) or a final cost after call ends. Make clear whether shown numbers are estimates vs final billed amounts. Example formula (simple) • billable_minutes = max(0, ceil(duration_minutes) - included_minutes_remaining) • cost = billable_minutes × per_minute_rate Notes and limitations • There is no built‑in LiveKit API that returns "call cost" or real‑time cost estimates; cost must be computed externally using usage metrics and pricing rates. • Included minutes and plan-specific rules affect final cost — make sure you fetch the account’s included allotment and current used minutes from your account/billing data before computing overages. • Volume tiers (for SIP minutes) may change the per‑minute rate once usage crosses thresholds — handle tiered pricing if that applies to your account. If you want, I can help with next steps: • Outline exact inputs you’ll need from your system (call events, billing plan, minutes used). • Provide a snippet of code (language of your choice) that calculates running and final costs. • Design UI wording and how to present “estimate” vs “final bill.” Which of those would be most helpful right now? Sources: Pricing | LiveKit | Pricing | LiveKit | Agents telephony integration | LiveKit Documentation | Outbound Calling Script | LiveKit Documentation | Understanding and Estimating Pricing for Video Conference and Livestream Us..., with interactive elements