Web Search

The POST /search endpoint is a Tavily-compatible web search mock. Register fixture patterns on the LLMock instance and the request query is matched against them — first match wins, no match returns empty results.

Endpoint

Method Path Request Body Response
POST /search { "query": "...", "max_results": 5 } { "query": "...", "results": [...] }

How It Works

Unit Test: Search Fixture

search-fixture.test.ts ts
const mock = new LLMock();
mock.onSearch("weather", [
  { title: "Weather Report", url: "https://example.com/weather", content: "Sunny today" },
]);
await mock.start();

const res = await fetch(`${mock.url}/search`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ query: "weather today", max_results: 5 }),
});

const body = await res.json();
expect(body.results).toHaveLength(1);
expect(body.results[0].title).toBe("Weather Report");

Response Format

The response echoes the request query and carries the matched results:

Response shape json
{
  "query": "weather today",
  "results": [
    {
      "title": "Weather Report",
      "url": "https://example.com/weather",
      "content": "Sunny today"
    }
  ],
  "images": [],
  "response_time": 0,
  "answer": null
}

Validation

Journal Integration

Search requests are recorded in the LLMock journal with service: "search":

Journal entries typescript
const entries = mock.getRequests();
const searchRequests = entries.filter((e) => e.service === "search");

See also the Services overview, plus the sibling pages Rerank and Moderation.