AI Search is a short Python example. One prompt searches the web and X together. Supported tools: web, twitter. To search Reddit, use the Web Search API with site:reddit.com (see Reddit Search API). The example asks for links with a final summary.
The problem
A question that spans the web and X means several searches and then a pass to line up the links. One call can return those links and, with LINKS_WITH_FINAL_SUMMARY, a final summary, and still keep the URLs.
What the app does
- Sends one prompt, a tool list, a result type and a system message.
- Asks for up to
countresults. - Prints the response, including per-source results and a completion block of key posts, news and sources with URLs.
How it works
The example opens an async Desearch client and awaits ai_search. That method posts to POST /desearch/ai/search. Pass prompt, tools, result_type, system_message and count. tools is web and twitter. result_type is LINKS_WITH_FINAL_SUMMARY. The other result type is ONLY_LINKS. date_filter=None means no date restriction; date filters apply to X results only.
The code
import asyncio
import os
from desearch_py import Desearch
# Set DESEARCH_API_KEY in your environment to a key from the Desearch console. Do not commit a real key.
API_KEY = os.environ["DESEARCH_API_KEY"]
async def main():
# desearch-py 1.2.1 ai_search posts to POST /desearch/ai/search.
# Tools are "web" and "twitter". streaming is not a parameter.
# result_type is ONLY_LINKS or LINKS_WITH_FINAL_SUMMARY.
# Pass date_filter=None when tools include "web": the client default is PAST_24_HOURS,
# and that filter is not sent with the web tool.
async with Desearch(api_key=API_KEY) as desearch:
result = await desearch.ai_search(
prompt="Bittensor",
tools=[
"web",
"twitter",
],
date_filter=None,
result_type="LINKS_WITH_FINAL_SUMMARY",
system_message="You are a helpful assistant.",
count=10,
)
print(result)
if __name__ == "__main__":
asyncio.run(main())Set DESEARCH_API_KEY in your environment to a key from the Desearch console. Do not commit a real key.
Endpoints
POST /desearch/ai/search
Example output
The script prints the response. It does not include a saved sample run or a measured cost.
Run it yourself
The file linked above is ai_search.py in the examples repository. Install desearch-py 1.2.1, create a key at console.desearch.ai, set DESEARCH_API_KEY in your environment, and await ai_search with prompt, tools, result_type, system_message and count from the snippet. tools is web and twitter. result_type is LINKS_WITH_FINAL_SUMMARY.
What it costs
This example does not record X-Desearch-Cost-Usd. Current responses include that header. See pricing.
Ideas to extend it
- Write the completion links to a file you can cite.
- Run the prompt again with the twitter tool when you want
date_filteron X results. - Hand the links to the page-to-Markdown example.
