stream to true. Every current model can stream. The examples use lume-3.5.
Use a client SDK to read the stream. The frames below are what that SDK is parsing, so you can also read them yourself.
Before you start
Create an API key in the dashboard withchat:completions for Chat Completions or messages:create for Messages. If your key has a model allowlist, include lume-3.5. Keep the key on your server and set it in the shell where you run the examples:
Authorization: Bearer or x-api-key. Supplying both with values returns HTTP 401.
For SDK examples, install the client you use. cURL examples do not need an SDK.
.py file. Save Node.js examples as .mjs files to use import and top-level await.
Messages accepts an optional anthropic-version header. If supplied, it must be one valid calendar date in YYYY-MM-DD form. It is a compatibility hint and does not change the supported features. The SDK supplies its version header automatically.
Chat Completions
POST /v1/chat/completions needs the scope chat:completions. The stream is server-sent events. Each frame is a data: line, a blank line, and then the next frame. The stream ends with data: [DONE].
choices[0].delta.content. The chunk that finishes the reply has an empty delta and finish_reason set to stop.
stream_options.include_usage to true. That field is only valid when stream is true. Content chunks then include "usage": null, and a later chunk has an empty choices array and the usage object:
include_usage out, and the chunks do not contain usage at all.
Once the stream has started, a failure is not a new HTTP status. You get an error object, then data: [DONE].
The model returned no visible assistant content and the code empty_model_response.
Messages
POST /v1/messages needs messages:create. Set stream to true. Each frame is an event: line, a data: line, and a blank line. This stream does not end with data: [DONE].
ping between events.
A text delta looks like this:
event: error frame with the Messages error body, and then the stream ends. That is not a new HTTP status. The body has error.type and error.message, and no error.code. An empty reply uses error.type api_error and the message The model returned no visible assistant content.
Stream tool calls and sources
For client function tools, Chat streams argument fragments inchoices[].delta.tool_calls. Accumulate them by tool-call index, then parse the assembled function.arguments JSON after the call is complete. Messages starts a tool_use block and streams input_json_delta fragments for that block’s index. Do not execute partial JSON arguments.
For server-side web search and web fetch, OverControl runs the work before emitting the result events. The connection can send SSE comment keepalives during that work. The returned answer then uses the normal protocol event shapes. This does not provide live token-by-token or per-operation progress while the web workflow runs.
Chat source annotations appear in choices[].delta.annotations as url_citation entries. Accumulate them alongside the text. Messages can return server_tool_use, search/fetch result blocks, and text citation events. Not every content block contains answer text.
With stream_options.include_usage: true, Chat’s final usage-only chunk has choices: []; never assume every chunk has choices[0]. Tool counters are under usage.server_tool_use.web_search_requests and web_fetch_requests. Messages reports these counters in the final message_delta usage. Token and tool rates are on Pricing.
Completion, errors, and cancellation
For text answers, Chatfinish_reason: "length" or Messages stop_reason: "max_tokens" means the output budget was reached. Tool calls finish with Chat tool_calls or Messages tool_use, and your application supplies the function results on the next request.
Errors before the stream begins use an ordinary HTTP error response. Missing or invalid credentials return HTTP 401, missing scopes return HTTP 403, and insufficient available usage returns HTTP 429. Once HTTP 200 and stream bytes have been sent, later failures arrive inside the stream. An SDK may raise an exception when it receives that error.
A raw SSE client must check error frames as well as terminal markers: Chat uses [DONE]; Messages uses message_stop. EOF alone is not proof of success. Preserve partial text for display if useful, but mark the response incomplete when an error arrives or the connection ends early. A completed answer can still be truncated by its output budget.
Close the SDK stream or abort the HTTP request when the user cancels. Do not keep reading a discarded response. Already completed model or tool work may still consume usage, and an interrupted connection may not deliver final usage to your client. Review account usage in the dashboard.
Lume 2 supports up to 16,384 output tokens; the other models support up to 32,768. Chat accepts one of max_tokens and max_completion_tokens, defaulting to the model maximum; Messages requires a positive max_tokens. Both APIs reduce the budget to the model maximum and remaining context space. The examples explicitly request 256 tokens. Keep X-Request-Id when reporting failures; Messages also returns request-id.
Next
Generate text
The same request without a stream.
Function calling
A streamed tool call arrives as its own deltas.

