Fluxio
← Back to the blog

Anthropic SSE Streams: Live Replies from Start to Stop

SSE & APIsEN

§1 Anthropic SSE streams deliver a reply in pieces

A streaming response lets your application show an answer while the model is still generating it. Instead of waiting for a complete message, your server receives a sequence of events and updates the screen as useful content arrives. This makes real-time chat feel responsive, especially when an answer takes several seconds to finish.

Anthropic uses server-sent events, or SSE, for streaming responses from its Messages API. Enable streaming in your request with the stream field set to true. The response then carries named events with JSON data. Think of these events as instructions for assembling one assistant message, not as separate chat messages.

§2 message_start establishes the assistant message

The first message event is message_start. It contains a message object with identifying information, the assistant role, model information, and initial usage data. Its content array starts empty because the actual content will arrive through later events.

Use this event to create the assistant message in your application state. You can stop showing a waiting indicator and prepare a place for incoming content. Do not treat the initial usage values or empty content as the finished response.

§3 Content block events build text and tool requests

An assistant message can contain multiple content blocks. Each block has an index that tells you where it belongs. The standard lifecycle is content_block_start, followed by content_block_delta events, and then content_block_stop.

  • – content_block_start introduces a block and identifies its type, such as text or tool_use.
  • – content_block_delta supplies an incremental update associated with that block index.
  • – content_block_stop marks that individual block as complete, not the entire assistant message.

For ordinary text, a text_delta contains a text fragment to append. These fragments are not guaranteed to match individual tokens, words, or sentences. A chunk might contain half a word or several words. Append the text exactly as received instead of inserting extra spaces between chunks.

For a tool request, input_json_delta events carry partial JSON strings. Accumulate these fragments for the relevant block and parse the assembled JSON once the block is complete. A fragment may be invalid JSON on its own. Only execute a tool after its input is complete and your application has validated and authorized the action.

§4 message_delta and message_stop finish the reply

After the content blocks, message_delta updates message-level information, including the stop reason and output usage. Output token counts reported in these updates are cumulative, so do not add them together as if each event were a separate billable increment.

The stop reason helps determine your next action. An end_turn reason means the assistant finished its turn. A tool_use reason means it is handing control to your application to handle a tool request. A max_tokens reason means the output reached its configured limit and may be incomplete.

Finally, message_stop marks the end of the assistant message. A stopped content block is not enough to declare success, and a closed network connection without this event should not automatically count as a completed reply.

§5 SSE parsing must handle pings and interruptions

Network chunks do not necessarily line up with SSE events. Use an SSE-aware parser that buffers incoming bytes and recognizes complete event boundaries before parsing their JSON payloads.

You may also receive ping events, which carry no answer text, or error events after streaming has begun. Handle errors explicitly, preserve partial output when useful, and offer a deliberate retry path. Keep your event handler tolerant of unfamiliar event types rather than crashing when the protocol evolves.

§6 Fluxio fits streaming apps with multiple providers

Fluxio is worth considering when you want a streaming-first, pay-per-token relay with one API key across multiple providers. Its OpenAI-style clients use the base address https://api.fluxioapi.com/v1.

Keep the protocol distinction clear: an OpenAI-style stream is not the same event format as an Anthropic Messages stream. Verify the interface your integration uses, and build your parser for that interface rather than expecting message_start and message_stop on every streaming endpoint.

Sign up for Fluxio to build your next streaming AI experience.

Create a Fluxio account →

More from the current