Getting Started
Streaming query responses
Consume SSE events and resume the same query after a disconnect.
Set stream: true in POST /v2/chat and authenticate with the channel API key. The response uses Content-Type: text/event-stream.
curl --no-buffer 'https://api.mu.chat/v2/chat' \
--header 'Authorization: Bearer YOUR_CHANNEL_API_KEY' \
--header 'Content-Type: application/json' \
--data '{"query":"Hello!","external_message_id":"message-001","stream":true}'| Event | Meaning |
|---|---|
CUSTOM | name: muchat.api.message.accepted.v1; value contains conversation and message IDs. |
RUN_STARTED | Reply generation has started. |
TEXT_MESSAGE_START | Starts an assistant message or text part. |
TEXT_MESSAGE_CONTENT | Append delta to the matching messageId / partId. |
TEXT_MESSAGE_END | Ends that message or text part. |
RUN_ERROR | Generation error; inspect code and message. |
RUN_FINISHED | Final authoritative response is in result. |
Each event's JSON is in data. Ignore heartbeat comments. Preserve SSE id values. On disconnect, resend the original body and external_message_id, with the last received ID in Last-Event-ID. Only stream may change. If conversation_id was omitted in the first request, omit it on retries too.
A replay may omit already delivered text deltas. Use the final result even when no new deltas arrive. A stream without RUN_FINISHED is incomplete, and HTTP 200 alone does not mean generation succeeded. Check the final finish_reason or error result before reporting success.
See the complete Node.js and Python streaming examples for parsing, reconnecting and handling suppressed or failed replies.