Connect
Connect to a persistent Responses API WebSocket. Send response.create events to create responses and response.steer events to queue user input containing text, images, or files for a continuation. Receive response stream events and steering acceptance, pending, or failure events over the socket.
WebSocket wss://api.openai.com/v1/responses
Connect
import asyncio
from openai import AsyncOpenAI
async def main():
async with AsyncOpenAI() as client:
async with client.beta.responses.connect(
extra_headers={"OpenAI-Beta": "responses_multi_agent=v1"}
) as connection:
await connection.response.create(
model="gpt-6-astra", input="Say hello in one sentence."
)
async for event in connection:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.completed":
print()
return
elif event.type in ("response.failed", "response.incomplete"):
raise RuntimeError(f"Response ended: {event.type}")
elif event.type == "error":
raise RuntimeError(event.error.message)
raise RuntimeError("Connection closed before the response completed.")
asyncio.run(asyncio.wait_for(main(), 60))