← Back to notes
DEVELOPER NOTES

DeepSeek Search and Fetch API:
a Python example

We used DeepSeek Search to find NIST’s 2026 daylight-saving rules. It returned the rules page and two historical PDFs. For that question, we would fetch the current rules page and pass its relevant passage to a model.

Requesting every result’s full text grew our serialized response from about 6.7 KB to 42.3 KB. A publication-date filter caused another problem: it dropped the source we wanted.

Start with Search, then choose a page to Fetch

The Search endpoint finds candidate pages; the Fetch endpoint retrieves a selected URL. Both accept JSON requests with a DeepSeek bearer API key. They are separate endpoints, so you can use them from a script without asking a chat model to generate an answer.

Set DEEPSEEK_API_KEY in your environment and run this with Python 3. It uses the standard library:

import json
import os
from urllib.error import HTTPError
from urllib.parse import urldefrag, urlsplit
from urllib.request import Request, urlopen

API_KEY = os.environ["DEEPSEEK_API_KEY"]
BASE_URL = "https://api.deepseek.com/v1/tools/"

def post(tool, payload):
    request = Request(
        BASE_URL + tool,
        data=json.dumps(payload).encode("utf-8"),
        headers={
            "Authorization": "Bearer " + API_KEY,
            "Content-Type": "application/json",
        },
        method="POST",
    )
    try:
        with urlopen(request, timeout=30) as response:
            return json.load(response)
    except HTTPError as error:
        print("HTTP", error.code, error.read().decode("utf-8"))
        raise

search = post("search", {
    "query": "site:nist.gov daylight saving time 2026",
    "count": 3,
    "need_content": False,
})

for result in search["results"]:
    print(result["title"], result["url"], result.get("date"))

# Choose a source deliberately. This example is specific to NIST.
candidate = next((
    result for result in search["results"]
    if urlsplit(result["url"]).scheme == "https"
    and urlsplit(result["url"]).hostname == "www.nist.gov"
), None)
if candidate is None:
    raise SystemExit("No matching NIST source; review the results.")

source_url = urldefrag(candidate["url"]).url
page = post("fetch", {"url": source_url})
print(page["title"])
print(page["content"][:500])

need_content stays false here because we are choosing one source ourselves. The host check is specific to this NIST example; change it when you change the task. An empty or unexpected result set stops the script before it tries to fetch a page.

When to ask Search for the full text

Search can include page content in the same response. Set need_content to true if you need several result pages, and inspect the returned text before deciding whether a separate Fetch is necessary. Individual pages can still have unavailable content.

We repeated the query site:nist.gov daylight saving time 2026 with a count of 3. Both settings returned three results:

need_contentContent charactersSerialized JSON bytes
false06,740
true35,16042,318

The false response still included snippet and summary. It was enough to inspect the candidates. Turning content on brought back the historical PDFs as well as the current rules page, adding text we did not need for this question.

For a broad research task, those extra documents might be useful. For a narrow fact check, we would start with the summaries and read the chosen source. Fetch adds a request, but passing unnecessary documents to a model can add its own cost and make the answer harder to verify.

A broader workflow makes a different trade-off. Reddit user u/PocketManey described building a multi-source answer pipeline with DeepSeek Search and Fetch: request page text with the search results, then fetch only where usable text is missing. Their warning that models “over-cite” comes with a separate step to check citations and repair unsupported sentences. That is a useful distinction: retrieving the page does not establish that it supports the answer. We have not reproduced their pipeline or verified its cost and timing estimates.

The byte counts above came from len(json.dumps(response, ensure_ascii=False).encode("utf-8")). The roughly 6.3-fold difference is a comparison of these two serialized responses, not compressed network traffic or model tokens.

The date filter lost an up-to-date page

The first result was NIST’s Daylight Saving Time Rules page. Its API date was 2010-03-01T16:00:00+00:00. The page text, however, contained the 2026 rule and an update note dated February 9, 2026.

We added an after filter:

{
  "query": "site:nist.gov daylight saving time 2026 after:2026-01-01",
  "count": 3,
  "need_content": false
}

That request returned HTTP 200 with {"results": []}. The official guide describes after as a publication-date filter. A recently updated page can still have an old publication date; our query lost a useful source carrying current information.

One query pair cannot tell us how every document is dated. It is enough to change how we would troubleshoot an empty search: remove the date restriction and inspect the source’s update note before concluding that no current information exists. This matters for documentation and reference pages that are maintained at the same URL for years.

For the clock-change question itself, our US–UK daylight-saving guide links the underlying sources.

Count the requests, then consider the text

On October 18, 2026, DeepSeek listed direct Search and Fetch at $0.75 per 1,000 successful requests each. The result count does not change that unit price. At those rates, 1,000 searches with one successful Fetch each cost $1.50 in retrieval requests; three Fetch calls per search make that $3.00. Model tokens and other charges are separate.

The temporary free period for integrated server-side tools is a different calling route. DeepSeek’s announcement says billing for those calls through DeepSeek Harness, Claude Code and Codex starts October 31, 2026 at 16:00 UTC — November 1 at 00:00 Beijing time. Our examples use the direct JSON endpoints.

The error we reproduced was straightforward: count: 0 returned HTTP 400 with invalid_request_error and the allowed range, 1–50. Fix the parameter before trying again. An HTTP 200 empty list, like our date-filter result, is a separate case and needs ordinary empty-result handling.

The API guide excludes failed requests, empty searches and timeouts from billing, and recommends waiting and retrying for HTTP 408, 429 and 5xx errors. Those transient failures were not part of our test. Before adding this to an agent, check the current limits and inspect a saved response; the JSON formatter can help separate the fields you plan to display from the text you plan to send to a model.

Where the API is being integrated

The direct endpoints are already appearing in public agent and chat-app code. These examples show different choices about how much text to retrieve and where to put the integration. We reviewed the linked source on October 18, 2026; this does not establish which released app versions include it or how well their search results perform.

OpenClaw

OpenClaw sends need_content: false and uses the summary, falling back to the snippet when needed. Unsupported filter fields produce an error with advice to use query operators. Moving an agent between providers means checking its filter parameters as well as changing the API key.

pi-web-access

Here a recency setting becomes an after: operator. The plugin checks the complete query length, including operators, and caps the returned summary. A friendly “recent results” control still invokes a publication-date filter, with the same risk to maintained reference pages illustrated by our NIST query.

Kelivo

Kelivo keeps Search and Fetch in separate methods. Search asks for summaries without page content; Fetch retrieves the selected page text. This is the same two-step retrieval choice as our Python example, inside an app’s provider interface.

BetterSearch

BetterSearch wraps the endpoints in search, fetch, batch and report commands. Its client throttles requests, retries selected failures and estimates retrieval cost from successful requests. A report still needs source review, and the estimate needs to be reconciled with the account bill.

Smart Reader

Smart Reader calls the endpoints from a Rust backend, using the DeepSeek credential in the app’s key storage. That retrieval path is separate from its chat route. The model writing an answer and the service retrieving its sources can be configured independently.

These are integration examples, not a provider-quality comparison. To choose a setup, run the same questions you actually need answered, inspect the returned pages and check whether the final citations support the answer. A working adapter alone cannot settle those questions.

Test notes

We made seven direct requests on one account: an initial Search, Fetch calls for example.com and NIST, a Search with count 0, the two need_content comparison requests, and the date-filtered Search. NIST’s fetched text included the 2026 rule. The displayed Python example was also run against those saved responses and an empty-result fixture, without extra paid calls.

Requests recorded – (UTC), using Python’s urllib client. This was a small retrieval task. We did not compare providers, load-test retries, check an invoice or test an MCP setup.