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

# Stream events

> Event types and fields in the Fleet RLM Turn Server-Sent Events stream.

`POST /api/sessions/{session_id}/turns` returns a `text/event-stream` response. Each frame sets the SSE `event` field to the event type and carries a JSON `data` payload with a matching `type`. The stream ends with a raw `[DONE]` frame.

Payload fields use camelCase on the wire. The source of truth is `src/fleet_rlm/api/ui_stream.py`, and `openapi.yaml` publishes it as `FleetUIMessageChunk`.

## Stream order

1. The stream opens with `turn_status` (`phase: "preparation"`) and repeats it every `runtime.heartbeat_seconds` until Fleet claims and prepares the Turn.
2. `turn_start` marks the start of execution.
3. Step, reasoning, code, output, tool, and text events stream while the RLM works.
4. The stream ends with exactly one terminal event: `turn_finish`, `turn_error`, or `turn_cancelled`.

If claim or preparation fails, the stream emits `turn_error` and then `turn_finish`.

## Lifecycle events

| Type | Fields | Description |
| - | - | - |
| `turn_status` | `phase`, `status`, `message` | Preparation and progress status. |
| `turn_start` | `runId`, `sessionId`, `delivery` (`live` or `replay`), `traceId` | Execution started. `traceId` appears when MLflow tracing is enabled and `mlflow.expose_trace_id` is `true`. |
| `step_start` | `step` | An RLM iteration started. |
| `step_finish` | `step`, `durationMs` | An RLM iteration finished. |
| `turn_finish` | `finishReason`, `status`, `checkpointVersion`, `durationMs`, `traceId` | The Turn settled. |
| `turn_error` | `message`, `code`, `durationMs` | The Turn failed. `code` defaults to `execution_failed`. |
| `turn_cancelled` | `reason`, `durationMs` | The Run was cancelled. |

## Content events

| Type | Fields | Description |
| - | - | - |
| `reasoning` | `streamId`, `step`, `text`, `delta`, `final` | Model reasoning for a step. |
| `code` | `streamId`, `step`, `code`, `isDelta`, `final` | Python the model wrote for the Sandbox. |
| `output` | `streamId`, `step`, `output`, `isDelta`, `final` | Sandbox execution output. |
| `text` | `streamId`, `delta`, `text`, `final`, `role` | Assistant answer text. |
| `structured_result` | `schemaId`, `schemaVersion`, `value` | A typed result payload. |

## Activity events

| Type | Fields | Description |
| - | - | - |
| `tool_call` | `toolCallId`, `toolName`, `input` | A host tool call started. |
| `tool_result` | `toolCallId`, `toolName`, `output`, `error` | A host tool call returned. |
| `skill` | `skillId`, `name`, `phase`, `version`, `trust`, `affordances` | A Skill was selected or loaded. |
| `child_progress` | `childId`, `taskLabel`, `state`, `elapsedMs`, `outcome`, `evidence`, `gaps`, `resultFileCount`, `codeExcerpt`, `outputExcerpt`, `cleanupState`, `parentRunId` | Progress of a recursive child RLM. `state` is `not_started`, `running`, `completed`, `failed`, `cancelled`, or `timed_out`. |
| `attachment` | `attachmentId`, `phase`, `filename`, `byteSize` | An Attachment was staged for the Turn. |
| `artifact` | `artifactId`, `artifactKind`, `title`, `mediaType`, `byteSize`, `checksumSha256` | An Artifact was produced. |
| `usage` | `iterations`, `durationMs`, `usage` | Token and iteration usage. |
| `warning` | `message`, `code` | A non-fatal warning. |

## Compatibility chunks

The stream contract also admits Vercel AI SDK UI message chunk shapes, such as `start`, `text-delta`, `tool-input-available`, `finish`, and `data-*` parts. The response sets the `x-vercel-ai-ui-message-stream` header. New clients should consume the event types above.

## Example

```text theme={null}
event: turn_status
data: {"type":"turn_status","phase":"preparation"}

event: turn_start
data: {"type":"turn_start","runId":"…","sessionId":"…","delivery":"live"}

event: text
data: {"type":"text","streamId":"text","delta":"The first 20 Fibonacci numbers are…","final":false,"role":"assistant"}

event: turn_finish
data: {"type":"turn_finish","finishReason":"stop","status":"completed","checkpointVersion":3}

data: [DONE]
```


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