xAI has introduced a new WebSocket mode for its Responses API, intended to support lower-latency interactions, particularly for agentic workloads. This feature allows developers to use a persistent WebSocket connection to /v1/responses instead of initiating a new HTTP request for each turn in a conversation.
Key Points
- The new WebSocket mode is available for the Responses API.
- It utilizes a single, long-lived WebSocket connection to
/v1/responses. - Subsequent turns after the first response only require sending new input items and a
previous_response_id. - The server maintains prior state in memory on the open socket.
- This mode is compatible with Zero Data Retention (ZDR) and
store=falsesettings. - It is specifically designed for agentic workloads that involve numerous sequential tool calls.
- Internal benchmarks by xAI showed up to 20% lower end-to-end latency for agentic workloads with many tool calls, compared to repeated HTTP requests using
previous_response_idchaining.
Context
According to xAI, the WebSocket mode addresses the overhead of connection setup and re-sending full conversation histories in long interactions. By maintaining an open socket and only transmitting new input items, the system aims to optimize performance for conversational agents and orchestration loops that engage in dozens of back-and-forth exchanges with the model.
Why It Matters
This update offers builders a method to decrease latency and improve efficiency for applications requiring extensive, rapid interactions with xAI's models, such as coding agents or complex orchestration systems. The reported latency reduction could translate to more responsive and fluid user experiences in these demanding scenarios.
What To Do
- Review the xAI documentation on WebSocket Mode for implementation details.
- Test the WebSocket mode with existing agentic workloads to evaluate latency improvements.
- Compare the performance of WebSocket connections against traditional HTTP requests for tool-call-heavy applications.
- Note the requirement to send
response.createmessages after the WebSocket upgrade.
