AI Search API: How to Add Real-Time Search to Your Agent
Language models are frozen at their training cutoff. This is how you give yours a way to look things up - in about ten minutes, with two HTTP calls and no SDK to install.
Why your agent cannot answer "what happened this week"
A language model knows what was true when it was trained. It does not know what is true now. That is fine for "explain gradient descent" and useless for "what did the FOMC decide on Tuesday", "is the new API in beta yet", or "who won the election in the country whose capital moved last year".
So an agent that answers questions about the present needs a search tool. Most teams start with a browser-search API, paste the snippets into the prompt, and discover three problems a few weeks later:
- They fetch too much. A snippet is not always enough, but the full text of ten pages is usually more than the model needs - and every one of those characters is billed to your model provider.
- They cannot tell a summary from a page. Once the text is in the prompt, the model cannot cite what it read. It cites what looks plausible.
- They cannot see how much it cost. Search calls, page reads and model tokens end up on three different invoices, and nobody can attribute a month's bill to a single feature.
AgentSearch exists to make those three problems explicit: Search finds the pages, Fetch reads the one you decide is worth reading, and the two are metered separately so you can see exactly what each step cost.
What you need
- Python 3.9+ (or any language - it is plain HTTP), or JavaScript/TypeScript
- An API key - the Free plan includes 100 searches and 20 page fetches per month, no card
- An agent, or a script that stands in for one
There is no SDK to install. AgentSearch is a JSON API, and calling it is requests.post or fetch. That is a deliberate choice: a thin HTTP surface has no version to keep in sync with your agent framework, and it works the same from a Python script, a Rust service, or a Cloudflare Worker.
Step 1: get a key
Create a key in the dashboard. It is shown once, at creation, together with an integration guide you can paste straight into your agent's system prompt. The base URL for the API is:
https://agentsearch.tech/v1
Every endpoint is also mounted under /api/v1, so /v1/search and /api/v1/search are the same endpoint. Use whichever your client library finds more natural.
Step 2: search
One call returns the pages, already summarised, scored and sorted:
curl -X POST "https://agentsearch.tech/v1/search" \
-H "Authorization: Bearer $AGENTSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "What did the FOMC decide in November 2026?", "limit": 5}'
In Python:
import os, httpx
API_KEY = os.environ["AGENTSEARCH_API_KEY"]
BASE = "https://agentsearch.tech/v1"
def search(query: str, limit: int = 5) -> dict:
response = httpx.post(
f"{BASE}/search",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"query": query, "limit": limit},
timeout=45,
)
response.raise_for_status()
return response.json()
result = search("What did the FOMC decide in November 2026?")
print(result["total_results"], "results in", result["latency_ms"], "ms")
print(result["structured_markdown"])
The response is a flat JSON object - there is no envelope to unwrap:
{
"query_id": "search_e6bb86e4b7ed",
"intent": "news",
"results": [
{
"title": "...",
"url": "https://...",
"content": "The summary of the page.",
"snippet": "The first 300 characters.",
"source": "web",
"quality_score": 0.89,
"published_date": "2026-11-18T00:00:00+00:00",
"authority": 3,
"rerank_score": 2.4,
"site_name": "Example News"
}
],
"total_results": 5,
"structured_markdown": "# Search Results for: ...",
"total_tokens": 2117,
"latency_ms": 443,
"cached": false,
"sources_used": ["web"],
"unavailable_sources": []
}
Two fields matter more than the rest. structured_markdown is the same results rendered for a prompt - drop it in and you are done. quality_score is a 0-1 score for the page, and it is what lets your agent skip the SEO sludge: filter on quality_score >= 0.75 and you usually keep the primary sources and drop the listicles.
Step 3: read the page you actually need
The summary is the right default. When your agent needs to quote a page verbatim, or the summary is too thin to answer from, read the page itself:
def fetch(url: str, max_chars: int = 20000) -> dict:
response = httpx.post(
f"{BASE}/fetch",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"url": url, "max_chars": max_chars},
timeout=45,
)
response.raise_for_status()
return response.json()
page = fetch(result["results"][0]["url"])
print(page["title"], "|", len(page["text"]), "characters")
The page is read on our servers, not by your model provider, and it comes back as text. A fetch is counted against the fetch allowance, which is separate from the search allowance: reading four pages does not use up four searches, and running four searches does not use up four fetches.
A practical loop looks like this:
def answer(question: str) -> str:
hits = search(question, limit=5)["results"]
# Read only the pages that look worth reading.
good = [h for h in hits if h["quality_score"] >= 0.75][:2]
if not good:
return hits[0]["structured_markdown"] # summaries are enough
bodies = [fetch(h["url"])["text"] for h in good]
return "\n\n".join(bodies)
Step 4: make the query sharper
The query is passed to the search service as it is, so it understands operators. These are worth learning, because they turn a fuzzy question into a precise one:
| Operator | Example | What it does |
|---|---|---|
site: | swift site:github.com | Only pages on that site. Join several with OR. |
-site: | swift -site:medium.com | Exclude a site. |
lang: | open source license lang:de,en | Only these languages. |
after: | model release after:2026-01-01 | Only pages published after the date. |
before: | model release before:2026-06-01 | Only pages published before the date. |
"..." | "context window" | The exact phrase. |
- | pricing -enterprise | Exclude a word or phrase. |
Two more parameters are worth knowing. ori_question is the user's original question when it is longer than the query - the search service reads it to work out the intent. localization is an IP address whose region the results should be localised for.
Step 5: handle the errors honestly
The failure modes are worth knowing before you hit them in production:
- 400 - the request was rejected, and the message says which field. Common cause: a query longer than 128 characters.
- 401 - the key is missing, invalid or revoked.
- 402 - the plan does not include the action at all. Going over the allowance is not this error: an overage is served and priced.
- 422 - the body does not validate. A missing query, a limit outside 1-50.
- 429 - rate limited. The rate is the plan's: 2 per second on Free, 20 on Pro, 50 on Team. Back off and retry.
- 502 / 503 / 504 - the search service failed, is not configured, or did not answer in time. Retry these.
Retry 429, 502 and 504 with a backoff. Do not retry a 400 or a 422 unchanged - the request itself is wrong and will fail the same way every time.
What it costs
A search is billed per successful call, not per token and not per result: limit: 1 and limit: 50 cost the same. Fetching a page is billed separately and carries no per-page fee.
- Free - 100 searches and 20 fetches per month, 2 requests per second
- Pro, $9/month - 3,000 searches and 1,000 fetches per month, 20 requests per second
- Team, $79/month - 30,000 searches and 10,000 fetches per month, 50 requests per second
A call beyond the allowance is priced at $2.5 per 1000 and still served - an overage never interrupts your agent mid-answer. Annual billing is two months free.
One more thing worth knowing
AgentSearch does not run a language model. The search service gathers and ranks the pages; the model is yours. The "Result Tokens" on your dashboard are the size of the text you were handed - what it cost you to read - not what we spent on inference.
Get a free API keyNext: the same two tools over MCP, for agents that speak the protocol directly.
Related: what a web search API is and how to choose one, what the free search API tiers really give you, and how to run this in production.