Skip to navigation

Follow a call's transcript live

Summary

This guide opens the live transcript stream of a call, shows each line while the call runs, and resumes the stream after a dropped connection. It covers streamLiveCallTranscript. It does not cover the verified transcript of a finished call; see Calls and results.

Facts

ItemValue
OperationstreamLiveCallTranscript
PathGET /calls/{call_id}/transcript/live
Capabilitycalls.read
Required headersAuthorization
Optional headersLast-Event-ID: the last event id you received, 1 to 2048 characters
Answer200 with text/event-stream
Eventstranscript.message for each line, then transcript.end once the call is over
transcript.message fieldstype, call_id, segment_id, speaker (agent or customer), text, final, start_ms, end_ms
transcript.end fieldstype, call_id, state (the call’s state)
HeartbeatsComment frames (: keep-alive) with no data
Connection lengthAt most 55 minutes for one connection
Calls it works forEvery call: dialled, inbound, agent sessions and test calls
EnvironmentRASEN_API_BASE (the base URL, ending in /v1), RASEN_API_KEY, CALL_ID
Python3.10 or later, with the httpx package
TypeScriptNode.js 22 or later (built-in fetch)

Steps

Set CALL_ID to the id of the call, from the answer of createCall or createAgentSession, or from listCalls. You can open the stream any time after the call is created: it waits for the call to connect.

1. Open the stream and print each line

The sample keeps the newest payload of each segment_id and prints it. It also keeps the last event id, for step 2.

curl -N -sS "$RASEN_API_BASE/calls/$CALL_ID/transcript/live" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Accept: text/event-stream"

Each transcript.message is one payload of one line. A customer line arrives when its speech recognition is final. An agent line arrives as its words go to speech, then once more with its final words. start_ms and end_ms are milliseconds from the start of the call recording. When the call is over, transcript.end arrives with the call’s state, and the stream closes.

2. Resume after a dropped connection

Set LAST_EVENT_ID to the last id: value that step 1 printed.

curl -N -sS "$RASEN_API_BASE/calls/$CALL_ID/transcript/live" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Accept: text/event-stream" \
-H "Last-Event-ID: $LAST_EVENT_ID"

The stream continues after the last line you received. Event IDs are opaque and bind the workspace and the call: send an ID only to the stream of the call that gave it.

Rules

  • MUST show the newest payload of each segment_id, and MUST NOT replace a final: true line with a later final: false one.
  • MUST treat a segment_id of null as a line of its own.
  • MUST reconnect with Last-Event-ID when a connection drops or reaches 55 minutes.
  • MUST NOT treat the live lines as the call’s record. The last words of a call can be missing from them when the call ends first. After the call, read the verified transcript with getCallTranscript or streamCallTranscript.
  • MUST NOT treat comment frames as lines. They are heartbeats.
  • The stream never starts work on the call.

Verify

After the call is over, read its verified transcript:

curl -sS "$RASEN_API_BASE/calls/$CALL_ID/transcript" \
-H "Authorization: Bearer $RASEN_API_KEY"

Expected output: the transcript items with speaker, text, start_ms and end_ms.

{"items": [{"index": 0, "speaker": "agent", "text": "Hello, this is the clinic.", "start_ms": 0, "end_ms": 2100}], "next_cursor": null}

Errors

CodeCauseFix
not_foundThe call does not exist in this workspace.Check CALL_ID.
forbiddenThe key does not have calls.read.Use a key with calls.read.
rate_limitedThe key or the workspace already has the most transcript streams open, or sent too many requests.Wait the seconds in Retry-After, then reconnect with Last-Event-ID.
invalid_requestA parameter is not valid, for example a Last-Event-ID longer than 2048 characters.Send the id value exactly as the stream gave it.
unavailableThe service is unavailable.Wait, then reconnect with Last-Event-ID.