The stream stops prematurely and cuts off mid-sentence.
Why this happens
A null finish reason is normal on intermediate streaming chunks. Inspect the final chunk: length indicates an output limit, while a stream that closes without a final reason can indicate an interrupted connection. Increasing the token budget only addresses a confirmed output-limit case.
Answer 1: Increase max_tokens to accommodate full responses
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Write a story"}],
max_tokens=2048,
stream=True
)
Reference: OpenAI streaming response fields.
