TinyMCE AI Streaming
Real-time AI interactions using Server-Sent Events (SSE) for immediate feedback and progressive content generation.
Overview
TinyMCE AI services use Server-Sent Events (SSE) to provide real-time streaming responses. This allows users to see AI-generated content as it is being created, providing immediate feedback and enabling interactive experiences.
SSE event types
Conversations, Reviews, Actions, and Document Processing each use their own set of events and JSON payloads in the SSE stream. Those payloads are documented on each streaming operation in the interactive API documentation.
Use the API reference for the operation being called—for example:
-
Conversation Messages and related Conversation tags for chat streaming, sources, and reasoning.
-
Reviews API for review streaming responses.
-
Actions API for action streaming responses.
-
Process a document (streaming) for Document Processing streaming responses. See also Document Processing streaming.
The shared wire format and client-side parsing are covered in SSE wire format and Basic implementation on this page.
Conversations, actions, and Document Processing can stream a proposed modification as several modification-delta events. To join them, see Fragments in a stream.
SSE wire format
The response body is a text stream in Server-Sent Events format. Events are separated by blank lines. Each event can include an event: line (event name) and one or more data: lines (payload; long payloads may be split across several data: lines). For example:
event: <event-name-1> data: <data> event: <event-name-2> data: <data2>
In version 1.1 reply streams, events also carry an SSE event ID on an id: line. To resume the stream, record the ID of the last event processed. See Resumable reply streams.
Parsing this format correctly (including chunk boundaries, multi-line data: fields, and comments) is easy to get wrong in hand-written loops. For production code, use a maintained SSE parser such as the eventsource-parser package.
Resumable reply streams
Version 1.1 of the conversation message endpoints, under /v1.1, makes the reply stream more resilient. When replay is available for a reply, a client can:
-
Resume an interrupted reply with
GET /v1.1/conversations/{conversationId}/messages/{messageId}/stream. ThemessageIdcomes from themessage-metadataevent of the reply stream. SetlastEventIdto the ID of the last SSE event the client processed, or to0-0to replay the whole reply. -
Cancel a reply in progress with
DELETEon the same path. The stored message status becomescancelled. Resuming a cancelled reply ends with a finalerrorevent that closes the stream.
Some replies stream without replay support. The reply still streams, but the resume and cancel operations are not available for it. For the request that starts a version 1.1 reply, see Send a message (V1.1).
Basic implementation
After obtaining a streaming Response from fetch, pass the byte stream through an SSE parser. The following example uses eventsource-parser to turn raw chunks into parsed events. For each event, event.event is the event name from the event: line, and event.data is the JSON payload from the data: lines:
import { createParser } from 'eventsource-parser';
const response = await fetch('/v1/your-endpoint', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
// Request payload
})
});
const parser = createParser({
onEvent: (event) => {
// event.event is the SSE event name
// event.data is the reassembled data string for this event
// Some events, such as web-search and reasoning, have an empty data line
const payload = event.data ? JSON.parse(event.data) : null;
switch (event.event) {
case 'error':
console.error('Error:', payload?.message);
break;
default:
// Handle all other events — event names vary by API; see
// https://tinymceai.api.tiny.cloud/v1/docs for each operation's schema.
// Examples: Conversations (text-delta, source, reasoning, modification-delta),
// Reviews (review-delta, review-metadata), Actions (modification-delta, action-metadata)
console.log('Event:', event.event, payload);
}
}
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
parser.feed(decoder.decode(value, { stream: true }));
}
Error handling
A request that the service rejects before the stream opens returns an HTTP error status with the JSON body described in Error responses. Errors after the stream opens arrive as an error event.
Always handle errors gracefully:
if (event.event === 'error') {
const payload = JSON.parse(event.data);
console.error('Streaming error:', payload.message);
}
Progress tracking
Use metadata events to show progress. Event names and fields for review streaming are defined in the Reviews API operations that return SSE responses, not in the Review plugin overview.
API reference
The interactive API documentation describes streaming endpoints, event shapes, and errors for each feature area.
Next steps
-
Chat, Review, and Quick Actions for product behavior and editor integration.
-
AI Models for model configuration and limits.