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:

  1. response.created
  2. response.in_progress
  3. response.output_item.added
  4. response.content_part.added
  5. response.output_text.delta (one per chunk)
  6. response.output_text.done
  7. response.content_part.done
  8. response.output_item.done
  9. response.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.