John George
11/28/2024, 2:13 PMpython
import datetime as dt
# Anchor our processing to right now
process_until = dt.datetime.now()
# Process in batches, but only up to our anchored time
limit = 100 # Process 100 calls at a time
while True:
calls_batch = vapi_client.calls.list(
limit=limit,
created_at_lt=process_until # Don't process calls newer than when we started
)
if not calls_batch: # No more calls to process
break
for call in calls_batch:
cost_data = {
'call_id': call.get('id'),
'total': call.get('cost', 0),
'breakdown': call.get('costBreakdown', {})
}
# Process each call's cost data immediately
# instead of keeping everything in memory