Calls
Every conversation becomes a record you can find, read, act on while it's live, and delete.
A call record tells you when a conversation happened, what was said, which tools ran, and how it ended. Ordinary reads are PII-redacted. Raw artifacts require audited access.
curl 'https://api.kejue.co/v1/calls?direction=inbound&handled_by=ai&limit=25' \
-H "Authorization: Bearer $KEJUE_API_KEY"Placing outbound calls is a separate workflow — Outbound calling.
Listing and filtering
GET /v1/calls returns non-eval, non-purged calls by default and paginates
with an opaque cursor (Pagination). Filters
combine with AND:
| Axis | Parameters |
|---|---|
| Agent | agent_id, agent_name, or repeated agent_ids (any listed agent) |
| State | status, lifecycle/display outcome, call direction |
| Who handled it | handled_by=ai|human — agent-run vs ingested human calls |
| Time and size | start-time range, call/total duration ranges, turn-count range |
| Flags | recording, legal-hold, purged state |
| Extraction results | up to 20 repeated ef filters |
| Campaign and channel | campaign_id, campaign_name, flow_id, channel, repeated channel_not |
| Call identity | call_id + call_id_match, caller_number + caller_match, platform_number, human_agent, failure_code |
| Guardrails | guardrail_name, guardrail_id, guardrail_severity, guardrail_set_slug |
| Tool calls | tool_slug, tool_name, tool_kind, tool_ok, tool_error_kind |
| Ordering | sort field and direction |
Unknown or duplicated singleton parameters return 400. The repeatable parameters are
ef (at most 20), agent_ids (at most 120 UUIDs), and channel_not (at most six channels).
Agent IDs combine with OR inside the scope; channel exclusions combine with AND.
Both combine with all other filters using AND. An ef
filter is unpadded base64url of JSON: object (extraction-object UUID),
field, a type-compatible op, value — operators per field type in the
CallExtractionFilter schema (API reference).
The guardrail and tool axes are existence tests over a child table: a
call matches when it has a guardrail trigger (or tool invocation) with
those properties. All parameters in one family must describe the same
row — tool_slug=book_appointment&tool_ok=false returns calls where that
specific tool failed, not calls that called it and separately failed
something else. The two families are independent of each other.
call_id and caller_number are text searches (1–64 characters, trimmed,
no number normalization). Their match parameter picks the comparison:
| Match value | call_id_match | caller_match |
|---|---|---|
starts_with | default | prefix |
contains | substring | default |
is | exact UUID | exact value, case-sensitive |
call_id searches ignore case, so a pasted short ID prefix finds the call.
Search caller_number the way the number is stored — +9715 and 9715 are
different prefixes. An invalid match value returns 400 invalid_query_parameter.
Filters that name a nullable column match only rows where it is set:
human_agent is null on agent-run calls, channel is null on rows
predating its backfill, and failure_code is null on calls that
succeeded.
For example, this scopes calls to either agent while excluding web tests and transfer briefs:
curl --get 'https://api.kejue.co/v1/calls' \
--data-urlencode "agent_ids=$AGENT_A" \
--data-urlencode "agent_ids=$AGENT_B" \
--data-urlencode 'channel_not=web_test' \
--data-urlencode 'channel_not=transfer_brief' \
-H "Authorization: Bearer $KEJUE_API_KEY"channel_not uses the same channel vocabulary as channel. Null channels do
not satisfy an exclusion, matching the analysis query's neq behavior. Existing
agent_id and channel filters remain supported and can further narrow this scope.
Reading a call
GET /v1/calls/{id}/summary returns just the post-call summary. Its status is
queued, running, done, or error; read the summary text when it is done.
404 call_summary_not_found means no summary is available yet.
GET /v1/calls/{id} returns the full record: timing and lifecycle,
outcome, direction, safe number metadata, contact, exact deployed agent
version, redacted transcript with entity metadata, redacted tool
invocations, actions, injected-context delivery state,
summary/extraction/webhook-delivery results, recording metadata, turn
metrics, caller-turn clips, and legal-hold/purge state.
Four fields say what kind of call it was:
| Field | Values |
|---|---|
channel | sip_inbound, sip_outbound, web_sdk (web calls), web_test (dashboard test calls), eval, transfer_brief (a warm transfer's consult leg); null for human-handled calls |
direction | inbound or outbound. Web and test calls are inbound. |
metadata.source | real_call, web_call, test_call, or eval_call |
agent_version_is_draft | true when the call ran the agent's unpublished draft — test calls usually do. agent_version is then null, since a draft has no number. |
caller_number is always the external party: the caller on an inbound call,
the dialed destination on an outbound one. platform_number is our side — the
number dialed, or the caller ID presented. Text calls report
recording_enabled: false.
A failed call explains itself. failure_code is a stable code to branch
on, failure_reason a customer-safe sentence, and ended_reason why the
call ended (null while it is live). Detail adds the evidence behind them —
see Why a call failed.
Calls in another workspace and eval-backed calls return the same
404 call_not_found; while purge cleanup or a delivery is in flight, the
response carries Retry-After.
Transcript rows
Every row has speaker, text, timestamp (Unix epoch seconds), kind, and
leg. speaker is agent, caller, tool_call, tool_result, system,
wait, or noise; kind is empty on ordinary rows and otherwise
dtmf_received, dtmf, dtmf_sent, transcription_failed,
agent_handoff, or tool_interrupted — meanings on
webhook events.
Rows that need more carry it: speech_id and interrupted on agent rows,
name and is_error on tool rows, and dtmf_masked with digit_count where
the caller used the keypad — we publish how many keys were pressed and never
the digits. reason explains a non-empty kind or a masked value from a closed
vocabulary. Handoff rows add from_agent and to_agent, the agent slugs either side.
Full field list: API reference.
Latency and Requests
The dashboard's Latency tab shows the call summary and one compact row per turn. Response, transcription, model and speech-synthesis timings are visible together; you do not need to expand each turn to compare measurements.
Each turn's reply time is split into the parts that add up to it: end-of-turn wait, transcription wait, model time to first token, tool wait, first-sentence buffering, speech synthesis to first audio, and the remaining hand-off. The Latency tab draws them as one bar per turn, so the slowest part stands out. In GET /v1/calls/{id}, each turn_metrics row carries them as eou_delay_ms, transcribe_wait_ms, model_first_token_ms, tool_wait_ms, first_chunk_ms, tts_first_audio_ms and handoff_ms. When breakdown_version is 1, they sum exactly to response_latency_ms; when a part is unknown it is null. model_hidden_ms is model time that ran before the caller finished speaking and is not part of the sum.
Each turn’s model_name is the catalog display name, or null when no
unambiguous public name is available. model_role describes the work the
model performed. Internal model_family diagnostics are omitted. An absent
measurement is unavailable; a measured zero is still zero.
The Requests tab lists every provider request in order, with timing, token or audio usage, and failures inline — filterable to a single turn. Long calls paginate beyond the first 200 requests. Older records without an exact turn correlation are marked as estimates.
The public event ledger also accepts a turn_index with session_id to inspect one conversational turn. See Usage and metering.
Trace and timeline
The Trace button on a call opens every event of the call on one timeline: caller and agent audio, transcription, end-of-turn decisions, model and speech-synthesis requests, tool runs, transfers, SIP signalling and errors, laid over the recording. Click an error for its stage, HTTP status, request ID, model and provider. Download trace exports the same data as Chrome Trace Event JSON.
The same data comes from GET /v1/calls/{id}/timeline:
curl https://api.kejue.co/v1/calls/CALL_ID/timeline \
-H "Authorization: Bearer $KEJUE_API_KEY"Every time is milliseconds from anchor, the moment the agent joined the
call; connection and SIP events can be negative because they happen first.
| Key | Contents |
|---|---|
events | Every event, sorted by t: id, t, nullable duration d, track, kind, turn, speech_id, level (info, warn, error), label, source, attrs |
turns | Per-turn latency: response, endpointing, transcription, model, speech-synthesis and tool milliseconds, plus outcome and model |
transcript | The redacted transcript on the same clock |
models | Per model: requests, errors, average time to first token |
recording | Offset and duration of the ready recording, or null |
sources, truncated | Which evidence was available, and whether an event cap was reached |
track | What it holds |
|---|---|
call, state | Lifecycle (joined, answered, ended) and agent state (listening, thinking, speaking) |
caller_speech, agent_speech, vad | Who was speaking, playout, barge-ins |
stt, endpoint, turn, decision | Transcripts, end-of-turn waits and verdicts, turn commits |
llm, tts | Model and synthesis requests, with first-token and first-byte marks |
tool, transfer, guardrail, dtmf | Tool runs, transfer steps, guardrail triggers, keypad input (digits masked) |
sip | SIP requests and responses for the call's legs |
degraded | A fallback the agent switched to, with attrs.reason |
error | Real failures: provider_error, stt_error, tts_error, llm_error, tool_error, session_error, session_open_failed |
An error event’s attrs carry classified evidence — stage, a safe
message, http_status, request_id, the service’s display name in
provider, and error_class where known. Use these fields and support IDs
to report the failing stage; raw upstream diagnostic text isn't returned.
You can read the timeline while a call is live. Events update periodically,
and the sip track fills in when a leg ends. Errors
and degraded-mode events are always kept when a cap truncates the
timeline. Calls handled before timelines were recorded return model
requests, tool runs, turns and transcript only. The operation takes no
query parameters and is not paginated.
Why a call failed
failure_code is stable, so you can branch on it. Treat anything you don't
recognize as unknown.
| Code | Meaning |
|---|---|
caller_hangup_pre_answer | The caller hung up before the agent answered, or nobody joined a web call within about three minutes |
agent_dispatch_timeout | No agent was available to answer |
provider_busy, provider_no_answer | Busy, or no answer |
provider_rejected, provider_forbidden | The carrier refused or declined the call |
provider_authentication | The carrier rejected our credentials |
destination_invalid, caller_id_invalid | The carrier rejected the destination or the caller ID |
provider_capacity, provider_rate_limited | The route was at capacity or rate-limited |
provider_route_unavailable | The carrier returned a server error |
provider_unknown | The provider never confirmed an outcome |
media_pipeline_error | The media session failed |
dncr_blocked, dncr_unavailable, dncr_configuration_invalid | Do Not Call Registry outcomes |
unknown | No more specific cause |
The dashboard labels calls the callee's side didn't take by outcome rather
than "Failed": provider_busy → Busy, provider_no_answer → No
answer (or Rejected when sip_failure shows the far end refused it),
provider_rejected → Declined (SIP 603) or Rejected,
destination_invalid → Invalid number, provider_forbidden →
Blocked. status stays failed for all of them.
A vague code can sharpen later — provider_no_answer can become
destination_invalid when the carrier's final response turns out to be a
404.
On calls through our SIP service, GET /v1/calls/{id} also carries the SIP
evidence (Twilio Media Streams and web calls have none):
| Field | Contents |
|---|---|
sip_failure | The final SIP status, status_text, reason, the carrier-visible call_id, the derived class, and — when the far end sent a Reason: Q.850 header — q850_cause and q850_text. source: "capture" marks an answer taken from Kejue Voice's own SIP capture (the carrier refused a call the provider reported as a plain hang-up). null without a SIP failure |
sip_messages | Captured messages for each leg's setup — the first INVITE, an auth challenge, the authenticated INVITE, and the final response — oldest first. hop is sonus for our SIP service and edge for our SIP edge; on a trunk that signals through the edge, edge messages are exactly what your carrier sent and received, with transport (udp, tcp or tls) |
sip_rejections | SIP-level refusals linked to this call (same shape as the trunk rejection list) |
timeline_available | Whether the timeline has anything beyond start, answer and end — agent events, model requests, tool runs, turns, transcript, transfers, SIP or a recording |
Raw provider and agent diagnostics aren't returned. Stable failure codes, SIP evidence, and request or call IDs are what you troubleshoot with.
Captured messages hold the start line and headers only — bodies are
dropped, and digest response and cnonce values are redacted. They purge
with the call.
Acting on a live call
Hang up
POST /v1/calls/{id}/hangup (no body) durably records the intent, then
instructs the telephony provider to terminate the call.
curl -X POST https://api.kejue.co/v1/calls/CALL_ID/hangup \
-H "Authorization: Bearer $KEJUE_API_KEY" \
-H "Idempotency-Key: incident-884-hangup-1"200 means the provider confirmed termination or the call was already
over — never a guess. The response: call_id, terminal status,
changed, provider_confirmation (confirmed|already_terminal), and
reconciliation_status (scheduled = outbound-job linkage still healing;
it doesn't weaken the confirmation).
Inject context
POST /v1/calls/{id}/context queues an encrypted system message the agent
sees mid-call — a verified identity, an updated case status. content is
UTF-8 up to 4,096 bytes; urgency is immediate, soon (default), or
later. Not a prompt-variable update; send an Idempotency-Key.
The 202 returns a durable message (delivery_status: pending) and a
Location for the parent call; poll after Retry-After and match the
message id in data_messages — delivery moves
pending → publishing → retrying → published | failed; stop at
published or failed.
Provider failures never fake success:
502 call_hangup_provider_failed— the provider definitively refused.503 call_hangup_unavailable— call-bound control or lifecycle state is unavailable; honorRetry-After.504 call_hangup_outcome_unknown— ambiguous provider result;Retry-Afteris one second and reconciliation remains required.
When error.details.retry_with_same_idempotency_key is true, retry with
the same key. Concurrent requests with different keys are serialized; one
that finds the call already terminal succeeds with changed: false.
Media
GET /v1/calls/{id}/recording downloads call audio (Ogg/Opus); the
written reason (8–500 characters) is audited. Select an exact
recording_id or a role/leg/segment tuple (roles agent|caller|mixed;
legs caller, transfer brief; zero-based segments) — mixing selectors
is a 400. Call metadata reports recording|encrypting|ready|failed,
duration, and size. One RFC 9110 Range is honored (206 +
Content-Range; malformed or multiple ranges: JSON 416);
download=true sets attachment disposition; 409 not ready; 410 audio
gone, metadata kept.
GET /v1/calls/{id}/turn-audio?turn_index=N&leg=caller|brief — one
short-lived WAV clip of a caller turn, from the list in call detail. Same
recording permission, audited, accepts download and one byte range;
410 once the clip expires.
Transfer history
GET /v1/calls/{id}/transfers returns every transfer attempt with its
append-only event timeline; payloads pass a fail-closed public allowlist
and flag payload_redacted when internal keys were removed. Needs
transfers:read; configuration is in
Call actions. Handoffs to another agent appear here
too, as kind: agent with method: handoff — see
Handoffs.
Retention and deletion
Calls age out after the workspace's retention_days
(Workspace settings); a purge tombstone records
manual vs retention.
DELETE /v1/calls/{id} purges on demand — PHI and diagnostic content
removed; a tombstone, billing aggregates, and scrubbed audit evidence
remain. The call must be ended, past post-call processing, and off legal
hold. 200: cleanup done; 202: durable recording/PCAP/turn-audio
deletion jobs still running — follow Location/Retry-After and watch
purge_cleanup counts.
POST /v1/calls/batch-delete (1–200 unique call UUIDs; Idempotency-Key
required) returns one typed result per input: purged, purging,
already_purged, legal_hold, active, processing, or not_found.
Poll each purging entry's own poll_url — the batch is not one shared
job.
Audited access and compliance
Some call data is too sensitive for routine reads. These operations are
permission-gated, always audited, and hidden from the API-reference
navigation while remaining in the published OpenAPI document, served
normally. Approval friction is governed by pii_access_mode — workflow
in Compliance.
GET /v1/calls/{id}/transcript-raw?leg=caller|brief&reason=...— newest encrypted raw transcript. Needspii-access:unmask.GET /v1/calls/{id}/tools/{toolId}/raw?reason=...— one tool invocation's original JSON request and response. Needspii-access:unmask.GET /v1/calls/{id}/sip-pcap/summary— pollable packet/byte/capture state, no packet bytes;503when capture isn't deployed.GET /v1/calls/{id}/sip-pcap?reason=...— decrypted, validated PCAP download; one byte range. Needscalls:read-sip-pcap.PUT /v1/calls/{id}/legal-holdwith{"held": true}or{"held": false}— idempotent, returnschanged, takesIf-Match. A held call cannot be purged (manually or by retention); a purged call's hold can't change. A real change needscalls:legal-holdplus thelegal_holdentitlement (403 entitlement_required,details.feature: "legal_hold"); re-sending the current state is a permitted no-op.
Never copy raw responses into logs, analytics, prompts, or support tickets; prefer the redacted call detail whenever it answers the question.
Permissions
| Permission | Grants |
|---|---|
calls:read | list, redacted detail, and timeline |
calls:hangup | live-call termination |
calls:inject-context | live context injection |
calls:download-recording | recordings and caller-turn audio |
transfers:read | transfer history |
pii-access:unmask | raw transcript and raw tool I/O |
calls:read-sip-pcap | PCAP summary and download |
calls:legal-hold | hold changes |
calls:delete | individual and batch purge |
See also Human-handled calls, Compliance, and Errors.