Analytics

The numbers behind the **Analytics** page: overview, trends, sessions with their transcripts, phone number stats and a CSV export. Requires `analytics:read`.

Get headline numbers
GET /analytics/overview
List conversations
GET /analytics/sessions
Get a conversation
GET /analytics/sessions/{id}
Get a conversation's transcript
GET /analytics/sessions/{id}/transcript
Get daily trends
GET /analytics/trends
Export conversations as CSV
GET /analytics/export
Get call counts per phone number
GET /analytics/phone-stats

The Analytic object

Returned by the analytics endpoints.

Attributes
totalSessionsinteger
Conversations in the period, all channels.
successRatenumber
Share of conversations with status `success`, as a percentage from 0 to 100. 0 when there were none.
workflowsCompletedinteger
Conversations that finished the playbook the agent was following.
totalCostnumber
Total cost in US dollars.
avgCostPerSessionnumber
`totalCost` divided by `totalSessions`, in US dollars. 0 when there were none.
avgLatencynumber · nullable
Average voice response time in milliseconds, weighted by conversations. `null` when no conversation recorded one.
voiceCountinteger
Phone calls.
whatsappCountinteger
WhatsApp conversations.
successCountinteger
Conversations the agent handled to the end.
handoffCountinteger
Conversations handed to a person.
dropOffCountinteger
Conversations where the customer left before finishing.
periodstring
The `period` you asked for, echoed back as sent (an unknown value is echoed too, though the week window was used).
startDatestring
Start of the window, in UTC.
endDatestring
End of the window (the time of the request), in UTC.
The Analytic object
{
  "totalSessions": 412,
  "successRate": 81.3,
  "workflowsCompleted": 156,
  "totalCost": 14.82,
  "avgCostPerSession": 0.036,
  "avgLatency": 640.5,
  "voiceCount": 289,
  "whatsappCount": 123,
  "successCount": 335,
  "handoffCount": 41,
  "dropOffCount": 36,
  "period": "week",
  "startDate": "2026-09-29T08:15:02.481Z",
  "endDate": "2026-10-06T08:15:02.481Z"
}

Get headline numbers

GET https://api.trycareflow.com/analytics/overview

Requires `analytics:read`. Returns conversation counts, outcomes, cost and response time for a recent period. Periods are rolling: `week` is the 7 days before now, `month` the month before now, `quarter` the 90 days before now, and `today` runs from 00:00 UTC. For the whole workspace, `week`, `month` and `quarter` come from daily totals that are added up just after midnight UTC, so they leave out today, and the oldest day only counts if it falls entirely inside the window. With `assistantId`, or with `today`, the numbers are counted live from the conversations themselves. For a fixed calendar day, use the session list or the export with `startDate` and `endDate` instead.

Query parameters
periodenumoptional
Which window to cover. Any other value falls back to `week`.todayweekmonthquarter
assistantIdstringoptional
Only count conversations handled by this agent. Leave it out for the whole workspace. A value that isn't a valid ID is rejected with 400 rather than ignored.
curl https://api.trycareflow.com/analytics/overview \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "totalSessions": 412,
    "successRate": 81.31,
    "workflowsCompleted": 156,
    "totalCost": 14.82,
    "avgCostPerSession": 0.036,
    "avgLatency": 640.5,
    "voiceCount": 289,
    "whatsappCount": 123,
    "successCount": 335,
    "handoffCount": 41,
    "dropOffCount": 36,
    "period": "week",
    "startDate": "2026-09-29T08:15:02.481Z",
    "endDate": "2026-10-06T08:15:02.481Z"
  }
}
{
  "code": "ERROR",
  "message": "invalid assistantId",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to get sessions",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

List conversations

GET https://api.trycareflow.com/analytics/sessions

Requires `analytics:read`. Returns one page of conversations, newest first, with every stored field including the full transcript. Filter by day range, outcome, channel and agent, and page through with `page` and `limit` until `page` reaches `pages`. Days are UTC. A date in the wrong format, or an unknown `status` or `channel`, doesn't cause an error: a bad date is ignored and an unknown value matches nothing. When nothing matches, `sessions` is `null` rather than an empty list.

Query parameters
startDatestringoptional
First day to include, as `YYYY-MM-DD` in UTC, counted from 00:00. A value in any other format is ignored silently, so the filter is dropped.
endDatestringoptional
Last day to include, as `YYYY-MM-DD` in UTC. The whole day is included, up to 23:59:59. A value in any other format is ignored silently.
statusenumoptional
Only conversations with this outcome. The value isn't checked: anything else simply matches nothing.successhandoffdrop-off
channelenumoptional
Only conversations on this channel. The value isn't checked: anything else simply matches nothing.voicewhatsapp
assistantIdstringoptional
Only count conversations handled by this agent. Leave it out for the whole workspace. A value that isn't a valid ID is rejected with 400 rather than ignored.
pipelineModestringoptional
Only calls handled by this voice engine, such as `custom`. WhatsApp conversations have none, so setting this leaves them out.
searchstringoptional
Matches part of the customer's phone number (case-insensitive), or a conversation ID: a full ID, or the start of one when at least 6 characters. It is read as a regular expression, so a leading `+` causes a 500. Search without the `+`.
pageintegeroptional
Page number, from 1. Values below 1 become 1.
limitintegeroptional
Conversations per page, up to 100. A value outside 1 to 100 becomes 20 (not 100).
curl https://api.trycareflow.com/analytics/sessions \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "sessions": [
      {
        "_id": "6710b3e2c4a1f09d8e7b6a52",
        "createdAt": "2026-10-05T14:02:09Z",
        "updatedAt": "2026-10-05T14:06:40Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e1",
        "assistantId": "66f1c2a9e4b0f1a2b3c4d5e6",
        "assistantName": "Harbourview Front Desk",
        "channel": "voice",
        "phoneNumber": "+447700900123",
        "dialedNumber": "+442071234567",
        "costUsd": 0.0313,
        "startTime": "2026-10-05T14:02:09Z",
        "endTime": "2026-10-05T14:06:31Z",
        "durationSeconds": 262,
        "status": "success",
        "workflowCompleted": true,
        "workflowName": "Early check-in",
        "avgLatencyMs": 610,
        "pipelineMode": "custom",
        "transcript": [
          {
            "speaker": "assistant",
            "text": "Thanks for calling Harbourview Hotel, how can I help?",
            "startTime": "2026-10-05T14:02:09Z",
            "endTime": "2026-10-05T14:02:12Z"
          },
          {
            "speaker": "user",
            "text": "Can I check in before 2pm on Friday?",
            "startTime": "2026-10-05T14:02:13Z",
            "endTime": "2026-10-05T14:02:16Z",
            "confidence": 0.94
          }
        ],
        "voiceProvider": "twilio"
      }
    ],
    "total": 412,
    "page": 1,
    "limit": 100,
    "pages": 5
  }
}
{
  "code": "ERROR",
  "message": "invalid assistantId",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to get sessions",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get a conversation

GET https://api.trycareflow.com/analytics/sessions/{id}

Requires `analytics:read`. Returns one conversation with its outcome, cost, cost breakdown, response times and transcript. The ID field is `id` here, while the list calls it `_id`. Fields that weren't recorded are left out, apart from `endTime`, which is `null` while the conversation is still going.

Path parameters
idstringrequired
The conversation (session) ID, the `_id` from the session list.
curl https://api.trycareflow.com/analytics/sessions/value \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "session": {
      "id": "6710b3e2c4a1f09d8e7b6a52",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e1",
      "assistantId": "66f1c2a9e4b0f1a2b3c4d5e6",
      "channel": "voice",
      "startTime": "2026-10-05T14:02:09Z",
      "endTime": "2026-10-05T14:06:31Z",
      "durationSeconds": 262,
      "status": "success",
      "costUsd": 0.0313,
      "workflowCompleted": true,
      "pipelineMode": "custom",
      "phoneNumber": "+447700900123",
      "twilioCallSid": "CA0f2d4c8e6b1a3957d2e4f6a8b0c1d2e3",
      "costBreakdown": {
        "telephony": 0.0085,
        "stt": 0.0043,
        "llm": 0.0061,
        "tts": 0.0124,
        "total": 0.0313
      },
      "latencyMetrics": {
        "sttLatencyMs": 180,
        "llmLatencyMs": 310,
        "ttsLatencyMs": 120,
        "totalLatencyMs": 610,
        "turnCount": 3,
        "e2eP50Ms": 620,
        "e2eP95Ms": 700
      },
      "transcript": [
        {
          "speaker": "assistant",
          "text": "Thanks for calling Harbourview Hotel, how can I help?",
          "startTime": "2026-10-05T14:02:09Z",
          "endTime": "2026-10-05T14:02:12Z"
        },
        {
          "speaker": "user",
          "text": "Can I check in before 2pm on Friday?",
          "startTime": "2026-10-05T14:02:13Z",
          "endTime": "2026-10-05T14:02:16Z",
          "confidence": 0.94
        }
      ],
      "hasTranscript": true
    }
  }
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the analytics:read scope"
}
{
  "code": "ERROR",
  "message": "session not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get a conversation's transcript

GET https://api.trycareflow.com/analytics/sessions/{id}/transcript

Requires `analytics:read`. Returns just the transcript of one conversation, in order. Returns 404 `no transcript` when nothing was stored, for example on very old calls or after your retention settings removed it.

Path parameters
idstringrequired
The conversation (session) ID, the `_id` from the session list.
curl https://api.trycareflow.com/analytics/sessions/value/transcript \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "transcript": [
      {
        "speaker": "assistant",
        "text": "Thanks for calling Harbourview Hotel, how can I help?",
        "startTime": "2026-10-05T14:02:09Z",
        "endTime": "2026-10-05T14:02:12Z"
      },
      {
        "speaker": "user",
        "text": "Can I check in before 2pm on Friday?",
        "startTime": "2026-10-05T14:02:13Z",
        "endTime": "2026-10-05T14:02:16Z",
        "confidence": 0.94
      }
    ],
    "pipelineMode": "custom",
    "sessionId": "6710b3e2c4a1f09d8e7b6a52"
  }
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the analytics:read scope"
}
{
  "code": "ERROR",
  "message": "session not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Export conversations as CSV

GET https://api.trycareflow.com/analytics/export

Requires `analytics:read`. Downloads matching conversations as a CSV file (`sessions_export.csv`), newest first, up to 10,000 rows. There's no paging: if you might pass 10,000, split the date range. The filters work like the conversation list, but `search` and `pipelineMode` aren't supported. Columns, in order: `Start Time` (RFC 3339, UTC), `Channel`, `Duration (s)`, `Status`, `Cost (USD)` (4 decimals), `Workflow Completed` (`true`/`false`), `Phone Number`, `Disconnect Reason`, `Avg Latency (ms)` (empty when not recorded), `Session ID`. Transcripts aren't included. Errors before the file starts come back as JSON.

Query parameters
startDatestringoptional
First day to include, as `YYYY-MM-DD` in UTC, counted from 00:00. A value in any other format is ignored silently, so the filter is dropped.
endDatestringoptional
Last day to include, as `YYYY-MM-DD` in UTC. The whole day is included, up to 23:59:59. A value in any other format is ignored silently.
statusenumoptional
Only conversations with this outcome. The value isn't checked: anything else simply matches nothing.successhandoffdrop-off
channelenumoptional
Only conversations on this channel. The value isn't checked: anything else simply matches nothing.voicewhatsapp
assistantIdstringoptional
Only count conversations handled by this agent. Leave it out for the whole workspace. A value that isn't a valid ID is rejected with 400 rather than ignored.
curl https://api.trycareflow.com/analytics/export \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
Response
{
  "code": "ERROR",
  "message": "invalid assistantId",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to get sessions",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get call counts per phone number

GET https://api.trycareflow.com/analytics/phone-stats

Requires `analytics:read`. Returns, for each of your phone numbers, how many calls it took in the last 7 days (rolling, up to now) and what they cost. Numbers with no calls in that time aren't listed, and older calls recorded before the dialled number was tracked aren't counted.

curl https://api.trycareflow.com/analytics/phone-stats \
  -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "stats": {
      "+442071234567": {
        "calls7d": 96,
        "totalCost": 3.41
      },
      "+442079876543": {
        "calls7d": 12,
        "totalCost": 0.38
      }
    }
  }
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "aggregation failed",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}