```yaml
product: AlterLab
title: Agent and RAG Grounding
category: guides
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
source_url: https://alterlab.io/docs/guides/search-grounding
```

# Agent and RAG Grounding

Give a model current, citable context: search once, receive ranked results with the page content of each, and pass the text into the prompt.

## Search with content

`scrape_results: true` scrapes each result page and returns its content in the formats you request. The `rag` and `markdown` formats are the usual choices for LLM context.

```python
import requests

resp = requests.post(
    "https://api.alterlab.io/api/v1/search",
    headers={"X-API-Key": "YOUR_API_KEY"},
    json={
        "query": "postgres 17 release notes logical replication",
        "engine": "auto",
        "num_results": 5,
        "scrape_results": True,
        "formats": ["markdown"],
    },
).json()

context = "\n\n".join(
    f"[{i}] {r['title']} ({r['url']})\n{(r.get('content') or {}).get('markdown') or r['snippet']}"
    for i, r in enumerate(resp["results"], 1)
)
```

Check the Search API reference (`/docs/api/search`) for the exact content shape of a scraped result.

## Freshness and domain control

Unified search accepts `freshness` (day, week, month, year), `include_domains`, `exclude_domains` and `max_per_domain` so an agent can restrict grounding to recent pages from sources you trust. Use `sources` to mix verticals such as web and news in one request.

## Keep citations

Every result carries `url`, `title` and `published_at` when known; the response has `fetched_at`. Carry these into your prompt and ask the model to cite by index, so each claim traces back to a page you can open. For multi-step investigations that need many searches and reads, use a research job (`/docs/guides/research`) instead of looping in your own agent.

## Cost

A unified search request costs $0.001 and a multi-query request (`queries`) is billed as one unit. Content scrapes for `scrape_results` are billed per page at the scrape tier of each URL. Cached results are billed at zero. New accounts get up to 5,000 free requests.
