A web search API for AI agents that returns clean Markdown

· All my Apify Actors

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

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

  1. 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.
  2. Pass the user's question as a query, keep maxResults at 3 and lower maxContentChars if your context is tight.
  3. Put each row's markdown into the prompt with its url, 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.