
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.
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.
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)));Storage is scoped to what you ask for:
store omitted or null: the response is kept in memory for as long as the socket is open, and nowhere else.store: true: Mixlayer saves the response durably and also keeps a copy in the socket, so the next turn doesn't need a database read.store: false: nothing is kept.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.
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:
background on a WebSocket request.store: true response can't continue from a response that only exists in the socket's memory.