JavaScript SDK Specification

    The Desearch JavaScript SDK wraps common Desearch API calls for Node.js and server-side JavaScript applications.

    Installation

    bash
    npm install desearch-js

    Initialize the client

    js
    const { Desearch } = require("desearch-js"); const desearch = new Desearch({ apiKey: process.env.DESEARCH_API_KEY });

    Do not expose production API keys in browser bundles. Call Desearch from your backend or server-side runtime.

    AI Search

    js
    const result = await desearch.aiSearch({ prompt: "latest research on AI search benchmarks", tools: ["web", "reddit", "arxiv"], date_filter: "PAST_WEEK", streaming: false, count: 10, }); console.log(result);

    Web Search

    js
    const result = await desearch.webSearch({ query: "latest AI search news", num: 10, start: 0, }); console.log(result);

    X Search

    js
    const result = await desearch.xSearch({ query: "Bittensor", sort: "Top", count: 20, }); console.log(result);

    Billing metadata

    Billable API responses expose request cost in USD through X-Desearch-Cost-Usd. Compatible JSON object responses may also include:

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

    If your SDK call returns only parsed JSON, use the SDK's raw-response or metadata option when you need headers. Arrays, text responses, and streaming responses keep their body shape, so headers are the source of truth for cost metadata.

    Troubleshooting

    • 401 — check the API key and server environment variable.
    • 422 — check request body fields, enum values, and endpoint-specific required fields.
    • 429 — add backoff/retry or review account limits.

    For all endpoint schemas, use the API Reference.