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
-
The
queryfield is matched against registered patterns — string patterns are case-insensitive substring matches, RegExp patterns are tested as-is - First matching fixture wins, so register specific patterns before catch-alls
-
max_resultstruncates the matched fixture's results (when positive); unmatched queries return an emptyresultsarray -
Under strict mode (
--strict, orX-AIMock-Strict: trueon the request), an unmatched query returns503 no_fixture_matchinstead of an empty array -
An array
queryis joined with spaces for matching, and the response echoes the rawqueryvalue back unchanged
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
- Malformed JSON bodies are rejected with
400 -
A
querythat is neither a string nor an array is rejected with400 - A missing
querymatches against the empty string (usually a miss)
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.