Skip to main content
Need ultra-low latency output? Use stream_text - an async iterator that yields text deltas in real time.
1

Prepare the script

2

Run it

You’ll see tokens appear immediately instead of buffering the full response.
stream_text accepts the same arguments as generate_text plus optional callbacks:
  • on_chunk(delta) - each text delta
  • on_error(exc) - exceptions while streaming
  • on_finish(full_text) - once complete
stream_object is similar, but yields objects instead of text.
stream_text is similar, but yields objects instead of text.