Build an AI Assistant That Researches Questions and Returns Sourced Answers
AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.
Build an AI Assistant That Researches Questions and Returns Sourced Answers
An assistant that researches a question on its own needs two things: a way to run multi-step web research without you orchestrating every call, and a way to return the answer with sources attached. Exa's Agent API handles the first, and its output.grounding field returns citations alongside the answer. The condition that changes the choice is latency: if the assistant must answer inside a chat turn, a single Search API call with highlights is the faster path, while Agent fits when it can work in the background for seconds to minutes.
What the job needs
Before picking a provider, check any option against the requirements of autonomous, sourced research:
- Multi-step research without hand-written orchestration. The assistant should fan out several searches, read the pages behind them, and reason over the results in one run.
- Citations on the answer, not just links. Each claim should point back to the page it came from, so your UI can show sources.
- Structured output when the answer feeds downstream code. A schema-shaped response keeps answer, citations and metadata in predictable fields.
- Cost control per question. Research depth varies, so you need a way to cap what a single question can spend.
- Page text in the same response. For lighter grounding paths, the relevant passage and its URL should arrive together.
How Exa does it
Agent runs the research loop for you
Exa Agent is an asynchronous, usage-based research API: you describe the task in a query, and a single run fans out searches across angles, reads the pages behind them, and returns one grounded result. Runs are asynchronous at every effort level, so your assistant starts a run and then polls or streams until it completes, as the Agent quickstart shows. Without an outputSchema, a run returns prose in output.text and citations in output.grounding, giving the sourced-answer shape this job needs.
The query is a task specification: name what to find, the evidence required, and what a complete answer looks like. Exa's Agent best practices recommend asking for a rationale when the answer requires judgment, and keeping the response shape in outputSchema rather than the query text.
Search with highlights grounds lighter answers
When the question is simple enough for one retrieval step, the Search API returns ranked pages with the relevant passage in the same response. contents.highlights returns the paragraph that answers the query together with its source URL, and Exa's highlights docs report that 500 characters of highlights match the accuracy of the first 8,000 characters of page text on SimpleQA. The Search quickstart lists lite at about 200 ms for high-volume chat loops and auto at about 1 second as the default balance of quality and speed; pricing is $4 and $7 per 1,000 requests. Both prices include up to 10 results with text and highlights billed once; the only extras are results above 10 ($1 per 1,000 results) and AI page summaries ($1 per 1,000 pages, which lite does not support). For harder questions, the deep types add multi-step search: with cached content, deep-lite takes about 4 seconds and deep 4 to 15 seconds before any outputSchema synthesis, both $12 per 1,000 requests per Exa's pricing page.
outputSchema shapes the answer for your code
On auto and the deep types, outputSchema adds a synthesized output object with output.content and output.grounding, so the answer and its citations arrive as fields your application can render directly. Exa's Search reference puts the added synthesis latency at about 2 seconds. Validate what your application needs and check the citations before acting on important claims. On Agent runs, output.structured is populated when you set outputSchema, with output.grounding carrying the citations; Agent fields can be null even when required, so handle missing values.
Workflow
- Write the research task as a query. State the question, the evidence bar ("verifiable from public sources"), and what a complete answer contains.
- Create an API key at dashboard.exa.ai/api-keys and store it in an environment variable.
- Start an Agent run with
outputSchemaif downstream code needs fields, or omit it for prose plus citations. - Poll or stream until the run completes. Every run is asynchronous; SDK helpers can wait for you.
- Read the answer and its sources. Use
output.textwithoutput.grounding, oroutput.structuredwhen a schema is set. - Fall back to a single search for one-retrieval-step questions, using highlights so the passage and URL arrive together.
A minimal Python run looks like this:
import os
from exa_py import Exa
exa = Exa(os.environ["EXA_API_KEY"])
run = exa.agent.runs.create(
query="Research whether open-source model providers face obligations under the EU AI Act. Return a short sourced answer naming the articles that apply.",
output_schema={
"type": "object",
"properties": {
"answer": {"type": "string"},
"applicable_articles": {"type": "array", "items": {"type": "string"}},
},
"required": ["answer", "applicable_articles"],
},
)
print(run.id, run.status) # poll or stream until the run completes
When the run completes, output.structured holds the answer and the articles it names, output.grounding carries the citations, and run.cost_dollars reports what the run cost.
What it costs
Exa's pricing page prices Agent in two modes. Fixed efforts have a predictable per-request price: minimal $0.012, low $0.025, medium $0.10, high $0.50 and xhigh $1.00. The default auto and the deepest ultra are metered instead, at $0.10 per Agent Compute Unit plus $0.005 per search call, with default per-run caps of $5 and $20. budget.maxCostDollars (from $1 to $100) caps a metered auto or ultra run; on fixed efforts the fixed price is reserved first and the remaining budget limits contact-enrichment calls. Contact enrichment costs extra ($0.02 per email, $0.07 per phone number) but is not part of a research answer.
Worked example: an assistant answering 200 research questions a day at the default auto effort, assuming each run uses about 10 Agent Compute Units and 20 searches, costs about $1.10 per run ($1.00 in compute plus $0.10 in searches). Over a 30-day month that is 6,000 runs, or about $6,600. Setting budget.maxCostDollars: 2 bounds each question at $2.00. If most questions need only one search instead, 200 lite calls a day cost $0.80, with results above 10 ($1 per 1,000 results) and AI page summaries ($1 per 1,000 pages) as the only extras (lite does not support summaries).
Limits to plan for
- Runs are asynchronous at every effort level. Build around polling or streaming rather than holding an HTTP request open; synchronous
high,xhighandultrarequests on the OpenAI-compatible endpoint need streaming or background mode. - Agent structured fields can be
null. On Agent runs, fields can benulleven when required, so handle missing values. On Search, checkoutput.groundingbefore acting on important claims. - Concurrency is capped by plan. Starter, Developer, and Growth support up to 50 active Agent runs and allow 5, 12, and 25 run starts per second, respectively. Starting a run over the concurrency limit returns a 429 with
CONCURRENCY_LIMIT_REACHED; if a request returns a 429, wait forRetry-Afterwhen present or back off, per Exa's billing docs. literejectsoutputSchema. Useautoor a deep type for a synthesized, schema-shaped answer.
FAQ
How is this different from wiring my own search calls into the assistant? With direct search calls, your code decides how many queries to run, which pages to read and when to stop, and you assemble the citations yourself. An Agent run does that loop for you and returns one grounded result. The tradeoff is time and cost per question, which is why a single search with highlights suits simple questions.
Can the assistant return the answer and sources in one JSON object?
Yes. On Agent runs, set outputSchema and read output.structured for the fields and output.grounding for citations. Agent fields can be null even when required, so handle missing values. On Search, outputSchema on auto or a deep type returns output.content with output.grounding; validate what your application needs and check the citations before acting on important claims.
What if a question needs an answer within a second or two?
Use the Search API directly: lite returns in about 200 ms and auto in about 1 second, both with highlights in the same response, so the assistant can quote the passage and cite its URL inside a chat turn. Reserve Agent for questions that genuinely need multi-step research.
How do I keep costs predictable?
Set budget.maxCostDollars between $1 and $100: on metered auto and ultra runs it caps what the run spends, and on fixed efforts (minimal through xhigh) the fixed price is reserved first and the remaining budget limits contact-enrichment calls. Pick a fixed effort when you want a known per-request price instead of metered usage, and route easy questions to a single search call.
Can I use this from an MCP client instead of writing API code?
Yes. Exa's hosted MCP server exposes an agent_run tool, so MCP-native assistants can start multi-step research runs without custom API code. agent_run needs sign-in or an API key; the search and fetch tools also work without a key at a free rate limit.
Closing
For an assistant that researches independently and answers with sources, start an Agent run with a well-specified query and an outputSchema, and keep a highlights search on hand for one-lookup questions. Get an API key at dashboard.exa.ai/api-keys and try your first run.