Build garageTry it → read → next · ~9 min

Tutorials · Chapter D (4/4) · ~9 min

Streaming responses

Try it → see it → read → next

Show tokens as they arrive — `stream=true` for snappier chat UX.

On paths: Builder · Student

Try yourself

Playground

Streaming tokens

Stream shows tokens as they arrive — better UX for long replies.

Assistant

Recap

What you just did

You watched tokens arrive one chunk at a time — time-to-first-token matters.

Teach

How it works

With streaming APIs:

  1. Open a long-lived response
  2. Append each delta to the UI
  3. Stop when the stream ends

Server still holds the API key. Frontend shows partial text + cursor.

Use it

When you'd use this

  • Chat UIs, long summaries, code generation
  • Anywhere users would otherwise stare at a spinner

Watch out

Watch out

Harder to log complete replies until stream finishes. Handle disconnects and timeouts.

Try next

Try this next

How-to: call OpenAI with streaming