import openai
client = openai.OpenAI(
base_url="https://api.llm7.io/v1",
api_key="unused", # Use a https://dash.llm7.io/ token for higher limits.
)
stream = client.chat.completions.create(
model="fast", # or another model with stream: true from /v1/models
messages=[
{"role": "system", "content": "Answer concisely."},
{"role": "user", "content": "List three tips for fast Python scripts."},
],
stream=True,
temperature=0.4,
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)
Each chunk includes
choices[0].delta content. Watch choices[0].finish_reason to know when the stream ends. Use the Models API to find models with stream: true.