Voice AI

Build a CDR Usage Analytics Dashboard with Telnyx AI Inference

Call Detail Records are one of those data sources that quietly explain a lot about a communications product.

They can tell you when traffic spikes, where calls are going, how much usage costs, which routes are busiest, and where something might be going sideways. The hard part is that raw CDRs are usually not how developers, support teams, or operations teams want to consume that information.

This example turns Telnyx CDR data into a small Python analytics API with summary metrics, daily trends, route breakdowns, peak-hour analysis, and AI-generated recommendations.

Code:

What the example builds

The project is a Flask app that exposes a few dashboard-friendly endpoints:

  • GET /cdrs fetches Call Detail Records for a date range
  • GET /analytics/summary returns total calls, duration stats, cost stats, and grouped counts
  • GET /analytics/peak-hours groups call volume by hour
  • GET /analytics/top-routes shows the busiest routes
  • GET /analytics/daily returns daily call and cost totals
  • GET /analytics/ai-insights sends a compact usage summary to Telnyx AI Inference for recommendations
  • GET /health gives a basic service health check

The important design choice is that the app separates deterministic analytics from AI interpretation.

Python calculates the metrics that should be exact: total calls, average duration, median duration, p95 duration, total cost, status counts, and route counts. Telnyx AI Inference is used after that to explain the pattern in plain language and suggest what to look at next.

Why this pattern is useful

Most teams already have communications data. What they often do not have is a fast path from raw records to an operational view.

For example, a usage dashboard can help answer questions like:

  • Did call volume spike this week?
  • Are short calls increasing?
  • Which routes are driving the most cost?
  • Are failed, busy, or incomplete calls clustering in a specific time window?
  • What should an ops person investigate first?

The example does not try to replace your billing system or BI stack. It gives you a small, readable starting point for an app that can sit between Telnyx APIs and the workflows your team actually uses.

Where AI fits

The AI endpoint does not send every raw call record into the model. Instead, the app builds a short summary:

  • number of calls
  • total cost
  • average duration
  • count and percentage of very short calls

That summary is sent to Telnyx AI Inference through the chat completions API. The model is asked to respond like a telecom analyst and return a few actionable observations about cost optimization and possible issues.

That keeps the AI layer focused. The model is not responsible for calculating the metrics. It is responsible for turning already-computed metrics into a useful explanation.

Running the example

Clone the examples repo and move into the project:

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/cdr-usage-analytics-dashboard-python

Create your environment file:

cp .env.example .env

Add your Telnyx API key:

TELNYX_API_KEY=your_telnyx_api_key
AI_MODEL=moonshotai/Kimi-K2.6
HOST=127.0.0.1

Install dependencies and start the app:

pip install -r requirements.txt
python app.py

Then test the health route:

curl http://localhost:5000/health

Try the summary endpoint:

curl "http://localhost:5000/analytics/summary?start_date=2026-07-01&end_date=2026-07-08" | python3 -m json.tool

And ask for AI insights:

curl http://localhost:5000/analytics/ai-insights | python3 -m json.tool

Extending it

A production version of this pattern could add:

  • a frontend dashboard
  • scheduled ingestion
  • a database for historical metrics
  • authentication for internal users
  • alerting when cost or failed-call ratios cross a threshold
  • customer, tenant, or campaign-level filtering
  • a weekly AI-generated usage report

The core idea stays the same: use code for exact metrics, then use the model for explanation, summarization, and next-step guidance.

Frequently Asked Questions

What does this tutorial cover?
Call Detail Records are one of those data sources that quietly explain a lot about a communications product.
What is what the example builds?
The project is a Flask app that exposes a few dashboard-friendly endpoints:
What is why this pattern is useful?
Most teams already have communications data. What they often do not have is a fast path from raw records to an operational view.
What is where ai fits?
The AI endpoint does not send every raw call record into the model. Instead, the app builds a short summary:
What is running the example?
Clone the examples repo and move into the project:

Resources

  • Code:
  • Telnyx AI skills and toolkits:
  • Telnyx AI Inference docs:
  • Chat Completions API:
  • Telnyx Portal:

Ready to build with low-latency voice AI?

Join developers building the future of real-time conversations