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

# Events & streaming

> The resumable, sequence-keyed event stream behind every session.

Everything an agent does is recorded as an ordered stream of events. Each event has a monotonically increasing `seq` within its session, so the stream is fully resumable: reconnect from the last `seq` you saw and never miss or duplicate an event.

Because every event is sequence-keyed, a dropped connection is not a lost event — you reconnect with the last `seq` you handled and the stream picks up exactly where you left off:

```
   session events, ordered by seq
   ──▶ 125 ─ 126 ─ 127 ─ 128 ─ 129 ─▶ (live tail)
                             ▲
        reconnect with after_seq = last seq you handled
        replay from 0 for a fresh consumer · no gaps, no duplicates
```

## Event shape

Events follow a `{domain}.{action}` naming scheme.

```json theme={"system"}
{
  "id": "evt_01H...",
  "seq": 128,
  "session_id": "ses_01H...",
  "type": "tool.completed",
  "created_at": "2026-08-20T23:14:02.140Z",
  "data": { "tool_call_id": "call_01H...", "name": "bash", "output": "…", "is_error": false }
}
```

## Streaming

Streams are delivered as Server-Sent Events. Pass `after_seq` (exclusive) to replay from a point in history — new consumers pass `0` to get the whole session. The SDK's stream ends at the turn's `session.idle`; a resume on a session that is already idle or ended returns once it has caught up to the session's last event.

```bash CLI theme={"system"}
# Stream live; append new events as they arrive
naive session stream $SID --from-seq 0
```

```typescript TypeScript theme={"system"}
for await (const e of client.stream(sessionId, { afterSeq: lastSeq })) {
  lastSeq = e.seq;
  handle(e);
}
```

```bash cURL theme={"system"}
curl -N "https://api.vetta.sh/v1/sessions/$SID/stream?after_seq=0" \
  -H "authorization: Bearer $NAIVE_API_KEY" \
  -H "accept: text/event-stream"
```

### The agent's final answer

`message.completed` fires for **your** message too (`data.role` is `"user"`). The agent's reply is the `message.completed` without `role: "user"`; its text is `data.content`. Keep the last one before `session.idle`:

```typescript TypeScript theme={"system"}
let answer = "";
for await (const e of client.stream(sessionId)) {
  if (e.type === "message.completed" && e.data.role !== "user") answer = String(e.data.content);
}
```

## Reading history

Events are also available as a paginated list for auditing or replay without a live connection.

```bash CLI theme={"system"}
naive session events --session $SID --limit 100
```

## Sending events in

You drive a session by sending events too — a user message, a tool confirmation, or an interrupt.

```typescript TypeScript theme={"system"}
await naive.sessions.send(session.id, { message: "Refund order #4821" });                    // a user message
await naive.sessions.confirmTool(session.id, { tool_call_id: toolCallId, decision: "allow" }); // answer a tool.confirm
await naive.sessions.interrupt(session.id);                                                  // stop the turn
```

## Common event types

| Type | Meaning |
| - | - |
| `session.running` | The agent started a turn. |
| `session.idle` | The turn yielded control and the session is waiting. Carries a `stop_reason` (`budget_paused` when it stopped at its budget cap). |
| `session.usage` | A cumulative cost/usage snapshot (`token_usage`, `consumed_micro_usd`, `active_seconds`, `tool_calls`), emitted before every idle or terminal transition. See [Observability](https://vetta.sh/docs/capabilities/observability.md). |
| `message.delta` | A chunk of assistant text. |
| `message.completed` | A message finished — the agent's, or yours with `role: "user"`. |
| `tool.started` | A tool call began. |
| `tool.confirm` | A tool gated by an [`ask` policy](https://vetta.sh/docs/concepts/policies) is waiting on your allow/deny. |
| `tool.completed` | A tool call finished (success or error). |
| `budget.exceeded` | A call was refused because it would breach the cap. |

See the full list in the [Event reference](https://vetta.sh/docs/api/events.md).

> [card] [Next: completion window](https://vetta.sh/docs/concepts/completion-window.md)
>
> Three prices for one model.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.