OpenAI Responses API
The Responses API uses event: + data: SSE format over HTTP, and
is also available over WebSocket. llmock supports both transports with the same fixtures.
Endpoints
| Method | Path | Format |
|---|---|---|
| POST | /v1/responses | HTTP SSE (event: + data:) |
| WS | /v1/responses | WebSocket JSON messages |
Unit Test: HTTP SSE Text Response
responses-text.test.ts ts
import { createServer, type ServerInstance } from "@copilotkit/llmock/server";
const instance = await createServer([
{ match: { userMessage: "hello" }, response: { content: "Hi there!" } }
]);
const res = await post(`${instance.url}/v1/responses`, {
model: "gpt-4o",
input: [{ role: "user", content: "hello" }],
});
// Parse event: + data: SSE format
const events = res.body.split("\n\n")
.filter(b => b.includes("event: ") && b.includes("data: "))
.map(b => ({
type: b.match(/^event: (.+)$/m)[1],
data: JSON.parse(b.match(/^data: (.+)$/m)[1]),
}));
const types = events.map(e => e.type);
expect(types).toContain("response.created");
expect(types).toContain("response.output_text.delta");
expect(types).toContain("response.completed");
Unit Test: Tool Call Response
responses-tools.test.ts ts
const instance = await createServer([
{
match: { userMessage: "weather" },
response: {
toolCalls: [{ name: "get_weather", arguments: '{"city":"NYC"}' }]
}
}
]);
const res = await post(`${instance.url}/v1/responses`, {
model: "gpt-4o",
input: [{ role: "user", content: "what is the weather?" }],
});
const events = parseTypedSSE(res.body);
const types = events.map(e => e.type);
expect(types).toContain("response.function_call_arguments.delta");
expect(types).toContain("response.output_item.done");
SSE Event Sequence
The Responses API uses typed events. A text response produces this sequence:
response.createdresponse.in_progressresponse.output_item.addedresponse.content_part.addedresponse.output_text.delta(one per chunk)response.output_text.doneresponse.content_part.doneresponse.output_item.doneresponse.completed
Tool call responses follow the same pattern but use
response.function_call_arguments.delta and
response.function_call_arguments.done events.
The same fixtures work for both HTTP SSE and WebSocket transports. See the WebSocket APIs page for WebSocket-specific details.