Python SDK Specification

    The Desearch Python SDK wraps common Desearch API calls so Python applications can search, retrieve results, and read billing metadata without hand-writing every HTTP request.

    Installation

    bash
    pip install desearch-py

    Initialize the client

    python
    import os from desearch_py import Desearch desearch = Desearch(api_key=os.environ["DESEARCH_API_KEY"])

    Do not hardcode production API keys. Store them in environment variables or a secret manager.

    AI Search

    python
    result = desearch.ai_search( prompt="latest research on AI search benchmarks", tools=["web", "reddit", "arxiv"], date_filter="PAST_WEEK", streaming=False, count=10, ) print(result)

    Web Search

    python
    result = desearch.web_search( query="latest AI search news", num=10, start=0, ) print(result)

    X Search

    python
    result = desearch.x_search( query="Bittensor", sort="Top", count=20, ) print(result)

    Billing metadata

    When the SDK returns raw response metadata or exposes headers, read request cost from X-Desearch-Cost-Usd. For JSON object responses, the API may also include:

    json
    { "cost_usd": 0.00015, "usage_count": 10, "service": "/desearch/ai/search", "currency": "USD" }

    Arrays, text responses, and streaming responses keep their original body shape, so use headers for cost metadata.

    Troubleshooting

    • 401 — check DESEARCH_API_KEY and whether the key is active in Console.
    • 422 — check parameter names, enum values, and endpoint-specific required fields.
    • 429 — reduce concurrency or check account limits.

    For the full generated method list and schemas, use the API Reference.