Skip to content
MeridFlow AiFlow v8.x • self-hosted

Analytics

Aggregate volume, sentiment, and funnel trends across one agent or every agent, and across every channel, a phone call, a widget chat, an inbound email, or a silent background task. This is what backs the admin dashboard's Analytics page. Every call is also classified individually (see "Sentiment and outcome" below); this endpoint aggregates that per-call data rather than drawing from a separate data source.

Endpoint

GET /api/v1/analytics/overview

Authentication and roles

Takes an admin session token (see Authentication). Any role can call it, including Viewer, the same read-only observability bar as the Calls log itself.

Query parameters

Parameter Type Description
agent_id integer Scope to one agent. Omit for every agent combined.
channel string Scope to one channel: phone, web, email, or agent_task. Omit for every channel combined. Only scopes total_calls/completed_calls/abandoned_calls/avg_duration_seconds/sentiment/funnel/volume_by_day/top_agents, never volume_by_channel itself (see below).
start_date date (YYYY-MM-DD) Inclusive lower bound on Call.created_at.
end_date date (YYYY-MM-DD) Inclusive upper bound on Call.created_at.
curl "https://api.your-domain.com/api/v1/analytics/overview?agent_id=1&start_date=2026-01-01" \
  -H "Authorization: Bearer $ADMIN_TOKEN"
import httpx

response = httpx.get(
    "https://api.your-domain.com/api/v1/analytics/overview",
    params={"agent_id": 1, "start_date": "2026-01-01"},
    headers={"Authorization": f"Bearer {admin_token}"},
)
response.raise_for_status()
overview = response.json()
{
  "total_calls": 128,
  "completed_calls": 96,
  "abandoned_calls": 22,
  "avg_duration_seconds": 143.5,
  "sentiment": { "positive": 61, "neutral": 30, "negative": 12, "unclassified": 25 },
  "funnel": { "queued": 128, "ringing": 4, "answered": 106, "completed": 96 },
  "volume_by_day": [
    { "date": "2026-01-01", "count": 12 },
    { "date": "2026-01-02", "count": 18 }
  ],
  "top_agents": [
    { "agent_id": 1, "agent_name": "Support Bot", "call_count": 128 }
  ],
  "volume_by_channel": [
    { "channel": "phone", "count": 90 },
    { "channel": "web", "count": 30 },
    { "channel": "email", "count": 6 },
    { "channel": "agent_task", "count": 2 }
  ]
}

Fields

Field Type Description
total_calls integer Every call matching the filters (despite the name, this counts every channel, not just phone).
completed_calls integer status == completed.
abandoned_calls integer status in no_answer, failed, or busy.
avg_duration_seconds number or null Average of duration_seconds across calls that have one; null if none do.
sentiment object Counts by classified sentiment, plus unclassified for calls with no sentiment set yet.
funnel object queued (pending), ringing, answered (in_progress/completed/transferred), completed. Always scoped to the phone channel alone, regardless of the channel filter, the same way volume_by_channel always ignores it: queued/ringing are phone-only realities, a chat or email session never rings.
volume_by_day array One entry per day with at least one call, ascending by date.
top_agents array Up to 10 agents by call count, descending. Trivially one entry when agent_id is set.
volume_by_channel array Every channel always present, phone/web/email/agent_task, zero-filled rather than omitted. Reflects agent_id/start_date/end_date but never the channel filter itself, so a filtered view still reads in context of the whole.

Sentiment and outcome

Every call is classified individually by a one-shot Gemini pass over its transcript at finalize time, following the same "never block on failure" pattern that warm transfer and every other call-finalize side effect follows. This produces sentiment (positive, neutral, or negative) and a short free-text outcome_tag (for example "resolved" or "booked appointment"), both returned on the Call resource itself. A call too short to have a transcript worth judging simply stays unclassified.

The same pass also decides whether someone on the team should look at the conversation, setting needs_attention and a one-line attention_reason: an unresolved problem, a complaint, a promise the agent could not keep, a request for a person, or a safety or legal concern. A failed conversation, or one where the person was unhappy, always counts, whatever the model judged. The pass reads the agent's tool calls and what they returned, as well as what was said, so an answer the agent fetched with a tool is judged as an answer. Flagged conversations carry a needs attention badge in the Calls and Chats lists.

Review emails

Set CONVERSATION_REVIEW_EMAIL and nobody has to open the dashboard to find a conversation that went wrong. When a phone call, a website chat or voice session, or an inbound-email exchange finishes, AiFlow emails that address a short note: the agent, who it was with, the channel, status, sentiment, outcome, why it needs attention, a two to three sentence summary, and, when ADMIN_DASHBOARD_URL is set, a link straight to the conversation. With CONVERSATION_REVIEW_MODE=attention (the default) only flagged conversations are sent; all sends every one. Headless agent_task runs have nobody on the other side and are never sent.

Each conversation is emailed at most once, recorded as review_emailed_at on the call. The email carries the summary, never the transcript, and is sent through the deployment's own Resend account (RESEND_API_KEY), so no new service sees the conversation. A failed send is logged and leaves review_emailed_at empty, and never affects the call itself.

Cost and outcomes

GET /api/v1/analytics/costs?agent_id=&start_date=&end_date=
GET /api/v1/analytics/costs.csv?agent_id=&start_date=&end_date=
GET /api/v1/analytics/cost-settings
PUT /api/v1/analytics/cost-settings

Each conversation records the Gemini tokens it used, by direction and modality, and the price Twilio charged once it priced the call. Costs are those figures times the unit prices saved in cost settings: AiFlow ships no vendor price list, so with none saved every cost is 0 and prices_configured is false. The period defaults to the last 30 days.

costs returns:

  • conversations, ai_resolved, human_handled, needs_attention, failed: counted over phone, web and email conversations. A conversation is AI-resolved when it completed and was not flagged, and human-handled when it was transferred.
  • gemini_cost, twilio_cost, total_cost, cost_per_resolved.
  • human_equivalent_cost, savings, and savings_method, which spells out the calculation.
  • ownership_cost: months_12, months_24 and months_36, from the licence, setup and monthly hosting costs plus the period's running cost projected per month.

costs.csv has one row per conversation with its token usage and cost. cost-settings holds currency, five Gemini prices per million tokens (input_text, input_audio, input_media for images and video, output_text, output_audio), human_cost_per_conversation, licence_cost, setup_cost and hosting_cost_per_month. Saving them needs the Admin role and is written to the audit log.

Next

  • Calls: the per-call record sentiment and outcome_tag live on.
  • Live architecture: what is happening right now, rather than how a date range went.