Back to use cases

    Use case / Developers / Python 3 / Published

    Find X Posts for a Prompt with Python

    Pass a prompt and get the X posts that match it, including text, links and engagement counts. The example is one SDK call that prints the posts it received.

    Card for Find X Posts for a Prompt with Python

    X Post Links Search is a short Python example. It takes a prompt and a count, asks for X posts that match, and prints them. Each post can include text, a URL, engagement counts and a short summary description.

    The problem

    A keyword search on X returns a timeline. When you want posts for a prompt, with the URL and the counts in one object, a single links call is the smaller tool.

    What the example does

    • Sends a prompt and a count.
    • Prints the posts that came back.

    How it works

    The file calls twitter_links_search with prompt and count. The current SDK method with those same arguments is ai_x_links_search. It posts to POST /desearch/ai/search/links/twitter.

    This is separate from GET /twitter, which takes an X query string, sort and date filters. Use that endpoint when you need operators such as since: or min_faves:.

    The code

    result = desearch.twitter_links_search(prompt="Bittensor", 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/links/twitter

    Example output

    The file documents post fields: text, URL, reply count, retweet count, like count, view count, quote count and a summary description. It does not include a saved sample run or a measured cost.

    Run it yourself

    The file linked above is twitter_links_search.py in the examples repository. Install desearch-py, create a key at console.desearch.ai, and call ai_x_links_search with a prompt and count.

    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 posts to the CSV exporter's columns.
    • Follow the loudest post into the replies example.
    • Combine the posts with web links for the same prompt.

    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 to find X posts for the prompt I give you. Return the posts you received with text, URL and engagement counts. Do not add posts 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