Back to use cases

    Use case / AI SEARCH / Python 3 / Published

    Build an AI Fact Checker That Finds Sources for Any Claim in Python

    Paste a claim and get linked web sources that back it or push back on it, a summary that keeps only cited sentences, and how the topic is discussed on X.

    Card for Build an AI Fact Checker That Finds Sources for Any Claim in Python

    This AI fact checker is a small web app for anyone who wants to see the sources behind a claim before repeating it. Paste one claim and get web sources that back it or push back on it, each with a link, a short summary that keeps only sentences tied to a returned source, and how the topic is discussed on X. It helps you find sources; you still read them and decide.

    The problem

    A claim shows up in a chat, a post or an AI answer, and checking it means opening a search engine, reading several pages and looking for who said what. A summary without links is hard to trust, and a list of links without context takes time to read. Most people want the few sources that matter, with the sentence that backs each point.

    What the app does

    • Takes one claim, 8 to 200 characters.
    • Returns web sources, deduplicated, each with a link, a snippet and a cue label: supports, contradicts or unclear.
    • Shows a summary in which every sentence cites one of the returned sources. Sentences that cite nothing are hidden and counted.
    • Shows "No strong sources found" when fewer than two sources match most of the claim's key words.
    • Adds X posts about the topic that contain all the search words, with authors shown as "a user".
    • Can also search Wikipedia, and serves the same result as JSON from GET /api/check.

    How it works

    1. Check the input. Blank, too short or junk claims get a 400 before any paid call.
    2. Find web sources. POST /desearch/ai/search with tools: ["web"], result_type: "LINKS_WITH_FINAL_SUMMARY" and count: 10 returns sources plus a summary that cites them.
    3. See the conversation on X. GET /twitter with the claim's first 4 key words, sort: "Top" and count: 10, run at the same time as step 2.
    4. Label and filter. Each source gets a keyword cue label, summary sentences are kept only when every link they cite is a returned source, and X posts are kept only when they contain all the search words.
    5. Serve. The page and the JSON endpoint share the same code, with a 6-hour cache header so repeat claims are answered from a CDN.

    The code

    The core call, copied from the example's README. The key is read from the DESEARCH_API_KEY env var:

    BASH
    curl -s https://api.desearch.ai/desearch/ai/search \
      -H "Authorization: $DESEARCH_API_KEY" -H "Content-Type: application/json" \
      -d '{"prompt": "Octopuses have three hearts and blue blood", "tools": ["web"], "streaming": false, "result_type": "LINKS_WITH_FINAL_SUMMARY", "count": 10}'

    The response holds search (each source's title, link, snippet and highlights) and completion, a summary that cites sources as [n](url).

    The folder layout:

    • factcheck/core.py: input checks, request bodies, source cleanup, cue labels, citation check, X post filter, rate limiter, spend cap and cache. No network.
    • factcheck/client.py: the plain-HTTP Desearch client.
    • factcheck/service.py: the /api/check logic shared by the local server and the hosted function.
    • api/check.py, public/index.html, vercel.json: the hosted version.
    • app.py: local server and CLI. test_core.py: offline tests.

    Endpoints

    • POST /desearch/ai/search
    • GET /twitter

    Example output

    A saved run on 2026-10-18 for the claim "The Great Wall of China is visible from space with the naked eye" made 2 calls and cost $0.0055.

    What came backCount
    Web sources holding most of the claim's key words10 of 10
    Sources labelled contradicts10
    Cited summary sentences shown3
    Uncited summary sentences hidden1
    X posts that passed the on-topic filter1 of 10

    The top sources included BBC Sky at Night Magazine, Wikipedia and Britannica. One cited summary line reads: "The myth that it is visible from space predates space travel and originated from a 1932 Ripley's Believe It or Not cartoon, but has been debunked by astronaut observations and scientific explanations."

    A made-up claim in the same run came back with every source labelled unclear, and the app showed "No strong sources found" instead of a summary.

    Run it yourself

    BASH
    python3 -m pip install -r requirements-dev.txt   # only pytest, for the tests
    export DESEARCH_API_KEY_FILE=/path/to/key         # or DESEARCH_API_KEY=your_key, or --key-file
    python3 app.py                                    # web app at http://127.0.0.1:8000

    For a one-off check from the command line:

    BASH
    python3 app.py --cli "Humans only use 10 percent of their brain" --wiki --json out.json --html out.html
    • --wiki (or wiki=1 on /api/check) also searches Wikipedia, with one more call.
    • --json and --html save the full result as data or as a page.
    • --log-dir runs/today saves each API call with the key removed.

    What it costs

    Measured on 2026-10-18 from the X-Desearch-Cost-Usd header, and the same on 2026-10-19: $0.004 for the web search and $0.0015 for the X search, so $0.0055 per check, or $0.0095 with Wikipedia. Checks served from the cache cost nothing. The hosted version has a daily spend cap, $1.00 by default. See pricing.

    Demo

    The live demo is paused, and the sample shows a real saved run. Demo. Saved sample run.

    Ideas to extend it

    • Limit sources to sites you trust with include_domains, for example a science magazine and an encyclopedia.
    • Add a browser button that sends the selected text on any page to /api/check.
    • Check every factual sentence in a draft article and list the ones with no strong sources.
    • Give an agent /api/check as a tool so it attaches sources before it answers.

    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.

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

    Prompt you can paste for this example:

    Use Desearch to gather sources for the claim I give you. Search the web, keep summary lines that cite those sources, and search X for posts that contain the search words. Show the links and the cue labels. Do not decide whether the claim is true. Do not invent sources.

    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