Streaming Chat

Stream tokens in real-time for a typing effect.

from openai import OpenAI
client = OpenAI(api_key="KEY", base_url="https://api.aipilotads.com/v1")
stream = client.chat.completions.create(model="gpt-5.5", messages=[{"role":"user","content":"Write a poem"}], stream=True)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")