> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GET /v1/agents/:id/live — stream live trace events

> Subscribe to a Server-Sent Events stream that delivers real-time trace updates for an agent. The dashboard uses this endpoint to power its live trace view.

The live endpoint opens a persistent Server-Sent Events (SSE) connection that delivers trace and event updates for a specific agent as they arrive. When your agent is actively running, batches appear on the stream within a second of being written to storage. This is the same stream the Mortem dashboard uses to power the live trace view on the agent detail page.

```
GET https://ingest.mortem.dev/v1/agents/:id/live
```

## Authentication

The live endpoint uses a **Privy JWT**, not an agent API key. This is because the stream is consumed by the dashboard running in the browser, not by the agent itself. The Privy JWT is the same token issued when you log in to the Mortem dashboard.

Pass the token in the `Authorization` header:

```
Authorization: Bearer <PRIVY_JWT>
```

The endpoint checks that the authenticated user has owner, editor, or viewer access to the requested agent. If they do not, it returns `403 Forbidden`.

<Note>
  If you are building a custom integration that needs to consume the live stream programmatically from server-side code, contact the Mortem team. The current authentication model is designed for browser-based dashboard consumption.
</Note>

## Path parameters

<ParamField path="id" type="string" required>
  The agent ID whose live trace updates you want to stream. This is the same `MORTEM_AGENT_ID` value used when configuring the SDK.
</ParamField>

## Response

The endpoint responds with `200 OK` and the following headers:

```
Content-Type: text/event-stream; charset=utf-8
Cache-Control: no-cache, no-transform
Connection: keep-alive
```

The connection stays open indefinitely. Each update arrives as a Server-Sent Event with the event name `trace` and a JSON-encoded body.

### Event format

```
event: trace
data: <JSON-encoded BufferBatchItem>
```

Each `data` value is a JSON string representing a single `BufferBatchItem` — the same object shape sent in the `items` array of a batch request. It contains a `trace` object (full snapshot of the trace state at flush time) and an `events` array (new events added since the last flush).

### Replay on connect

When you first connect, the endpoint replays up to the last 1,000 batches stored for the agent before switching to real-time delivery. This means you see recent history immediately without waiting for new agent activity. The replay events arrive in chronological order before any new live events.

### Warning events

If the live stream is temporarily interrupted — for example due to a Redis connectivity issue — the endpoint emits a `warning` event:

```
event: warning
data: {"message":"live stream interrupted"}
```

The connection remains open after a warning. You can continue listening; new batches will resume when the underlying issue resolves.

## Example

<CodeGroup>
  ```bash curl theme={null}
  curl \
    -H "Authorization: Bearer $PRIVY_JWT" \
    -H "Accept: text/event-stream" \
    https://ingest.mortem.dev/v1/agents/$MORTEM_AGENT_ID/live
  ```

  ```text SSE stream output theme={null}
  : connected

  event: trace
  data: {"trace":{"id":"01J8XKZP4N0000000000000000","agentId":"01J8AGENT00000000000000000","status":"running","startedAt":"2025-01-15T10:30:00.000Z","inputSummary":"Evaluate whether to swap 1 SOL for JUP","tags":["swap","devnet"],"eventCount":1,"totalTokens":312,"totalCostUsd":"0.0004","totalLamports":"0","solanaTxCount":0,"toolsCalled":[],"endedAt":null,"durationMs":null,"outputSummary":null,"errorMessage":null,"anchorSignature":null,"anchorSlot":null,"merkleProof":null,"traceHash":null,"shareToken":null},"events":[{"id":"01J8XKZP4N0000000000000002","traceId":"01J8XKZP4N0000000000000000","parentEventId":null,"sequence":0,"type":"llm_call","startedAt":"2025-01-15T10:30:00.100Z","endedAt":"2025-01-15T10:30:01.400Z","durationMs":1300,"payload":{"provider":"openai","model":"gpt-4o-mini","input":{"messages":[{"role":"user","content":"Should I swap 1 SOL for JUP right now?"}]},"output":{"content":"Based on current market conditions...","finishReason":"stop"},"usage":{"inputTokens":24,"outputTokens":288,"totalTokens":312},"costUsd":0.0004,"streamed":false},"payloadEncrypted":false,"status":"ok","errorMessage":null}]}

  event: trace
  data: {"trace":{"id":"01J8XKZP4N0000000000000000","status":"completed","endedAt":"2025-01-15T10:30:05.200Z","durationMs":5200,"outputSummary":"Decided not to swap — price impact too high at 2.3%","eventCount":3,"totalTokens":590,"totalCostUsd":"0.0009","totalLamports":"0","solanaTxCount":0},"events":[]}
  ```
</CodeGroup>

<Note>
  The 1,000-batch replay buffer is scoped per agent. Live replay is a convenience feature, not a durable event log. For the full trace record, use the dashboard trace detail view.
</Note>
