Skip to main content
Receive generated text as it arrives over server-sent events (SSE). The same response delivers the saved document, with no polling required. Both endpoints require scribe:generate and an Idempotency-Key. Prepare the session’s input first. See Notes and Documents for request fields.

Open the stream

The response is 200 OK with Content-Type: text/event-stream. cURL’s --no-buffer displays events as they arrive. A typical sequence is:
Save returned event IDs as opaque cursors for reconnecting.

Handle each event

A consult-note request can contain several templates. Events can interleave, so maintain separate text and completion state for every document_id. Wait for an output.ready for every requested document before treating the whole request as successful. A closed connection alone does not establish success. output.ready includes the saved content and current_version. Use it for review and edits; no additional GET is needed. If the request reuses completed output, the stream may return output.ready immediately without any deltas. In that case job_ids may be empty.

Parse events on your backend

Use an HTTP client that supports streaming POST requests. Send the request body and authorization header, then parse the SSE response. Read complete SSE frames separated by blank lines. Parse each frame’s data as JSON and dispatch on its event field. A network chunk can contain half a frame or several frames. Parse JSON after assembling a complete frame. Preserve UTF-8 characters across chunk boundaries and ignore heartbeat comments beginning with :. Keep the latest event id after you apply that event.

Reconnect after a disconnect

Generation continues in the background when the connection closes. To observe the same work again:
  1. Send the same POST URL, body, grant, and Idempotency-Key.
  2. If you retained the applied partial text and its event cursor, send the cursor in Last-Event-ID to resume after it.
  3. If you lost that local state, omit Last-Event-ID and rebuild from the replay.
  4. Accept an immediate output.ready if the document completed while disconnected.
Keep a valid Partner JWT on reconnect; renew an expired JWT for the same grant. Do not create a new idempotency key just because the connection dropped.

Handle failures

Before the stream starts, authentication, validation, permissions, and other request errors use the normal HTTP status and JSON error body. Check the status and content type before parsing SSE. After 200 headers have been sent, a generation failure is reported through output.failed or generation.failed. Inspect failure_code; partial text is not a completed clinical document. A network error or EOF without the expected completion events calls for reconnecting or retrieving the document’s status. Replaying a failed operation does not start a fresh attempt. Resolve the failure and use a new operation key when intentionally requesting new generation.

Use a background job instead

For a backend workflow that does not need live text, add ?stream=false to either generation endpoint. This returns the 202 application/json receipt:
Poll the returned jobs and retrieve their documents as described in Jobs. Existing integrations that parse these generation responses as JSON must set stream=false. An Accept: application/json header alone does not select JSON mode. Custom-template responses, Ask AI, transcription, and coding retain their own processing flows. The stream option applies only to the two endpoints above.