# AI answer API with citations

> RAG without the plumbing. Cited answers, real URLs, no hallucinated sources.

- Endpoint: `POST https://scrapenest.dev/v1/search/answer`
- Price: 20 + 5/source
- Category: Search & Discovery
- Reference: https://scrapenest.dev/docs#ep-search-answer
- Web page: https://scrapenest.dev/catalog/search-answer
- Updated: 2026-11-04

An end-to-end RAG pipeline behind one POST. We do the search, fetch the top sources, hand them to our answer model with a strict citation prompt, and return a clean answer with numbered [n] citations plus the list of sources it drew on, so you can check each claim against its URL.

## The hard part

Standing up your own RAG pipeline is half a weekend: a search call, a fetcher, an LLM key, a citation enforcer, a fallback for hallucinated URLs, and a way to keep your answers from leaning on whichever source got summarised first. One POST replaces all of that with cited answers that point at real, fetched pages.

## AI answer API: what you get

- Numbered [1][2] citations that resolve to real fetched URLs.
- Returns the answer plus the full citation list (index, url, title, snippet).
- Fast-fail on slow sources so one bad fetch doesn't drag the whole answer.

## AI answer API use cases

- **Cited answers in a chat product**: Show the answer with its [n] markers and link each one to the citation's URL, title and snippet.
- **Fact checks inside an agent**: Ask a narrow question and check each claim against the source it cites before the agent acts on it.
- **Research briefs**: Answer a list of questions with up to 10 sources each, then fetch any cited page in full with the Web Scraping API.

## AI answer API quickstart

Install an SDK with `pip install scrapenest` or `npm install scrapenest`, or call the HTTP API directly with your key in the `Authorization: Bearer` header. No key yet? Sign up free at https://scrapenest.dev/signup, verify your email, then create a key in your dashboard.

### Python SDK

```python
import os
from scrapenest import Client

client = Client(os.environ["SCRAPENEST_API_KEY"])
res = client.search_answer("is matcha actually better than coffee for focus?", max_sources=5)
print(res.answer)
for c in res.citations:
    print(f"[{c.index}] {c.title} {c.url}")
```

### Node SDK

```javascript
import { ScrapeNest } from "scrapenest";

const client = new ScrapeNest({ apiKey: process.env.SCRAPENEST_API_KEY });
const res = await client.searchAnswer({
  query: "is matcha actually better than coffee for focus?",
  max_sources: 5,
});
console.log(res.answer);
for (const c of res.citations) console.log(`[${c.index}] ${c.title} ${c.url}`);
```

### curl

```bash
curl -X POST https://scrapenest.dev/v1/search/answer \
  -H "Authorization: Bearer sn_••••" \
  -H "Content-Type: application/json" \
  -d '{
        "query": "is matcha actually better than coffee for focus?",
        "num_results": 8,
        "max_sources": 5
      }'
```

### Python (httpx)

```python
import httpx

r = httpx.post(
    "https://scrapenest.dev/v1/search/answer",
    headers={"Authorization": "Bearer sn_••••"},
    json={"query": "is matcha actually better than coffee for focus?", "num_results": 8, "max_sources": 5},
    timeout=60,
)
body = r.json()
print(body["answer"])
for c in body["citations"]:
    print(c["index"], c["url"])
```

### JavaScript (fetch)

```javascript
const r = await fetch("https://scrapenest.dev/v1/search/answer", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sn_••••",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    query: "is matcha actually better than coffee for focus?",
    num_results: 8,
    max_sources: 5,
  }),
});
const { answer, citations } = await r.json();
```

### Go

```go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    body, _ := json.Marshal(map[string]any{
        "query":       "is matcha actually better than coffee for focus?",
        "num_results": 8,
        "max_sources": 5,
    })
    req, _ := http.NewRequest("POST",
        "https://scrapenest.dev/v1/search/answer", bytes.NewReader(body))
    req.Header.Set("Authorization", "Bearer sn_••••")
    req.Header.Set("Content-Type", "application/json")
    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    var out struct{
        Answer    string
        Citations []map[string]any
    }
    json.NewDecoder(resp.Body).Decode(&out)
    fmt.Println(out.Answer)
}
```

## AI answer API request and response

### Request body

```json
{
  "query": "is matcha actually better than coffee for focus?",
  "max_sources": 5
}
```

### Response

```json
{
  "query": "is matcha actually better than coffee for focus?",
  "answer": "Matcha delivers caffeine with L-theanine, which smooths the energy curve [1][3] …",
  "citations": [
    {
      "index": 1,
      "url": "https://examine.com/supplements/l-theanine/",
      "title": "L-Theanine · Examine",
      "snippet": "L-theanine is an amino acid found in tea …"
    },
    {
      "index": 3,
      "url": "https://nccih.nih.gov/health/green-tea",
      "title": "Green Tea · NCCIH",
      "snippet": "Most studies on green tea …"
    }
  ],
  "took_ms": 4200,
  "cache_hit": false,
  "credits_charged": 35
}
```

Fields with no value are left out of the JSON rather than sent as `null`, so read optional fields defensively.

## AI answer API pricing

5 credits for the search, 5 credits per source actually fetched, plus 15 credits for the AI answer step. Formula: 5 + 5 × sources fetched + 15. The answer step is waived when no source page could be fetched and the answer falls back to search snippets (flat 5). When none of the sources is relevant the model isn't called and the call bills a flat 5; an answer that opens by saying the sources don't address the question also bills a flat 5. Wall, consent and empty pages don't count as fetched sources. Cache hits: 1 credit.

## AI answer API limits

- `max_sources`: 1 to 10, default 5. `query`: 1 to 400 characters.
- `depth` sets how hard sources are fetched: about 2.5 s a page at `fast`, 6 s at `balanced`, 9 s at `thorough` and 12 s at `stealth`, inside an overall fetch ceiling of roughly 6, 14, 20 and 28 s.
- `include_images`, `image_sources` and `include_image_descriptions` are rejected with a 422 on this endpoint.
- `timeout_seconds` is accepted but has no effect here, and `page` is ignored.

## AI answer API error codes

| HTTP | Code | Meaning |
| --- | --- | --- |
| 503 | `no_sources` | No usable sources were found. Not billed; rephrase the query. |
| 503 | `llm_upstream_failed` | The answer step failed. Not billed; retry. |
| 503 | `llm_not_configured` | The answer step is unavailable right now. Not billed. |
| 503 | `upstream_failed` | The search step failed. Not billed. |
| 422 | `validation_error` | A field is invalid, including any image flag. |

Every endpoint can also return `401 unauthorized` (missing or wrong key), `402 insufficient_credits` (balance used up), `403 email_not_verified` (an email signup must verify its address before its key works) and `429 rate_limited` or `concurrency_limit_exceeded`. All errors share one JSON envelope; see the [error reference](https://scrapenest.dev/docs#errors).

## AI answer API FAQ

### How are citations returned?

The `answer` text carries numbered markers like [1][3], and `citations` lists each one with its `index`, `url`, `title` and `snippet`, so every marker resolves to a page that was actually fetched.

### What does an answer cost?

5 credits for the search, 5 per source page fetched and 15 for the answer step: 5 + 5 × sources + 15. When no source page could be fetched, or none was relevant, the call bills a flat 5, and a cache hit bills 1.

### What if nothing on the web answers the question?

The model isn't called. You get a fixed answer saying no relevant sources were found, an empty `citations` list and a flat 5-credit charge.

### Can I choose how many sources it reads?

Yes, `max_sources` takes 1 to 10 (default 5). Raise `depth` when answers come back grounded in snippets: the higher tiers fetch each source harder.

## Related endpoints

- [Deep Search API for RAG](https://scrapenest.dev/catalog/search-deep.md): `POST /v1/search/deep`. Search plus auto-fetch the top N pages with extracted text. One round-trip for RAG.
- [SERP API for multi-engine web search](https://scrapenest.dev/catalog/search.md): `POST /v1/search`. Multi-engine web search aggregated and re-ranked into one feed.
- [Web scraping API for any URL](https://scrapenest.dev/catalog/scrape-url.md): `POST /v1/scrape/url`. Point us at a page. We get past the wall and hand back the rendered HTML and clean text.

## Get 1,000 free credits

Every account starts on the Free plan: 1,000 credits a month, no card. Verify your email, then mint an API key and make this call. Sign up at https://scrapenest.dev/signup.
