Streaming
SSE streaming for lower time-to-first-token and a better UX.
Enabling it
Set "stream": true in the request body. The response is text/event-stream, delivering delta.content chunk by chunk and terminating with [DONE].
# pip3 install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("AIGATEWAY_API_KEY"),
base_url="https://api.aigateway.ltd/v1",
)
resp = client.chat.completions.create(
model="auto", # or pin one: "deepseek-flash" / "qwen-max"
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
)
for chunk in resp:
print(chunk.choices[0].delta.content or "", end="")Timeout guidance
- Client read timeout ≥ 300s for long generations
- Heartbeat: the gateway emits a comment line every 15s so proxies don't drop the connection
- Disable buffering at the nginx/CDN layer (proxy_buffering off)