A web search API for AI agents that returns clean Markdown

An LLM only knows what it was trained on. Ask it about this week's release notes, today's prices or a library that changed last month, and it either guesses or says it doesn't know. The fix is to give it the web, but a list of search links isn't enough: the agent needs the text of the pages, cleaned up and small enough to fit in its context.
Doing that yourself means a search API, a page fetcher, an HTML clean-up step and retry logic for the pages that fail. I wrapped all of it into one call. Here's how it behaves and where the limits are.
What to watch for
- Results come from Bing, not Google. For most informational queries the top pages overlap heavily, but rankings differ. This is not a Google results scraper.
- Pages are fetched without running JavaScript. A search result that shows no text without JavaScript is replaced by the next result. A URL you pass directly comes back with whatever text it has, and
needsJavaScript: truetells you when that's little or nothing. - Some sites refuse automated requests. Reddit, Forbes, Scribd and academic publishers answered HTTP 403 in my tests. Those results are skipped and replaced, but a query whose results are mostly such sites can return fewer pages than you asked for: it tries at most twice as many results as
maxResults. Put sites you never want inskipDomainsto save time. - Thin pages are dropped. Results with fewer than 50 words (login walls, redirect stubs, empty app shells) are replaced.
freshnessis best effort, and there's nosite:filter. Bing sometimes ignores the date filter for automated searches; when that happens you get an uncharged row with the reason instead of wrong pages. To read one site, pass its URLs directly.maxContentCharscutsmarkdownandtext, nothtml. The default of 20,000 characters is about 5,000 tokens per page.- One market per run.
countryandlanguageapply to every query in the run.
Getting the data
I packaged this as an Apify Actor, RAG Web Search. Each row is one page, in rank order. The first result for "what is retrieval augmented generation" (Markdown shortened):
{
"query": "what is retrieval augmented generation",
"rank": 1,
"url": "https://www.geeksforgeeks.org/nlp/what-is-retrieval-augmented-generation-rag/",
"title": "What is Retrieval-Augmented Generation (RAG) - GeeksforGeeks",
"snippet": "Retrieval-Augmented Generation (RAG) is a way to make AI answers more reliable by combining searching for …",
"markdown": "Retrieval-Augmented Generation (RAG) is a way to make AI answers more reliable by combining searching for relevant information and then generating a response. ...",
"language": "en",
"wordCount": 955,
"tokensEstimate": 1706,
"truncated": false,
"statusCode": 200,
"needsJavaScript": false
}
tokensEstimate (characters divided by 4) lets you budget the context before you build the prompt, and truncated tells you when a page was cut.
One call, two questions, four pages each:
curl -X POST "https://api.apify.com/v2/acts/rjmacarthy~rag-web-search/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"queries": ["python asyncio TaskGroup tutorial", "how does HTTP/3 differ from HTTP/2"],
"maxResults": 4,
"maxContentChars": 8000,
"skipDomains": ["youtube.com", "reddit.com"],
"includeLinks": false
}'
A line in queries that is an http(s):// URL is fetched directly with no search, so you can mix questions with pages you already know. For another market, set country and language, for example DE and de.
Plugging it into an agent
- Add the Actor as a tool through the Apify MCP server, so Claude, Cursor or any MCP client can call it, or call the endpoint above from your own code.
- Pass the user's question as a query, keep
maxResultsat 3 and lowermaxContentCharsif your context is tight. - Put each row's
markdowninto the prompt with itsurl, so the model can cite its sources.
A three-result query took 2 to 3 seconds in my tests, because the result pages are fetched in parallel. If no page for a query can be fetched, you still get one free row with markdown: null, the reason in error and Bing's results in searchResults, so the agent has links to work with.
It's a normal Actor run that agents can call through the MCP server, not an always-on server.
What it costs
It's $0.001 per page returned on every Apify plan, plus $0.00005 per run. The search itself is free. A three-result query costs $0.003, 100 queries with three pages each cost $0.30, and 1,000 pages cost $1.00.
Pages that fail, time out, aren't HTML or have no text are not charged, and neither are rows without a page. maxResults times the number of queries is the most a run can cost.
It reads public search results and public web pages only, with no login.