Web answer
GET /api/answerAI-generated answer to a natural-language question, grounded in live web search results with source citations. Send GET /api/answer with the required field q and pay $0.08 per call over x402 or MPP (there is no free tier). It returns a JSON object with query, answer, citations and citationCount.
Returns clean prose plus a structured citations array (URL, snippet, favicon) - backed by an independent search index, not the model's training data. Useful when an agent needs a synthesized answer plus the receipts to verify or follow up.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
q | string | yes | Natural-language question (max 400 chars) Also accepted as query, search, term, keyword. |
country | string | no | Optional 2-letter country code (default us) |
language | string | no | Optional 2-letter language code (default en) |
max_tokens | integer | no | Optional cap on the generated answer length in tokens (default 1024, min 64, max 4096). Lower for TL;DR; higher for research questions. |
Example request
curl -i "https://agent402.tools/api/answer?q=what+is+the+x402+payment+protocol%3F"
Without payment this returns HTTP 402 Payment Required with the exact price for answer; any x402 v2 or MPP client pays it and retries.
Example response
{
"query": "what is the x402 payment protocol?",
"answer": "x402 is an open standard for internet-native, pay-per-request HTTP APIs that uses the HTTP 402 \"Payment Required\" status code to negotiate and settle micro-payments inline with the original request.",
"citations": [
{
"url": "https://www.x402.org/",
"snippet": "x402: An open standard for internet-native payments.",
"favicon": "https://imgs.search.brave.com/...",
"number": 1
}
],
"citationCount": 1
}
| Field | Type | Always present | In the example |
|---|---|---|---|
query | string | yes | what is the x402 payment protocol? |
answer | string | yes | x402 is an open standard for internet-native, pay-per-request HTTP APIs that ... |
citations | array of objects | yes | 1 item in the example |
citationCount | number | yes | 1 |
From an MCP client
catalog.call {
"slug": "answer",
"params": {
"q": "what is the x402 payment protocol?"
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for answer; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
qis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce different wording.
- A
POSTwith a JSON body to /api/answer is served as this GET, with the body as the input. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/answer?q=what+is+the+x402+payment+protocol%3F");
Part of these workflows
Web answer is one step in these 2 skill packs, each sold as a single call:
- Answer-a-question with sources - The 'research a question, return an answer with citations' workflow. Brave answer for the AI-synthesized take with citations, Brave web for the canonical SERP, Brave news for time-sensitive context, then a deterministic web-fetch + extract pass on the top citations to verify the answer hasn't hallucinated. Five tools, one cited paragraph, every claim traced back to a fetched URL.
- Article digest - Quick research brief on any topic - web search results plus an AI-generated answer in one pass.
Related tools
LLM grounding context
POST /api/llm-contextWeb search that returns READY-TO-USE grounding text, not links: for one query you get the passages an independent search…
Exa grounded answer
POST /api/exa-answerAsk a question and get a written answer with the sources it was drawn from. Exa searches its index, reads the pages and …
Web search
GET /api/searchLive web search: ranked results[] of {title, url, description (the snippet, plain text), age, publishedAt (ISO)} from an…
News search
GET /api/search-newsLive news search: ranked recent articles as results[] of {title, url, description (the snippet, plain text), age, publis…
Multi-search (batch)
POST /api/multi-searchRun 2-5 web searches in one call with a 20% volume discount vs. individual searches. Each query returns ranked results (…
Image search
GET /api/search-imagesLive image search: ranked image results (title, source page, image URL, thumbnail URL, dimensions) from an independent s…