Docs
Agent

Agent SSE Event Reference

Reference documentation for all SSE event types streamed during an agent turn, covering text, tool_call, tool_result, vault_file, and billing_required events with field descriptions and usage guidance.

The MarkDocket agent streams its responses as a sequence of Server-Sent Events (SSE) over an HTTP POST connection. Each event carries a type field that identifies its role in the turn, plus a data payload. This page documents every event type your client may receive, the fields each carries, and how to handle them.

Connection model. Because the agent stream uses POST (to carry the turn payload), it cannot use the browser's built-in EventSource API, which only supports GET. Use a streaming fetch() and parse the text/event-stream body line by line, or use the helper in @markdocket/cli if you are building a Node.js integration.


Event envelope

Every event in the stream follows the SSE wire format:

event: <type>
data: <JSON-encoded payload>

The data field is always a JSON object. The shape of that object depends on type, as described below.


Event types

text

A streaming prose chunk from the model. Multiple text events are emitted in sequence; concatenate their content fields in order to reconstruct the full assistant message.

FieldTypeDescription
type"text"Event discriminator.
contentstringA fragment of the assistant's natural-language response.
turnIdstringThe turn this event belongs to.

Usage: Append each content fragment to your display buffer as it arrives for a typewriter effect. The stream of text events ends when the model has finished producing prose for the current reasoning step — further events of other types may still follow.


tool_call

Emitted when the model decides to invoke a tool. The agent has not yet executed the tool at this point — the event signals intent.

FieldTypeDescription
type"tool_call"Event discriminator.
toolCallIdstringUnique identifier for this tool invocation within the turn. Matches the toolCallId on the corresponding tool_result event.
toolNamestringThe name of the tool being called, as registered in the tool catalog (for example, trademark_search or web_search).
argsobjectThe arguments the model is passing to the tool, as a JSON object matching the tool's input schema.
turnIdstringThe turn this event belongs to.

Usage: Use tool_call events to show the user which tools the agent is using and with what parameters. The toolName always matches a name from the published tool catalog. toolCallId is the correlation key — hold it until the matching tool_result arrives.


tool_result

Emitted after a tool call completes, carrying the result the agent received back. Every tool_call event will be followed by exactly one tool_result with the same toolCallId, unless the turn is cancelled or fails before the tool returns.

FieldTypeDescription
type"tool_result"Event discriminator.
toolCallIdstringMatches the toolCallId from the originating tool_call event.
toolNamestringThe name of the tool that was called.
resultobject | stringThe tool's output. Shape is tool-specific; consult the tool catalog for each tool's result schema.
isErrorbooleantrue if the tool call produced an error rather than a successful result.
turnIdstringThe turn this event belongs to.

Usage: Match toolCallId to the earlier tool_call event to update your UI (for example, mark a tool-call card as completed or errored). When isError is true, the model will typically observe the error and decide whether to retry, use a different tool, or explain the failure in a subsequent text event.


vault_file

Emitted when the agent has saved a file to the user's Vault as part of the turn. This can occur after tools that produce downloadable artifacts (reports, draft documents, figures, and similar outputs).

FieldTypeDescription
type"vault_file"Event discriminator.
vaultFileIdstringThe identifier of the newly created Vault file. Use this to fetch or display the file via the Vault API.
filenamestringThe display name of the file as stored in the Vault.
mimeTypestringMIME type of the file (for example, application/pdf or image/png).
turnIdstringThe turn this event belongs to.

Usage: Render a file attachment card in your UI when a vault_file event arrives. The user can then open or download the file using vaultFileId with the Vault file endpoint. More than one vault_file event may arrive in a single turn if the agent produces multiple artifacts.


billing_required

Emitted when the agent turn cannot proceed because a billing action is required — for example, the account has no remaining credits, or a plan upgrade is needed to use a particular capability. The turn stops after this event is emitted.

This event carries a BillingBlockEnvelope as its payload.

FieldTypeDescription
type"billing_required"Event discriminator.
reasonstringMachine-readable code explaining why billing was blocked (for example, "no_credits" or "plan_required").
requiredActionstringThe action the user must take to unblock the turn. Always corresponds 1-to-1 with reason per the platform's billing contract.
contractVersionstringThe billing contract version string that produced this envelope.
turnIdstringThe turn this event belongs to.

Turn is terminal after billing_required. No further events will be emitted for this turn once billing_required arrives. The agent has not taken any billable action. Display the appropriate upgrade or top-up prompt to the user based on requiredAction, then allow them to resubmit the turn after resolving the billing issue.

Usage: The billing_required event is the streaming equivalent of an HTTP 402 response — the same BillingBlockEnvelope shape is used at every layer of the platform (HTTP error bodies, automation signals, CLI output, and MCP structured errors), so you can handle it uniformly. Inspect requiredAction to determine which UI flow to present: a credits top-up, a plan upgrade, or a payment method update.


Turn lifecycle and event ordering

A normal agent turn produces events roughly in this order, though the exact sequence depends on how many tool calls the model makes:

  1. One or more text events — the model's initial reasoning or response prose.
  2. A tool_call event — the model requests a tool.
  3. A tool_result event — the tool returns its output.
  4. Steps 1–3 may repeat as the model reasons across multiple tool calls.
  5. Zero or more vault_file events — if the turn produced saved artifacts.
  6. A final text event — the model's concluding response.

If billing is blocked at any point, the sequence ends with a single billing_required event instead of completing normally.

Cancellation. If the user cancels a running turn, the stream closes without a terminal event. Your client should handle an unexpected stream closure gracefully — any tool_call events that arrived before cancellation will not have matching tool_result events.


Correlating events

All events include a turnId field that matches the turn identifier returned when the turn was submitted. Use turnId to associate streamed events with the correct conversation thread when multiple turns are in flight, and use toolCallId to pair each tool_call with its eventual tool_result.


Error handling summary

SituationWhat to expect
Tool call failstool_result arrives with isError: true; turn may continue
Billing blockedbilling_required event; turn is terminal
User cancelsStream closes; no terminal event
Network or server errorStream closes with an HTTP error status before SSE events begin

For billing errors specifically, the reason and requiredAction fields follow the platform's canonical billing contract — each reason maps to exactly one requiredAction, so you can drive UI flows deterministically from the event payload without additional API calls.

On this page