OpenAI Responses WebSocket
Enabled by default on local, dev, and beta. On latest and prod, set OPENCODE_EXPERIMENTAL_WEBSOCKETS=true.
Flow
- A streamed
POST /responsesrequest arrives. - If it has no
session-idorx-session-affinityheader, use HTTP. - Title requests use HTTP.
- If that session's socket is busy or already in fallback mode, use HTTP.
- Otherwise, reuse its open socket or open a new one.
- Send
response.createand return WebSocket events as SSE.
Lifetime
- Connect timeout: 15 seconds.
- Idle timeout: 5 minutes.
- After a completed response, keep the socket for reuse.
- Reuse a socket for up to 55 minutes, then replace it on the next request.
Retries
- If WebSocket setup fails or it fails before its first event, replay over HTTP and keep that session on HTTP until idle-pruned.
- If the server returns
websocket_connection_limit_reachedbefore output, reconnect up to 5 times, then follow the same HTTP fallback. - If a WebSocket fails after its first event, fail the stream. Do not replay partial output.
- Abort or cancel closes the socket.
Next Steps
previous_response_idcontinuation.- Optional second WebSocket for concurrent requests in one session. Currently these use HTTP.