Analytics
The numbers behind the **Analytics** page: overview, trends, sessions with their transcripts, phone number stats and a CSV export. Requires `analytics:read`.
The Analytic object
Returned by the analytics endpoints.
{ "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
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.
todayweekmonthquartercurl https://api.trycareflow.com/analytics/overview \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
{ "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
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.
successhandoffdrop-offvoicewhatsappcurl https://api.trycareflow.com/analytics/sessions \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
{ "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
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.
curl https://api.trycareflow.com/analytics/sessions/value \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.retrieve('value')
{ "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
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.
curl https://api.trycareflow.com/analytics/sessions/value/transcript \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.retrieve('value')
{ "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" }
Get daily trends
Requires `analytics:read`. Returns one metric per day for the whole workspace, oldest first, plus that day's phone and WhatsApp counts. There's no agent filter. Days come from totals added up just after midnight UTC, so today isn't included (ask for `period=today` to count it live), and a day with no conversations is missing rather than zero. `7d`, `30d` and `90d` cover that many days before today. Any other `period` is treated as `30d`, and any other `metric` as `sessions`.
sessionscostworkflowstoday7d30d90dcurl https://api.trycareflow.com/analytics/trends \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
{ "code": "SUCCESS", "message": "ok", "data": { "metric": "sessions", "period": "7d", "data": [ { "date": "2026-10-04", "value": 61, "voice": 44, "whatsapp": 17 }, { "date": "2026-10-05", "value": 58, "voice": 41, "whatsapp": 17 } ] } }
{ "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 metrics", "error": "<database error>" }
{ "code": "ERROR", "message": "service_unavailable", "error": "key lookup failed" }
Export conversations as CSV
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.
successhandoffdrop-offvoicewhatsappcurl https://api.trycareflow.com/analytics/export \ -H "Authorization: Bearer sk_live_••••"
const Analytic = await careflow.analytics.list()
{ "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
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()
{ "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" }