Blog

Introducing WebSocket Responses

Mixlayer Team·June 25, 2026

The Responses API now works over WebSockets. Open one connection for a whole conversation, send only the new turn each time, and let Mixlayer keep track of what came before.

How it works

Connect to wss://mixlayer.ai/v1/responses with the same Bearer token you use for HTTP, and send a response.create message for each turn. The body is the same as POST /v1/responses, plus "type": "response.create". Within one socket, each completed response can be referenced by its ID with previous_response_id. On the next turn, Mixlayer rebuilds the earlier context from the socket's own store, appends your new input, and keeps generating.

STATELESS HTTP · EACH TURN RESENDS EVERYTHINGturn 1turn 2turn 3turn 4ONE WEBSOCKET · SEND ONLY THE NEW TURNturn 1turn 2turn 3turn 4response.create + previous_response_idearlier turns stay in the socket's memory
Over plain HTTP, every turn resends the whole conversation, so each request grows. Over one WebSocket, the client sends only the new turn and points at the last response with previous_response_id. The socket keeps the earlier context in memory.
import WebSocket from "ws";

const ws = new WebSocket("wss://mixlayer.ai/v1/responses", {
  headers: { Authorization: `Bearer ${process.env.MIXLAYER_API_KEY}` },
});

ws.on("open", () => {
  ws.send(JSON.stringify({
    type: "response.create",
    model: "qwen/qwen3.5-4b-free",
    input: "Count to five.",
  }));
});

ws.on("message", (data) => console.log(JSON.parse(data)));

What gets stored, and for how long

Storage is scoped to what you ask for:

The default suits real-time apps: fast, and gone when the connection closes. If you need history that outlives the socket, ask for it with store: true, and you can reference that response later from a new connection.

Under the hood, a previous_response_id lookup checks the current socket first and then the database. Each socket's store has limits on the number of responses, total message bytes and chain depth, so a long-lived connection can't grow forever. If an entry has been evicted, a later reference to it returns previous_response_not_found.

Streaming

Events follow the OpenAI and OpenResponses model. Text, function-call arguments and reasoning all arrive as typed events, ending with response.completed and the full final response.

A few rules to know: