Which APIs provide source links for individual AI answer citations? Desearch offers two routes: POST /search returns web results and, with summary: true, a summary with numbered citations; POST /desearch/ai/search combines web and X results with an optional written summary. This guide walks through AI Search and shows when to use the web-only Search route instead. Keep the returned source URLs with the answer so readers can inspect the evidence.
The request at a glance
If you want the product overview first, start at the AI Search API page. If you are still deciding between AI search and plain web search, read AI search vs web search APIs.
Every call goes to the same place:
- Base URL:
https://api.desearch.ai - Endpoint:
POST /desearch/ai/search - Auth:
Authorization: $DESEARCH_API_KEY(the raw key from Desearch Console)
Here is a complete request (schema example, UNRUN):
--include prints the response headers, so you can see the cost headers covered in Step 8.
Five fields shape the result:
| Field | Required | What it controls |
|---|---|---|
prompt | yes | The natural-language question |
tools | yes | Which sources to search: web, twitter, or both |
result_type | no | LINKS_WITH_FINAL_SUMMARY (default) or ONLY_LINKS |
count | no | Results per source, from 10 to 200 (default 10); web results are capped at 20 |
streaming | no | Defaults to true. With LINKS_WITH_FINAL_SUMMARY, set false for one JSON body |
The OpenAPI default for streaming is true, so use LINKS_WITH_FINAL_SUMMARY with "streaming": false on your first call to get one JSON body. Optional fields for mode, domains and dates are covered in Steps 4 to 6. The full schema is in the AI Search API reference.
Step 1: Pick your sources with tools
The tools array accepts two values:
websearches the Desearch index. Results come back in asearcharray.twitterruns X Search over public X posts. Results come back in atweetsarray.
Send one or both. When you send both, a single JSON body can hold search and tweets side by side, so your agent gets web pages and social discussion from one call.
Each search item carries the fields an agent needs to cite a source:
| Field | Use it for |
|---|---|
link | The citable URL |
title | A short label for the source |
snippet | Short evidence text |
Each tweets item includes an id and the post text. A url field exists in the schema but is not required, so do not assume it is always there.
The current Search API guide lists only web and twitter as supported tools. Other values are unsupported and may be rejected; youtube, for example, returns 422. To search Reddit, use POST /search with include_domains: ["reddit.com"].
One thing to plan for: on a request with both web and twitter, a tool can return no results or fail to respond in time. When that happens, the response includes a warnings array. Each entry has a code (tool_no_results or tool_unavailable), the tool, the response field it refers to, and a message. warnings is omitted for single-tool requests and when every requested tool returned results. A warning for one source does not mean the other source failed, so handle each array on its own.
Step 2: Choose links plus a cited summary, or links only
This is the main decision, and it depends on who reads the output.
LINKS_WITH_FINAL_SUMMARY is the default. You get the search and tweets arrays plus a completion field: a written summary of the sources. Use it when a person or a downstream model wants a readable answer with the evidence attached.
Here is a search item from the OpenAPI response example (OpenAPI example, UNRUN, not a live capture):
The same response also carries tweets and the completion text.
ONLY_LINKS skips the summary. Use it when your own model will write the answer and you only want the sources. The Search API guide notes that in its live check, ONLY_LINKS on POST /desearch/ai/search returned a stream rather than one JSON object.
For sources as one JSON object, choose the route for your source:
- Web:
POST /searchreturnsresultswith source URLs inresults[].url. Omitsummaryor set it tofalsefor links without a generated answer. The olderPOST /desearch/ai/search/links/webroute is deprecated. See the Search API guide. - X:
POST /desearch/ai/search/links/twitterreturns posts inminer_tweets(links/twitter reference).
For a web answer with citations attached automatically, send summary: true to POST /search. Its response has summary.text with numbered [n] citations and a summary.citations list containing index, url and title. A summary can be unavailable: handle summary: null and the Summary unavailable notice without discarding the search results.
A quick way to choose:
| You want | Use |
|---|---|
| A readable answer with sources | /desearch/ai/search with LINKS_WITH_FINAL_SUMMARY |
| Sources only, from the main endpoint | /desearch/ai/search with ONLY_LINKS |
| Web sources only, as one JSON body | POST /search without a summary |
| A web answer with numbered citations | POST /search with summary: true |
| X sources only, as one JSON body | POST /desearch/ai/search/links/twitter |
Whichever path you pick, keep the source URLs next to any generated text. That way users can check the evidence, and your agent never presents a claim it cannot point to. For more help picking a route, see which endpoint to use.
Step 3: Set count per source
count sets how many results to request per source, not in total. It accepts integers from 10 to 200 and defaults to 10, but AI Search web results are capped at 20 per request. Raising count above 20 does not raise that web cap.
So "count": 10 with "tools": ["web", "twitter"] asks for up to 10 web results and up to 10 X posts.
Send count as a JSON number ("count": 10), not a string. Start at the default, check whether the evidence is enough for your task, and raise it only when the agent actually needs more coverage.
Step 4: Pick a mode
mode accepts fast, balanced or deep. The OpenAPI spec adds one rule: fast is web-only, and X search supports balanced and deep.
So if your request uses "tools": ["web", "twitter"], set "mode": "balanced" or "mode": "deep". Keep fast for web-only requests.
Step 5: Scope web results by domain
Two optional fields narrow Web Search results:
include_domainsrestricts Web Search results to the domains you list, for example["bbc.com", "reuters.com"].exclude_domainsdrops Web Search results from the domains you list, for example["pinterest.com"].
You can also put site:<domain> in the prompt. Both approaches apply to Web Search results, which land in search.
Request fragment with mode and domains (schema example, UNRUN):
For one-off Reddit threads, see find Reddit threads with Web Search API (GET /web with site:reddit.com).
Step 6: Set a date window
The Search API guide lists optional relative windows such as date_filter: "PAST_WEEK" for AI Search. These apply to X results. Do not rely on them to filter web results.
For a web date range, use start_date and end_date on POST /search, formatted YYYY-MM-DD. For absolute X date ranges, follow the X API guide.
Optional: highlights and full page text
Two request fields control how much page content comes back on Web Search results:
highlights(defaulttrue) includes token-efficient key excerpts from each page.page_text(defaultfalse) includes the full page text. Responses get significantly larger.
For the current web-only POST /search route, results use results[].highlights; setting highlights: false leaves those passages out. Use the Search API reference for its request and response schema.
Step 7: Decide on streaming
With LINKS_WITH_FINAL_SUMMARY, "streaming": false returns one JSON body. That is the easiest shape to validate for agents that read the whole result before acting. For ONLY_LINKS, account for the stream described in Step 2, or use POST /search for web results as JSON.
"streaming": true is the default and sends results as they arrive. It suits chat interfaces where a user is watching the answer form. The streaming guide covers the format.
streaming is a REST body field. The docs note that it is not an argument of the SDK ai_search / aiSearch methods.
Step 8: Read what the call cost
Every successful billable response includes four headers:
| Header | Meaning |
|---|---|
X-Desearch-Cost-Usd | Request cost in USD |
X-Desearch-Usage-Count | Billable usage units |
X-Desearch-Service | Pricing service key for the request |
X-Desearch-Currency | Currency code |
When the body is a JSON object, it can also include cost_usd, usage_count, service, and currency. Streamed, plain text, and array responses expose cost only in headers, so make headers your default source.
Logging these values per call lets an agent track its own spend, stop when a task budget runs out, and report cost alongside the answer. The pricing and billing guide has the details.
Put it together: AI search API request in Python
This example sends one request, prints the cost from headers, and reads the summary, web results, X posts and any warnings. It uses plain HTTP so the fields map one to one to the docs (schema example, UNRUN):
Hand the answer, the sources and the cost to your agent as one tool result, so every claim it makes can point back to a link.
For a broader look at wiring search into an agent loop, see how to build AI agents with search APIs. If you are comparing web search API options for AI agents, start there.
Related examples: Build an AI search engine in Python, Build an AI fact checker in Python, Web search API quickstart in Python.
What it costs
AI Search is billed by usage. AI Search is listed at $0.40 per 1,000 items on the pricing page. Confirm your current rate in Console, and use the cost headers above to see what each request used.
New accounts get $5 in API credits after attaching a card in Console, then pay as they go.
Frequently asked questions
Which sources can the AI search API use?
Two supported values: web for web results and twitter for public X posts. Send either one or both in the tools array. For Reddit, use POST /search with include_domains: ["reddit.com"].
Is count the total number of results?
No. count is per source. It accepts 10 to 200 and defaults to 10, but AI Search web results are capped at 20 per request.
How do I get one JSON object of links?
Use POST /search for web results in results, or POST /desearch/ai/search/links/twitter for X posts in miner_tweets. The older links/web route is deprecated. The Search API guide notes that ONLY_LINKS on the main AI Search REST endpoint returned a stream in its live check.
Can I use fast mode with X?
No. The OpenAPI spec says fast is web-only. X search supports balanced and deep.
How do I limit web results to certain sites?
Use include_domains or exclude_domains, or put site:<domain> in the prompt.
How do I know what a request cost?
Read the X-Desearch-Cost-Usd and X-Desearch-Usage-Count headers on the response. JSON object bodies may also carry cost_usd and usage_count, but headers are present on every successful billable response, including streams.
Which APIs provide source links for individual AI answer citations?
Desearch Search returns web source URLs and, with summary: true, a summary with numbered citations and a citation list on POST /search. AI Search returns web and X source results with an optional written summary on POST /desearch/ai/search.
Can a search API attach citations automatically?
Yes. Send summary: true to Desearch POST /search for a web summary with numbered citations in summary.text and source records in summary.citations. Handle summary: null when a summary is unavailable.
How is this post different from the comparison posts?
This post shows one request step by step. The comparison posts compare API types and options.
Where do I get an API key?
Create an account in Desearch Console, open API Keys, and create a key. Keep it server-side and send it in the Authorization header. See API keys for details.
Get started
Get an API key in Console and send your first AI search request. New accounts get $5 in API credits after attaching a card in Console, then pay as they go.
Then work from the AI Search API reference.
