Session Analysis API Usage Guide
Understand the full cost and event tree for any Telnyx AI or voice session — from a single inference call to complex multi-product conversations.What is Session Analysis?
Session Analysis gives you a complete view of costs and events for any usage session on the Telnyx platform:- Full event tree — parent events, child events, and their relationships
- Rollup costs — per-event costs plus cumulative totals across the session
- Product linkages — how different Telnyx products interacted in a single session
When to Use It
Core Concepts
Record Types
A record type identifies the category of usage event for a Telnyx product. Each record type maps to a specific product and has defined relationships to other record types. Example:ai-voice-assistant is the record type for AI Voice Assistant sessions, which have inference events as children.
Sessions
A session is a tree of related usage events. The root event is the primary event you’re analyzing. Child events are related usage that occurred as part of that session. Example: An AI Voice Assistant call involves acall-session root with a call-control child, which in turn has an ai-voice-assistant child with inference events underneath — each representing one LLM turn in the conversation.
Relationships
Events are connected via relationships:
Relationships are defined via field mappings — the child’s
local_field matches the parent’s parent_field. For example, inference events link to their ai-voice-assistant parent via the conversation_id field.
Cost Rollup
Each event node includes:event_cost— Cost of this individual eventcumulative_cost— This event’s cost plus all descendant costs
cumulative_cost equals the total session cost. For AI sessions, this means the call-session cumulative cost includes everything — the AI assistant, each inference turn, STT, TTS, call control, and SIP trunking — rolled up into one number.
Endpoints
1. List All Record Types
record_types[]— Array of all record types with their parent/child relationshipsquery_parameters— Valid parameters for session analysis queriesmeta— Total count and last updated timestamp
2. Get Record Type Details
- Valid child and parent relationships
- Example query URLs
- Recommended max depth for traversal
3. Get Session Analysis
You can find event IDs in the individual webhooks or detail records for the applicable event.
Which record type should I use? If you’re analyzing a call made with your AI assistant, start with
call-session. This gives you the full picture — AI assistant sessions, inference events, call control, SIP trunking, and all other products in one tree. Use the metadata endpoint to explore other starting points for different products.
Query Parameters:
Example:
Response Structure
Top-Level Fields
Event Node Structure
Each event in the tree follows this structure:Relationship Object
For child events, therelationship field explains the connection:
Note: The
via fields vary by relationship. AI-related linkages often use conversation_id, while voice/telephony relationships typically use telnyx_session_id or call_session_id.
Example: AI Voice Assistant Session
A customer makes an inbound call to an AI Voice Assistant using the Telnyx Web Dialer. The assistant handles a multi-turn conversation over ~152 seconds. Query:
Key observations:
- The call-session root has $0.00 event cost — it’s a container for the session, not a billable event itself.
- ai-voice-assistant is the dominant cost at 0.06/min for 3 billed minutes). Its cumulative cost of $0.1921 includes 5 inference events underneath.
- Each inference event represents a single LLM call during the conversation — one per assistant turn. The cost per turn varies based on the model and token count.
- call-control has a 0.1973 cumulative cost — the difference is the ai-voice-assistant subtree rolling up underneath it.
- recording, webrtc, and sip-trunking are leaf nodes with no children, so their event cost equals their cumulative cost.
Understanding the AI Cost Structure
In an AI-powered call, costs come from multiple layers:
Session Analysis rolls all of these into one tree, so you can see exactly where cost accumulates — whether it’s the AI assistant minute rate, the number of inference turns, or the underlying voice transport.
Common Use Cases
Debugging High-Cost AI Sessions
- Query the session with
max_depth=5to get the full tree - Look at
meta.productsto see which products were involved - Compare
event_costacross children — ifai-voice-assistantis the driver, check how many inference turns occurred underneath - Check
recordfields for rate information (rate,rate_measured_in) and duration
Finding Related Events
- Start from any event in the tree
- Use
relationship.viato understand the field linkage - Query the parent or children directly using their
id
Exporting for Analysis
- Use
expand=noneto get just the tree structure without full records - Flatten the tree programmatically for spreadsheet import
- Or keep full records and parse specific fields (e.g.,
rate,duration_sec)
Best Practices
Performance
- Provide
date_timewhen you know it — this narrows the index search and improves response time - Use appropriate
max_depth— start with2, increase only if needed. AI sessions with inference events typically needmax_depth=4or5to reach the leaf level. - Use
expand=noneif you only need cost rollups, not full records
Querying
- Start from the root event — the most complete picture comes from the top-level event
- Check metadata first —
/metadata/{record_type}shows expected children and recommended depth - Use
links.recordsto get the underlying detail records for deeper analysis