Skip to content

Streaming

Streaming replies are restored as they arrive — placeholders are swapped back to the real values inside the token stream, so your users see ordinary streamed text.

stream = client.chat.completions.create(
model="gpt-4o-mini", messages=msgs, stream=True)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")

If a placeholder straddles a chunk boundary, Baati buffers it until the full placeholder is available, then emits the restored text.