← Back to Journal
· 3 min read

Your site needs a search endpoint for AI agents

Four sites, 619 pages, one JSON index built at deploy time. How we expose .well-known/search so agents ask instead of crawling, and the three bugs it exposed.

TL;DR

TL;DR — An AI agent answering a question about your site has to crawl it, read twelve pages,
and hope it kept the right passage. You can hand it a search endpoint instead: one build-time JSON
index and a /.well-known/search?q= route that returns Markdown passages with scores. We shipped it
on four sites — 619 pages, 3.2 MB of index, about one second per query, no per-query fee. The hard
part was not the ranking; it was keeping navigation chrome out of the excerpts.

A question about your site arrives at an AI agent. Today the agent does the only thing it can: crawls your sitemap, fetches page after page, and reconstructs an answer from whatever it happened to read. For our sites that is 619 pages per question, most of them irrelevant.

We gave it a shorter path. Every page now advertises a search endpoint:

<meta name="agent:instructions" content="Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown.">
<meta name="agent:endpoint" content="https://zens.ink/.well-known/search/?q={query}">
<meta name="agent:method" content="GET">

And the endpoint answers with passages, not a page:

$ curl "https://zens.ink/.well-known/search/?q=content%20brief&limit=2"

# Search results for: "content brief"

## /zh/journal/content-brief-generator/ (score: 1.000)
# 内容简报:告别空白页的免费生成器 + 模板 · ZensInk
Section: 生成器:从排名数据构建简报
...

One call, two candidate passages, each with a path and a score. The agent can stop crawling.

What the index actually is

No vector database, no embedding API, no vendor. During the build we walk the generated HTML, keep only the article container, split it at <h2> boundaries, and cap each chunk at 800 characters with a maximum of eight chunks per page. The result is a JSON file that ships with the deploy.

SitePagesChunksIndex
zens.ink2051,3771.1 MB
theonchaindiary.com2311,6691.5 MB
jask.dev144446446 KB
howgeo.net39180114 KB

Ranking is BM25’s shape without the ceremony: term frequency times inverse document frequency, a small bonus when the term appears in the title area, Chinese split into bigrams, Latin words also split on . and - so that llms.txt matches a query for llms. Measured over five queries per site, responses landed between 0.5 s and 2.2 s cold, around 1 s typical. The static JSON never leaves the deploy; a Pages Function (or an Astro server route on the one site that needs it) reads it and answers.

Three bugs worth stealing

Navigation leaked into every excerpt. The first version stripped <nav> and <footer> and still returned “Skip to content · More · Tools · Contact” in front of the answer. The fix was to extract <article> when present, <main> otherwise, and only fall back to the whole body as a last resort.

HEAD requests returned HTML. The handler exported only onRequestGet; a HEAD fell through to static asset serving and came back as a page with a 200. One line — export const onRequestHead = onRequestGet — and the endpoint behaves under both methods.

A middleware branch shadowed the route. On the Astro site we had added an early middleware handler for the same path. Requests never reached the route file, so the logging and the response headers were silently missing; the endpoint looked fine and did nothing. If a response header you set never appears, the code did not run — check what runs before your route.

What we deliberately left out

The Onchain Diary has 474 glossary entries. Each is short, highly templated, and would have quadrupled the index for passages that mostly restate a definition. They are excluded, and a query for “what is a wallet drainer” goes to the long article instead. Exclusion is a real editorial decision, not a build flag: an index is only as good as what you keep out of it.

What this does not tell you

We cannot yet show agent traffic. The query log table has a few dozen rows and every one of them is our own test probe, so the honest statement is “the endpoint exists and answers correctly”, not “agents are using it”. Whether an assistant prefers a search API over crawling is decided by assistants, not by us.

Two more limits: the ranking is lexical, so a question phrased with synonyms your page never uses will miss — embeddings would help and would also cost money and a rebuild pipeline; and none of this changes how Google or Bing index the site. A search endpoint is for agents that are already on the page, not a substitute for the crawler.

If you want the cheap version: build the index from the HTML you already ship, put it behind one route, advertise it in three meta tags, and log every query so that in a month you can answer “did anyone actually use this” with data instead of hope.

FAQ

Do AI agents actually use a .well-known/search endpoint?
There is a published convention — meta tags named agent:instructions, agent:endpoint and agent:method that point at a Markdown search API — and Cloudflare now advertises the same shape from its AI Search product. Agent support is still thin, so treat it as a cheap bet rather than a traffic source: you ship it at build time and measure whether anything queries it.
How is this different from llms.txt?
llms.txt is a map: a curated list of the pages worth reading. A search endpoint is a lookup: the agent sends a question and gets back the two or three passages that match, already chunked. They solve different problems and both are static files, so ship both.
Can you do this without Cloudflare AI Search or another paid index?
Yes, and we did. The index is generated during the build from the HTML you already produce, stored as static JSON next to the deploy, and queried by a Pages Function (or an Astro server route). There is no ingestion bill and no query bill; the only cost is a few hundred KB of static files.

Want to run this analysis on your own site?

ZensInk Pro automates this pipeline. One command, from seed keywords to content plan.

Get Pro →