DEV Community

Cover image for Cloudflare Just Gave Every Website a Search Endpoint for AI Agents. Here Is One in 34 Lines of Python
Neeraj Sharma
Neeraj Sharma

Posted on AI-assisted

Cloudflare Just Gave Every Website a Search Endpoint for AI Agents. Here Is One in 34 Lines of Python

On November 25, Cloudflare launched Search for Agents. One toggle in the dashboard, and Cloudflare indexes your website and puts a search endpoint on your own domain at /.well-known/search. Agents stop crawling your pages one by one. They ask your site a question and get back the matching content as Markdown.

A few details from the launch worth knowing:

  • Cloudflare adds metadata to the <head> of every page: instructions for agents, the endpoint, the HTTP method and a link to the docs. Agents find the search box on their own.
  • Results come back as Markdown, because the agent already has a model and a conversation going. The only thing it is missing is the right part of your site.
  • It supports the new HTTP QUERY method, an IETF Proposed Standard (RFC 10008) since June 2026. The search goes in the request body, and nothing changes on the server. curl already supports it.
  • It is on every plan, free included (with limits), billed at AI Search rates. Under the hood it is a normal AI Search instance, so you can also turn on REST or MCP access.

You don't need Cloudflare to get the idea, though. The pattern is small enough to build yourself, which is the best way to understand what an agent will actually see. Here it is in 34 lines of Python, standard library only.

The pattern

agent  --->  GET   /.well-known/search?q=refund+webhook
       --->  QUERY /.well-known/search   {"q": "how much is the pro plan"}
             |
             |  1. index of your pages (rebuilt on every publish)
             |  2. rank pages against the question
             |  3. return the top few as Markdown, each with its source URL
             v
       <---  ## Refunds
             Source: /docs/refunds
             Refunds within 30 days...
Enter fullscreen mode Exit fullscreen mode

The code

import json, math, re
from collections import Counter
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs

PAGES = [  # in production: your sitemap, crawled and refreshed on publish
    {"url": "/pricing", "title": "Pricing", "text": "Starter plan is $29 a month. Pro is $99 a month with API access and SSO."},
    {"url": "/docs/webhooks", "title": "Webhooks", "text": "Send order.created and order.paid events to your endpoint. Retries for 24 hours."},
    {"url": "/docs/refunds", "title": "Refunds", "text": "Refunds within 30 days. Use the refunds API or the dashboard. Webhook order.refunded fires."},
]
words = lambda s: re.findall(r"[a-z0-9$.]+", s.lower())
DOCS = [Counter(words(p["title"] + " " + p["text"])) for p in PAGES]
DF = Counter(w for d in DOCS for w in d)

def search(q, k=3):
    scores = []
    for page, tf in zip(PAGES, DOCS):
        s = sum(tf[w] * math.log(1 + len(PAGES) / DF[w]) for w in words(q) if w in tf)
        if s: scores.append((s, page))
    hits = sorted(scores, key=lambda x: -x[0])[:k]
    return "\n\n".join(f"## {p['title']}\nSource: {p['url']}\n\n{p['text']}" for _, p in hits) or "No results."

class Handler(BaseHTTPRequestHandler):
    def _answer(self, q):
        body = search(q).encode()
        self.send_response(200); self.send_header("Content-Type", "text/markdown; charset=utf-8")
        self.send_header("Content-Length", str(len(body))); self.end_headers(); self.wfile.write(body)
    def do_GET(self):  # GET /.well-known/search?q=refund+webhook
        u = urlparse(self.path)
        if u.path != "/.well-known/search": return self.send_error(404)
        self._answer(parse_qs(u.query).get("q", [""])[0])
    def do_QUERY(self):  # QUERY method (RFC 10008): the search goes in the body, nothing changes on the server
        if urlparse(self.path).path != "/.well-known/search": return self.send_error(404)
        n = int(self.headers.get("Content-Length", 0))
        self._answer(json.loads(self.rfile.read(n) or b"{}").get("q", ""))

if __name__ == "__main__":
    HTTPServer(("127.0.0.1", 8787), Handler).serve_forever()
Enter fullscreen mode Exit fullscreen mode

Run it and ask it two questions, one with GET and one with QUERY:

curl "http://127.0.0.1:8787/.well-known/search?q=refund+webhook"

curl -X QUERY http://127.0.0.1:8787/.well-known/search \
  -H 'content-type: application/json' -d '{"q":"how much is the pro plan"}'
Enter fullscreen mode Exit fullscreen mode

Output:

## Refunds
Source: /docs/refunds

Refunds within 30 days. Use the refunds API or the dashboard. Webhook order.refunded fires.
----
## Pricing
Source: /pricing

Starter plan is $29 a month. Pro is $99 a month with API access and SSO.

## Refunds
Source: /docs/refunds
...
Enter fullscreen mode Exit fullscreen mode

Python's http.server calls do_<METHOD> for any method name, so supporting QUERY is just one more handler.

What each piece is doing

A stable address. /.well-known/ is the standard place for machine-readable site info (security.txt, openid-configuration). An agent that knows the convention can try it on any domain without being told.

Markdown, with sources. Every hit carries its URL. The agent can quote you and send the user to the right page, which is exactly what you want when an AI answers a question about your product.

Ranking. This uses a tiny TF-IDF score so the demo has no dependencies. Cloudflare's version runs on AI Search, so natural-language questions work too. In your own build, swap search() for BM25, embeddings or a hybrid of both. The interface stays the same.

QUERY for long questions. Agents ask long, messy questions. Putting them in a URL hits length limits and leaks into logs. QUERY puts them in the body while staying safe and repeatable, like GET.

Freshness. PAGES is hardcoded here. In production, rebuild the index on every publish so an agent never quotes last month's price.

Before you turn it on in production

  • Decide what is searchable. Anything indexed can be quoted. Leave out staging pages, internal docs and anything behind a login.
  • Rate limit it. Cloudflare notes that agents often hit the endpoint several times in one session. Budget for that.
  • Log the questions. The queries agents send are free product research: they tell you what people ask about you that your pages don't answer.
  • Test it like an agent. Ask your endpoint the ten questions customers ask your sales team, and read the Markdown that comes back.

Search for Agents is one more sign that websites now have two audiences: people, and the agents working for them. Making your product easy for agents to find and quote is quickly becoming part of shipping it.

At Axionry, an AI product development studio, we build agent-ready products like this, from search endpoints and MCP servers to the AI agents that use them, and we ship in weeks. If you want your product ready for agents, book a call.

Sources

Top comments (0)