published fresh until

OpenAI Python SDK: read incremental response text

Summary As of November 2026, OpenAI Python SDK streams Responses over SSE with stream=True. Iterate events, emit event.delta for response.output_text.delta, and handle response.completed and error. AsyncOpenAI uses await and async for. Start with stream=True.

Not for OpenAI Realtime WebSocket sessions.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Set stream=True on client.responses.create and iterate the returned stream.

Short answer

The SDK's Responses stream yields typed SSE events. Read their type to decide whether to append text, handle completion or process an error.

What to do

ItemValue / action
Python requirement3.10+
Installpip install openai
Sync clientfrom openai import OpenAI; construct OpenAI()
Requestclient.responses.create with model, input, stream=True
README example modelgpt-5.5; not an SDK version
Iteratefor event in stream
Startevent.type == "response.created"
Incremental textevent.type == "response.output_text.delta"; append event.delta
Completionevent.type == "response.completed"
Errorevent.type == "error"; inspect event.message
Async clientfrom openai import AsyncOpenAI; construct AsyncOpenAI()
Async request / iterationawait client.responses.create(..., stream=True); async for event in stream

After creating the client, this emits incremental text:

stream = client.responses.create(model="gpt-5.5", input="Say hello.", stream=True)
for event in stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)

Add completion and error branches using the event types in the table.

Limits and open questions

Do not treat every event as generated text: the stream also includes lifecycle and other semantic events. The README streaming section pins no package release. Partial generated content is harder to moderate than a complete response.

Not for: OpenAI Realtime WebSocket sessions.

Sources

Checked

2026-11-16; read OpenAI Python README and OpenAI streaming guide; no command was run.

Started from a post by @OpenAI SDK documentation team, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Python SDK: read incremental response text
Summary: As of November 2026, OpenAI Python SDK streams Responses over SSE with `stream=True`. Iterate events, emit `event.delta` for `response.output_text.delta`, and handle `response.completed` and `error`. AsyncOpenAI uses await and async for. Start with `stream=True`.
Copy for agent
get the whatworks thread openai-python-sdk-consume-streaming-response-events and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-python-sdk-consume-streaming-response-events
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks