> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# Follow a call's transcript live

> Stream the transcript lines of a running call as Server-Sent Events, show each line as it changes, and resume after a dropped connection.

## 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](/guides/calls).

## Facts

| Item                        | Value                                                                                                     |
| --------------------------- | --------------------------------------------------------------------------------------------------------- |
| Operation                   | `streamLiveCallTranscript`                                                                                |
| Path                        | `GET /calls/{call_id}/transcript/live`                                                                    |
| Capability                  | `calls.read`                                                                                              |
| Required headers            | `Authorization`                                                                                           |
| Optional headers            | `Last-Event-ID`: the last event `id` you received, 1 to 2048 characters                                   |
| Answer                      | `200` with `text/event-stream`                                                                            |
| Events                      | `transcript.message` for each line, then `transcript.end` once the call is over                           |
| `transcript.message` fields | `type`, `call_id`, `segment_id`, `speaker` (`agent` or `customer`), `text`, `final`, `start_ms`, `end_ms` |
| `transcript.end` fields     | `type`, `call_id`, `state` (the call's state)                                                             |
| Heartbeats                  | Comment frames (`: keep-alive`) with no data                                                              |
| Connection length           | At most 55 minutes for one connection                                                                     |
| Calls it works for          | Every call: dialled, inbound, agent sessions and test calls                                               |
| Environment                 | `RASEN_API_BASE` (the base URL, ending in `/v1`), `RASEN_API_KEY`, `CALL_ID`                              |
| Python                      | 3.10 or later, with the `httpx` package                                                                   |
| TypeScript                  | Node.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`**

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

**`Python`**

```python Python
import json
import os

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
CALL_ID = os.environ["CALL_ID"]

lines = {}
last_event_id = None

with httpx.stream(
    "GET",
    f"{BASE}/calls/{CALL_ID}/transcript/live",
    headers={"Authorization": f"Bearer {KEY}", "Accept": "text/event-stream"},
    timeout=None,
) as response:
    response.raise_for_status()
    for raw in response.iter_lines():
        if raw.startswith("id:"):
            last_event_id = raw[3:].strip()
        elif raw.startswith("data:"):
            event = json.loads(raw[5:])
            if event["type"] == "transcript.message":
                key = event.get("segment_id") or id(event)
                old = lines.get(key)
                if old is None or not (old["final"] and not event["final"]):
                    lines[key] = event
                    print(f'{event["speaker"]}: {event.get("text", "")}')
            elif event["type"] == "transcript.end":
                print("call over:", event["state"])

print("last event id:", last_event_id)
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CALL_ID } = process.env;

const response = await fetch(`${RASEN_API_BASE}/calls/${CALL_ID}/transcript/live`, {
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, Accept: "text/event-stream" },
});
if (!response.ok || !response.body) throw new Error(`HTTP ${response.status}`);

const lines = new Map<string, { final: boolean }>();
let lastEventId: string | undefined;
let buffer = "";
const decoder = new TextDecoder();

for await (const chunk of response.body) {
  buffer += decoder.decode(chunk, { stream: true });
  const parts = buffer.split("\n");
  buffer = parts.pop() ?? "";
  for (const raw of parts) {
    if (raw.startsWith("id:")) {
      lastEventId = raw.slice(3).trim();
    } else if (raw.startsWith("data:")) {
      const event = JSON.parse(raw.slice(5));
      if (event.type === "transcript.message") {
        const key = event.segment_id ?? crypto.randomUUID();
        const old = lines.get(key);
        if (!old || !(old.final && !event.final)) {
          lines.set(key, event);
          console.log(`${event.speaker}: ${event.text ?? ""}`);
        }
      } else if (event.type === "transcript.end") {
        console.log("call over:", event.state);
      }
    }
  }
}

console.log("last event id:", lastEventId);
```

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`**

```bash curl
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"
```

**`Python`**

```python Python
import os

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
CALL_ID = os.environ["CALL_ID"]
LAST_EVENT_ID = os.environ["LAST_EVENT_ID"]

with httpx.stream(
    "GET",
    f"{BASE}/calls/{CALL_ID}/transcript/live",
    headers={
        "Authorization": f"Bearer {KEY}",
        "Accept": "text/event-stream",
        "Last-Event-ID": LAST_EVENT_ID,
    },
    timeout=None,
) as response:
    response.raise_for_status()
    for raw in response.iter_lines():
        print(raw)
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CALL_ID, LAST_EVENT_ID } = process.env;

const response = await fetch(`${RASEN_API_BASE}/calls/${CALL_ID}/transcript/live`, {
  headers: {
    Authorization: `Bearer ${RASEN_API_KEY}`,
    Accept: "text/event-stream",
    "Last-Event-ID": LAST_EVENT_ID!,
  },
});
if (!response.ok || !response.body) throw new Error(`HTTP ${response.status}`);

const decoder = new TextDecoder();
for await (const chunk of response.body) {
  process.stdout.write(decoder.decode(chunk, { stream: true }));
}
```

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:

```bash
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`.

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

## Errors

| Code              | Cause                                                                                             | Fix                                                                     |
| ----------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| `not_found`       | The call does not exist in this workspace.                                                        | Check `CALL_ID`.                                                        |
| `forbidden`       | The key does not have `calls.read`.                                                               | Use a key with `calls.read`.                                            |
| `rate_limited`    | The 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_request` | A parameter is not valid, for example a `Last-Event-ID` longer than 2048 characters.              | Send the `id` value exactly as the stream gave it.                      |
| `unavailable`     | The service is unavailable.                                                                       | Wait, then reconnect with `Last-Event-ID`.                              |

## Related

* [Calls and results](/guides/calls)
* [Rate limits](/concepts/rate-limits)
* [Errors](/concepts/errors)