Back to use cases

    Use case / Developers / Python 3 / Published

    Run a Multi-Source AI Search with Python

    Run one prompt across the web, X, Reddit, Hacker News, Wikipedia, YouTube and arXiv. The example asks for links with summaries from the past 24 hours.

    Card for Run a Multi-Source AI Search with Python

    AI Search is a short Python example. One prompt searches the web, X, Reddit, Hacker News, Wikipedia, YouTube and arXiv together. The file asks for links with summaries and limits the window to the past 24 hours.

    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 example does

    • Sends one prompt, a tool list, a date filter, a result type and a system message.
    • Asks for up to count results.
    • Prints the response, including per-source results and a completion block of key posts, news and sources with URLs.

    How it works

    The current ai_search method posts to POST /desearch/ai/search. Pass prompt, tools, date_filter, system_message and count. For result_type, the current enum is ONLY_LINKS or LINKS_WITH_FINAL_SUMMARY. Leave out streaming. The file below includes that argument. The current method does not accept it.

    The file sets result_type to LINKS_WITH_SUMMARIES. That value is not in the current enum. date_filter is PAST_24_HOURS. Other windows in the file's notes include the past week, month and year.

    The code

    result = desearch.ai_search(
        prompt="Bittensor",  # The search query
        tools=[
            "web",
            "hackernews",
            "reddit",
            "wikipedia",
            "youtube",
            "twitter",
            "arxiv",
        ],  # List of tools to use for the search
        # model="NOVA",  # The model to use for the search
        date_filter="PAST_24_HOURS",  # Filter results from the past 24 hours
        streaming=False,  # Whether to stream results
        result_type="LINKS_WITH_SUMMARIES",
        system_message="You are a helpful assistant.",
        count=10,
    )
    

    Set the key in the environment when you use the current client. The file's setup lines use a placeholder string. Do not commit a real key.

    Endpoints

    • POST /desearch/ai/search

    Example output

    The file documents the result shape: per-source results, text chunks, completion links, and a completion object with key posts, key news, key sources and summaries. 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, create a key at console.desearch.ai, and call ai_search with the prompt, tools, date filter, system message and count from the file. Set result_type to ONLY_LINKS or LINKS_WITH_FINAL_SUMMARY, and leave out streaming.

    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.
    • Swap the date filter for a start and end date.
    • Hand the links to the page-to-Markdown example.

    Use with AI agents

    Point an MCP client at the hosted Desearch server. Replace the placeholder with a key from the console. Do not commit the key.

    {
      "mcpServers": {
        "desearch": {
          "url": "https://mcp.desearch.ai/mcp",
          "headers": {
            "Authorization": "Bearer <DESEARCH_API_KEY>"
          }
        }
      }
    }

    Prompt you can paste for this example:

    Use Desearch AI search for the prompt I give you. Search the web, X, Reddit, Hacker News, Wikipedia, YouTube and arXiv over the window I set. Set result_type to ONLY_LINKS or LINKS_WITH_FINAL_SUMMARY. Keep the URL on every point. Do not add sources you did not retrieve.

    Build your own example.

    Give your agents access to web and social search. Get an API key to start building, or talk to us about your integration.

    Read docs