GET /v1/responses to WebSocket. Confirm model, upstream, and channel support; the administrator must enable channel ResponsesWebSocketEnabled. Working HTTP Responses calls do not prove bidirectional support.
Runnable two-turn text example
Install dependencies and configure the environment using connection and runtime, then run:websocket-client.mjs alongside the copied script.
History, deltas, and completion
The example replays user messages and all raw output items, preserving encrypted reasoning, message phase, and extra metadata. It resends instructions each turn. The model must supportreasoning.encrypted_content; adapt to its protocol if needed rather than dropping returned reasoning state.
The receiver obtains the ID from response.created and correlates text by output_index / content_index / item_id. Responses text deltas do not guarantee response_id; the example checks it when present. The terminal object must match the current response and its text must equal collected deltas. Empty output, refusals, tool calls, and unfinished messages are rejected as text answers.
For previous_response_id, send new input and verify that upstream connection state is still available. Do not assume caches survive reconnects. Stateless recovery can replay full history or a compacted window, but the application must decide whether to resubmit. See the official WebSocket mode background.
Gateway and upstream capabilities differ
This project permits only one active generation per connection and locks the established model and channel. Do not import newer official promises of multiple stream_id lanes, queuing, or forks. Open a new connection to change models. Verify incremental continuation with the actual channel. Handshake and each create can fail as access, rate limits, or channel configuration changes. Warmup withgenerate: false and provider extensions are outside the example. stream and background are not WebSocket transport switches. Client tools need separate argument assembly, execution, result association, and recovery handling; this text example rejects tool output.
Cancellation and recovery
The API acceptsresponse.cancel controls for an active generation, but success depends on the upstream response. Correlate control errors separately from generation errors; sending cancel is not confirmation. The example sends no automatic cancellation. Closing after timeout does not guarantee a refund or upstream interruption.
Handshake, fields, and events · Troubleshooting
阅读中文