Developers

Stream a chat turn (SSE)

Send a user message to an existing chat and stream the assistant's reply as Server-Sent Events.

POST/chats/{chatId}/stream/

Send a user message to an existing chat and stream the assistant's reply as Server-Sent Events.

The response is text/event-stream (not the standard JSON envelope). Each event is a frame of the form event: <type> followed by a camelCase JSON data: payload. The connection stays open for the whole assistant turn and closes when the turn ends.

Event types (see the 200 response examples for full payloads):

  • message.start / message.content / message.stop: the assistant message lifecycle and its streamed text chunks.
  • conversation.offtopic: the message was classified as off-topic.
  • conversation.end: the assistant ended the conversation (reason explains why).
  • guardian: a safety condition was detected; guardianId is stable.
  • error: a recoverable error such as rate limiting; may include retryAfterSeconds.
  • skill_code.cta: an end-of-flow call to action (e.g. see a Doctronic doctor, or book an in-person visit); carries skillCode, widget, and an optional text label.
  • ai_consultation.complete: consultation completion with document IDs. Document retrieval can still return 202 while generation finishes.

Event compatibility: Published event names are stable wire identifiers. New event names may be added. A replacement will be introduced additively and the old name explicitly deprecated; published names will not be silently renamed. Consumers should ignore event names they do not recognize.

Request body

  • userEvent: the user message: type user_message, userInput, and optional messagePromptContext (up to 50,000 characters) with situational context for this turn.
  • timezone: optional IANA timezone (default UTC); an invalid value returns 400.

The chat must have been created through this Doctronic API and belong to both the authenticated organization and user; otherwise it is masked as 404 error.partner.chat_not_found.

Auth: organization Bearer token + X-Doctronic-User-ID header (both required).

Authorization

HTTPBearer XDoctronicUserID
AuthorizationBearer <token>

In: header

X-Doctronic-User-ID<token>

Doctronic user ID returned as data.id by POST /users/. This value identifies the user in your organization scope; it is not an API token.

In: header

Path Parameters

chatId*string

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

text/event-stream

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/chats/string/stream/" \  -H "Content-Type: application/json" \  -d '{    "userEvent": {      "userInput": "string"    }  }'

Eventmessage.start
Data payload
{  "type": "message.start",  "role": "assistant",  "messageId": "ac_hist_01K6JGGM2G2DB4Y9KB9H9MJJ6Q",  "messageTimestamp": 1741856873000}
View raw SSE frame
Raw frame
event: message.startdata: {"type":"message.start","role":"assistant","messageId":"ac_hist_01K6JGGM2G2DB4Y9KB9H9MJJ6Q","messageTimestamp":1741856873000}