SSE Streaming
For long-running AI operations, use Server-Sent Events (SSE) to receive real-time progress updates instead of waiting for the full response.SSE is one option, not the only option. For non-browser consumers (server-side workers, batch jobs, AI agent tools), the synchronous
/v1/chat endpoint or polling on /v1/jobs/{id} are simpler and equally valid. See Server Integration for the patterns.Revert + active SSE. If your UI lets users revert a session while an SSE stream is still open, close the
EventSource first (or wait for the final event) before sending the revert call. Revert returns 409 while a chat job is in flight on the session, and any updates that arrive after revert from the original branch are stale.How it works
- Start an async chat request to get a
job_id - Open an SSE connection to stream progress
- Receive events as the AI processes your request
Setup
SSE uses EventSource, which doesn’t support custom headers. Pass your API key as the
api_key query parameter.Event types
The stream emits 11 event types:intermediate
Progress updates during AI processing.
Rendering intermediate events in your UI
Show everyintermediate event to users in real time. Operations on large documents (or with model_tier: "max" + thinking_depth: "deep") can take 30 seconds to several minutes — without visible progress, your UI looks frozen and indistinguishable from a crash.
Pattern 1 — Append-and-update an in-flight chat bubble (recommended for chat-style UIs):
timestamp field to detect stalls programmatically.
proposed_change
In HITL mode (approval_mode: "ask_every_time"), the AI proposes a document change for review. Single, isolated changes still arrive as one proposed_change event; multi-change turns are delivered via proposed_change_batch instead (a single event carrying every change in the batch).
content field is a JSON string. Parse it to get the change details:
| Field | Type | Description |
|---|---|---|
change_id | string | Unique ID for this change. Use when calling /approve. |
operation | string | "edit", "create", or "delete". |
chunk_id | string | null | The document section being modified or deleted. Null for creates. |
old_html | string | null | Current HTML content. Present for updates and deletes. Null for creates. |
new_html | string | null | Proposed new HTML content. Present for updates and creates. Null for deletes. |
ai_explanation | string | Why the AI proposed this change. Show this to the user. |
batch_id | string | null | Groups related changes. All changes in a batch share the same batch_id. |
batch_total | number | null | How many changes are in this batch. Wait for this many events before showing the review UI. |
insert_after_chunk_id | string | null | For create: where to insert the new section in the document. |
proposed_change_batch
When the AI proposes multiple changes in a single turn (common for sweeping edits across many sections of a document), the entire batch arrives as one SSE event instead of a fan-out of N proposed_change events. This keeps the wire load proportional to turns, not changes, and lets HITL UIs render the whole approval card at once.
proposed_change.content, the content field is a JSON-stringified string that must be parsed once more:
changes[] also carries the document_id it belongs to, so your UI can group the review list per document.
The parsed payload:
| Field | Type | Description |
|---|---|---|
type | string | "batch_approval" for multi-change turns, "single_approval" for one-change turns delivered through this event for uniformity. |
batch_id | string | Shared identifier across the batch — equals the first change’s change_id. |
batch_total | number | Number of entries in changes. |
changes | array | Per-change objects with the same fields as proposed_change (change_id, operation, chunk_id, old_html, new_html, ai_explanation, insert_after_chunk_id). |
continue_prompt
For a very large edit, the AI completes as much as it can in one turn, keeps that work, and asks whether to continue with the rest. This can happen in either approval mode. Resume (or stop) by calling POST /v1/chat/{session_id}/continue.
content field is a JSON string — parse it for:
message— a ready-to-display prompt, already in the user’s language.done/total/remaining— progress counts you can show alongside it.
continue: true to keep going or false to stop and keep what’s done. The job resumes and may emit another continue_prompt for the next segment — handle it in a loop, the same way you handle repeated proposed_change rounds.
document_sync
Emitted before the AI begins processing, after the backend has prepared your document for editing. The event carries the prepared HTML containing the section identifiers the AI will reference when proposing changes.
document_html in the request. The event arrives once at the start of the stream, before any intermediate or proposed_change events.
What to do with it: Apply the HTML to your editor immediately so the editor’s section IDs match the IDs the AI will reference in subsequent proposed_change events. This is essential for HITL diff highlights to render correctly on freshly pasted or uploaded documents — without it, the editor and the AI may disagree on which section a change targets.
If you do not render diffs in an editor (e.g., you only display the final response), you can ignore this event.
documents_changed
Emitted when a turn touched more than one open document on auto-apply, or created a new document (creation applies immediately in either approval mode). Tells your UI which documents changed so non-focused tabs can badge and newly created tabs appear — for review-mode edits, proposed_change_batch already carries per-change document_id, so this event isn’t needed there.
content):
documents[]— one entry per changed document:document_id,title,change_count,changed_chunk_ids(sections to flash on tab switch), andcreated(truewhen the AI opened this as a brand-new document this turn — add a tab for it; itschange_countis0).focused_document_id— the document currently in focus after the turn.
approval_mode: "approve_all") turns that changed 2+ documents, and on any turn — either approval mode — where the AI created a new document (creation applies immediately even in review mode). Single-document edit turns don’t emit it. Ignore it if your integration only ever works with one document per session.
final
Job completed successfully. Contains the full result.
result also includes focused_document_id so you know which open document the turn finished on.
usage
Emitted after final with usage consumption data.
ui_pointer
Side-channel hint that the user’s last message expressed intent for a specific UI affordance — most commonly export / download / “open in Word”. Use it to surface the relevant button in your UI (e.g., glow the Export button) instead of having the AI describe its location in prose. Fires alongside final, not before it.
target— the affordance the user wants. Current values:export_button. Treat as forward-compatible — new targets may be added without changing the event-type contract; ignore values you don’t recognise.reason— short human-readable note describing the inferred intent. Surface in telemetry; never to end users.
final content). Multilingual — recognition is intent-based, not keyword-based.
Rendering pattern (recommended):
reason text — it’s a trace string for your telemetry, not a user-facing message.
error
Job failed, was cancelled, or an auth error occurred.
model_fallback
Emitted only when the AI tier you requested is temporarily unresponsive upstream and SuperDocs automatically completed your request on the pro tier instead. Your request still succeeds — this event just tells you (and lets you tell your users) that a different tier served it.
Reconnect & resume
Every event carries a monotonically increasingsequence number. If your EventSource connection drops mid-job, reconnect with the last_sequence query parameter set to the highest sequence you already processed — the stream replays only newer events, never the full history:
last_sequence (or pass 0) to receive the full event history for the job — useful when a fresh client attaches to an already-running job. This also makes reconnecting after approve_change safe: already-rendered proposed_change_batch / document_sync events are not re-delivered.

