AI Development

    How to build a SERP API rank checker

    By Desearch Editorial Team5 min read

    I wanted a simple answer to where a site shows up for these 10 keywords, as JSON I can store and diff, without running a browser. It took one Desearch endpoint and 222 lines of standard-library Python.

    The worked example is Check Keyword Rank in Desearch Web Results. View the code in the Desearch Python examples repo.

    The basics

    • Base URL: https://api.desearch.ai
    • Auth: Authorization: $DESEARCH_API_KEY (the raw key from Desearch Console)
    • Endpoint: GET /web

    Get a key

    Sign up in the Desearch console, create an API key, and export it as DESEARCH_API_KEY.

    BASH
    export DESEARCH_API_KEY=your_key

    The checker sends that value on the request. It does not write the key into the output files.

    Make one call

    BASH
    curl -s "https://api.desearch.ai/web?query=web+search+api&start=0" -H "Authorization: $DESEARCH_API_KEY"

    The response is {"data": [{"title", "link", "snippet"}, ...]}. In the sample, a page returned as many as 21 results. start is how many results to skip.

    The product page is Web Search. Parameters for this endpoint are in the Web Search API reference.

    Run the checker

    Write the keywords, one per line. The checker skips blank lines, lines starting with # and duplicate keywords, so you can comment your list. The sample file is samples/keywords.txt.

    BASH
    python rank_check.py --keywords samples/keywords.txt --domain desearch.ai
    # a later run, diffed against the first one
    python rank_check.py --keywords samples/keywords.txt --domain desearch.ai --diff runs/<first-run>/summary.json

    For each keyword the checker asks for two pages (start=0 and start=20), drops duplicate URLs, numbers the rest 1, 2, 3, and records the first rank where the domain or a subdomain appears.

    Read the output

    results.csv has every result: keyword, rank, title, url, domain, and page_start. summary.json has the best rank per keyword, or not in top N when the domain did not appear.

    A later run with --diff compares best ranks with the earlier summary.json. The change is same, entered, dropped out, up N, or down N. A move from rank 3 to rank 1 is up 2.

    What I saw

    • Each call cost $0.001. Ten keywords with two pages is 20 calls and $0.02 per run.
    • Across 40 calls, the median was 1.92 s, the fastest 1.06 s, and the slowest 8.25 s.
    • Use start steps of 20. A step of 10 mostly repeated the first page, adding 0 to 6 new URLs.
    • In the sample diff, 9 of 10 best ranks did not change. Keywords with few results move more.
    • These are the search results Desearch returned at that moment, not a copy of any specific search engine's live ranking.

    Without code

    The Desearch MCP server has a web-search tool with the same idea. Ask an agent to search one keyword and say where the domain appears.

    Frequently asked questions

    How do I page past the first results?

    Use start steps of 20. Two pages are start=0 and start=20. A step of 10 mostly repeated the first page, adding 0 to 6 new URLs.

    How do I compare a later run?

    Pass --diff with the earlier summary.json. The change is same, entered, dropped out, up N, or down N.

    What should I check before a run?

    The checker skips blank lines, lines starting with # and duplicate keywords, so you can comment your list.

    Where is the code?

    View the code in the serp-api-rank-checker folder. The same checker is Check Keyword Rank in Desearch Web Results.

    Put your next idea to work.

    Try a query in the playground, then use the docs to bring Desearch into your application.

    Browse more articles