Responses WebSocket

Use progrok's typed client to connect directly to wss://api.x.ai/v1/responses with the server-side bearer. The localhost HTTP server does not accept WebSocket upgrades.

Typed session

// connectResponsesWebSocket is exported by src/surfaces/index.ts.
const session = await connectResponsesWebSocket();
await session.send({
  type: "response.create",
  model: "grok-4.6",
  input: "Summarize this change",
});

for await (const event of session.events()) {
  if (event.type === "text_delta") process.stdout.write(event.text);
  if (event.type === "done" || event.type === "incomplete") break;
}
await session.close();

This is a repository source-level client used by progrok itself. The current npm artifact is a CLI bundle rather than a separately exported SDK package.

Lifecycle and rules

open -> response.create -> typed deltas -> done|incomplete|error
  • Requests are processed serially on one connection. Do not send stream or background.
  • The first terminal event wins; EOF alone is not success.
  • Mid-stream failures are surfaced and never replayed automatically.
  • The upstream connection lifetime is limited to 25 minutes.
  • Handle previous_response_not_found and websocket_connection_limit_reached.