Add a streaming chat feature to your app
The reference pattern for a production chat surface on top of Gateway.
- Create an edge function that calls the AI Gateway with streaming enabled.
- Wire the frontend to fetch with ReadableStream and render tokens as they arrive.
- Persist final assistant messages to Postgres, not partial streams.
- Add rate-limits per user via a Cloud function.
- Set a workspace credit cap so runaway loops can't drain your balance.