Skip to main content
Streaming lets your application render the beginning of a model response while the model is still generating the rest. Planck uses the OpenAI-compatible Chat Completions stream format, so the OpenAI SDKs can consume the stream directly.
Keep your Planck API key on your server. If you are building a browser or mobile chat UI, stream from your own backend to the client instead of calling Planck directly from public code.

Stream with an SDK

Set stream: true, then iterate over the returned stream. Each chunk contains only the new delta; append each delta.content value to reconstruct the full answer.
The -N option tells cURL not to buffer the response, so each event appears as soon as it arrives.

Request and stream format

The request is a normal Chat Completions request with stream enabled:
Request
The response has a text/event-stream content type. Every data: line contains one JSON chunk, and a blank line separates events. The final data: [DONE] event closes the stream.
Response stream
Planck emits one usage-only chunk before [DONE]. Its choices array is empty, so read choices[0] defensively, as the SDK examples above do. The exact chunk boundaries are not stable: never assume that one chunk is one word or one complete JSON value from a tool call.

Read the stream without an SDK

Use an SDK when possible. If you need to consume the SSE response directly, remember that one network read can contain part of an event or several events. Buffer text until you have a complete blank-line-delimited SSE event.
Node.js fetch

Errors during a stream

There are two different failure points: Once the response headers have been sent, the HTTP status is already committed and can remain 200 even if generation later fails. SDK users should wrap stream creation and iteration in try/catch. Direct SSE consumers must inspect every decoded event for a top-level error object.
Error event
Do not automatically retry after displaying partial output unless your product can replace or discard that partial answer. Otherwise, users can see duplicated text.

Cancel a generation

Abort the request when the user presses Stop generating or leaves the page. Planck stops forwarding the stream and records the request as partial.
TypeScript

Production checklist

  • Render delta.content; do not wait for the final assembled message.
  • Treat chunks as arbitrary fragments and accumulate tool-call arguments before parsing them.
  • Handle the usage-only chunk with an empty choices array.
  • Handle errors from both the initial HTTP response and the open stream.
  • Support cancellation and expect cancelled streams to have partial usage.
  • Avoid retrying a stream after partial text is visible unless you reset the displayed answer.
  • Proxy browser requests through your backend so your API key is never exposed.

Chat & Responses

Compare Chat Completions, Responses, and Anthropic-compatible routes.

Chat Completions reference

See the complete request schema and supported parameters.

Error handling

Understand gateway errors, retries, and provider fallback.

Vercel AI SDK

Stream chat in applications built with the Vercel AI SDK.