Web Search

Use the built-in webSearch tool to let the model search the web for real-time information.

webSearch is a built-in web search tool in deepseek-kit, powered by the DeepSeek Anthropic-compatible endpoint. It enables the model to search the web for real-time information — recent events, current data, documentation lookups, or fact-checking — breaking through the limitations of training data.

Basic Usage

Call webSearch() directly to create a tool, then pass it to an agent:

import { createAgent, createModel, webSearch } from 'deepseek-kit'

const model = createModel({ model: 'deepseek-v4-flash' })

const agent = createAgent({
  model,
  tools: [webSearch()],
})

const result = await agent.generate({
  prompt: 'Who won the 2024 Nobel Prize in Physics?',
})

console.log(result.text)

You can also use it with generateText:

import { createModel, generateText, webSearch } from 'deepseek-kit'

const model = createModel({ model: 'deepseek-v4-flash' })

const result = await generateText({
  model,
  tools: [webSearch()],
  messages: [{ role: 'user', content: 'What are the new features in React 19?' }],
})

Configuration Options

webSearch() accepts an optional configuration object:

const searchTool = webSearch({
  thinking: 'enabled',
  maxTokens: 32768,
})
  • thinking ('enabled' | 'disabled', default 'enabled') — Whether to enable thinking mode. When enabled, the model reasons before searching, improving the quality of search results.
  • maxTokens (number, default 32768) — Maximum number of tokens for the search response.

How It Works

The webSearch workflow is as follows:

  1. Sends the user query to the DeepSeek Anthropic-compatible endpoint (https://api.deepseek.com/anthropic)
  2. Uses Anthropic's web_search_20250305 tool to perform the search
  3. The model generates a summary answer based on the search results
  4. Returns formatted search results, including a summary and source links

The returned result includes:

  • Search result summary — A comprehensive answer generated by the model based on search results
  • Source list — Titles, URLs, and page dates of the found web pages

Combining with Other Tools

webSearch can be used alongside other tools. The model will autonomously choose which tool to call based on context:

import { createAgent, createModel, tool, webSearch } from 'deepseek-kit'
import { z } from 'zod'

const calculatorTool = tool({
  name: 'calculator',
  description: 'Perform mathematical calculations',
  schema: z.object({ expression: z.string().describe('Mathematical expression') }),
  execute: async (input) => evaluate(input.expression),
})

const agent = createAgent({
  model,
  tools: [webSearch(), calculatorTool],
})

const result = await agent.generate({
  prompt: 'Who won the 2024 World Cup? Also calculate 123 * 456 for me.',
})

Cancellation Support

webSearch supports cancellation of in-progress search requests via AbortSignal:

const controller = new AbortController()

const result = await agent.generate({
  prompt: 'Search for the latest AI news',
  signal: controller.signal,
})

// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000)

API Reference

WebSearchOptions

thinking'enabled' | 'disabled'
'enabled'
Whether to enable thinking mode. When enabled, the model reasons before searching, improving search result quality.
maxTokensnumber
32768
Maximum number of tokens for the search response.