> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get session analysis

> Retrieves a full session analysis tree for a given event, including costs, child events, and product linkages.



## OpenAPI

````yaml https://telnyx-openapi-ng.s3.us-east-1.amazonaws.com/account-billing/session-analysis.yml get /session_analysis/{record_type}/{event_id}
openapi: 3.1.0
info:
  title: Telnyx Session Analysis API
  version: 2.0.0
  description: API for Session Analysis.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
security:
  - bearerAuth: []
paths:
  /session_analysis/{record_type}/{event_id}:
    get:
      tags:
        - Session Analysis
      summary: Get session analysis
      description: >-
        Retrieves a full session analysis tree for a given event, including
        costs, child events, and product linkages.
      operationId: GetSessionAnalysis
      parameters:
        - name: record_type
          in: path
          required: true
          description: The record type identifier.
          schema:
            type: string
        - name: event_id
          in: path
          required: true
          description: The event identifier (UUID).
          schema:
            type: string
            format: uuid
        - name: include_children
          in: query
          required: false
          description: Whether to include child events in the response.
          schema:
            type: boolean
            default: true
        - name: max_depth
          in: query
          required: false
          description: Maximum traversal depth for the event tree.
          schema:
            type: integer
            minimum: 1
            maximum: 5
            default: 2
        - name: expand
          in: query
          required: false
          description: Controls what data to expand on each event node.
          schema:
            type: string
            enum:
              - record
              - none
            default: record
        - name: date_time
          in: query
          required: false
          description: >-
            ISO 8601 timestamp or date to narrow index selection for faster
            lookups. Accepts full datetime (e.g., 2026-03-17T10:00:00Z) or
            date-only format (e.g., 2026-03-17).
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: Session analysis result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionAnalysisResponse'
              example:
                session_id: call-123
                cost:
                  total: '0.056800'
                  currency: USD
                root:
                  id: call-123
                  product: callcontrol-cdrs
                  event_name: callcontrol-cdrs
                  relationship: null
                  cost:
                    event_cost: '0.001800'
                    cumulative_cost: '0.056800'
                    currency: USD
                  links:
                    self: /v2/session_analysis/callcontrol-cdrs/call-123
                    records: >-
                      /v2/detail_records?record_type=callcontrol-cdrs&id=call-123
                  record: {}
                  children: []
                meta:
                  event_count: 3
                  products:
                    - ai-voice-assistant
                    - callcontrol-cdrs
                    - inference
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionAnalysisErrorResponse'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionAnalysisErrorResponse'
        '404':
          description: Event not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionAnalysisErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionAnalysisErrorResponse'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Telnyx from 'telnyx';

            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });

            const sessionAnalysis = await client.sessionAnalysis.retrieve(
              '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
              { record_type: 'record_type' },
            );

            console.log(sessionAnalysis.session_id);
        - lang: Python
          source: |-
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            session_analysis = client.session_analysis.retrieve(
                event_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                record_type="record_type",
            )
            print(session_analysis.session_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tsessionAnalysis, err := client.SessionAnalysis.Get(\n\t\tcontext.TODO(),\n\t\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\t\ttelnyx.SessionAnalysisGetParams{\n\t\t\tRecordType: \"record_type\",\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", sessionAnalysis.SessionID)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.sessionanalysis.SessionAnalysisRetrieveParams;

            import
            com.telnyx.sdk.models.sessionanalysis.SessionAnalysisRetrieveResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    SessionAnalysisRetrieveParams params = SessionAnalysisRetrieveParams.builder()
                        .recordType("record_type")
                        .eventId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
                        .build();
                    SessionAnalysisRetrieveResponse sessionAnalysis = client.sessionAnalysis().retrieve(params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            session_analysis =
            telnyx.session_analysis.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
            record_type: "record_type")


            puts(session_analysis)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $sessionAnalysis = $client->sessionAnalysis->retrieve(
                '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
                recordType: 'record_type',
                dateTime: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                expand: 'record',
                includeChildren: true,
                maxDepth: 1,
              );

              var_dump($sessionAnalysis);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx session-analysis retrieve \
              --api-key 'My API Key' \
              --record-type record_type \
              --event-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e
components:
  schemas:
    SessionAnalysisResponse:
      type: object
      required:
        - session_id
        - cost
        - root
        - meta
      properties:
        session_id:
          type: string
          description: Identifier for the analyzed session.
        cost:
          $ref: '#/components/schemas/CostSummary'
        root:
          $ref: '#/components/schemas/EventNode'
        meta:
          $ref: '#/components/schemas/ResponseMeta'
    SessionAnalysisErrorResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/SessionAnalysisError'
    CostSummary:
      type: object
      required:
        - total
        - currency
      properties:
        total:
          type: string
          description: Total session cost as a decimal string.
        currency:
          type: string
          description: ISO 4217 currency code.
    EventNode:
      type: object
      required:
        - id
        - product
        - event_name
        - cost
        - links
        - record
        - children
      properties:
        id:
          type: string
          description: Event identifier.
        product:
          type: string
          description: Product that generated this event.
        event_name:
          type: string
          description: Name of the event type.
        relationship:
          oneOf:
            - $ref: '#/components/schemas/RelationshipInfo'
            - type: 'null'
          description: Relationship to the parent node, null for root.
        cost:
          $ref: '#/components/schemas/CostInfo'
        links:
          $ref: '#/components/schemas/Links'
        record:
          type: object
          description: The underlying detail record data. Contents vary by record type.
          additionalProperties: true
        children:
          type: array
          items:
            $ref: '#/components/schemas/EventNode'
          description: Child events in the session tree.
    ResponseMeta:
      type: object
      required:
        - event_count
        - products
      properties:
        event_count:
          type: integer
          description: Total number of events in the session tree.
        products:
          type: array
          items:
            type: string
          description: List of distinct products involved in the session.
    SessionAnalysisError:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        detail:
          type: string
    RelationshipInfo:
      type: object
      required:
        - type
        - via
        - parent_id
      properties:
        type:
          type: string
          description: Relationship type identifier.
        via:
          $ref: '#/components/schemas/FieldMapping'
        parent_id:
          type: string
          description: Identifier of the parent event.
    CostInfo:
      type: object
      required:
        - event_cost
        - cumulative_cost
        - currency
      properties:
        event_cost:
          type: string
          description: Cost of this individual event.
        cumulative_cost:
          type: string
          description: Cumulative cost including all descendants.
        currency:
          type: string
          description: ISO 4217 currency code.
    Links:
      type: object
      required:
        - self
        - records
      properties:
        self:
          type: string
          description: Link to this session analysis node.
        records:
          type: string
          description: Link to the underlying detail records.
    FieldMapping:
      type: object
      required:
        - local_field
        - parent_field
      properties:
        local_field:
          type: string
          description: Field name on the child record.
        parent_field:
          type: string
          description: Field name on the parent record.
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````