Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(search): add DeepSeek as a web search provider and crawler (#21298)

LiJian9026d016e260
diff --git a/apps/cli/src/commands/search.ts b/apps/cli/src/commands/search.ts
index e6437d4ca19..6429edc990b 100644
--- a/apps/cli/src/commands/search.ts
+++ b/apps/cli/src/commands/search.ts
@@ -88,7 +88,7 @@ export function registerSearchCommand(program: Command) {
.option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
.option(
'-i, --impl <impls>',
- 'Crawler implementations for web URLs (comma-separated: browserless, exa, firecrawl, jina, naive, search1api, tavily)',
+ 'Crawler implementations for web URLs (comma-separated: browserless, deepseek, exa, firecrawl, jina, naive, search1api, tavily)',
)
.action(
async (
@@ -245,7 +245,9 @@ async function crawlView(url: string, options: { impl?: string; json?: string |
const toolsClient = await getToolsTrpcClient();
const input: {
- impls?: ('browserless' | 'exa' | 'firecrawl' | 'jina' | 'naive' | 'search1api' | 'tavily')[];
+ impls?: (
+ 'browserless' | 'deepseek' | 'exa' | 'firecrawl' | 'jina' | 'naive' | 'search1api' | 'tavily'
+ )[];
urls: string[];
} = { urls: [url] };
diff --git a/apps/server/src/routers/tools/search.ts b/apps/server/src/routers/tools/search.ts
index e94e3abc49e..2cf8babc591 100644
--- a/apps/server/src/routers/tools/search.ts
+++ b/apps/server/src/routers/tools/search.ts
@@ -57,7 +57,16 @@ export const searchRouter = router({
.input(
z.object({
impls: z
- .enum(['browserless', 'exa', 'firecrawl', 'jina', 'naive', 'search1api', 'tavily'])
+ .enum([
+ 'browserless',
+ 'deepseek',
+ 'exa',
+ 'firecrawl',
+ 'jina',
+ 'naive',
+ 'search1api',
+ 'tavily',
+ ])
.array()
.optional(),
urls: z.string().array(),
diff --git a/apps/server/src/services/search/impls/deepseek/index.test.ts b/apps/server/src/services/search/impls/deepseek/index.test.ts
new file mode 100644
index 00000000000..b455edd805e
--- /dev/null
+++ b/apps/server/src/services/search/impls/deepseek/index.test.ts
@@ -0,0 +1,161 @@
+// @vitest-environment node
+import { TRPCError } from '@trpc/server';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { buildDeepSeekQuery, DeepSeekImpl } from './index';
+
+const createMockResponse = (body: object, ok = true, status = 200, statusText = 'OK') =>
+ ({
+ ok,
+ status,
+ statusText,
+ json: vi.fn().mockResolvedValue(body),
+ text: vi.fn().mockResolvedValue(JSON.stringify(body)),
+ }) as unknown as Response;
+
+const getRequestBody = () => JSON.parse(vi.mocked(fetch).mock.calls[0][1]!.body as string);
+
+describe('DeepSeekImpl', () => {
+ let impl: DeepSeekImpl;
+
+ beforeEach(() => {
+ impl = new DeepSeekImpl();
+ vi.stubGlobal('fetch', vi.fn());
+ process.env.DEEPSEEK_SEARCH_API_KEY = 'test-search-key';
+ });
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+ delete process.env.DEEPSEEK_SEARCH_API_KEY;
+ delete process.env.DEEPSEEK_API_KEY;
+ });
+
+ it('should opt into automatic search engine selection', () => {
+ expect(new DeepSeekImpl().useAutoSearchEngineSelection).toBe(true);
+ });
+
+ it('should call the search endpoint and map results', async () => {
+ vi.mocked(fetch).mockResolvedValue(
+ createMockResponse({
+ results: [
+ {
+ authority: 3,
+ content: '',
+ date: '2026-10-16T16:00:00+00:00',
+ rerank_score: 2.2,
+ site_icon: null,
+ site_name: 'Hugging Face',
+ snippet: 'Short snippet',
+ summary: 'Longer summary for the model',
+ title: 'DeepSeek-V4',
+ url: 'https://huggingface.co/collections/deepseek-ai/deepseek-v4',
+ },
+ { snippet: 'Only snippet', url: 'https://example.com/a' },
+ ],
+ }),
+ );
+
+ const result = await impl.query('DeepSeek V4');
+
+ expect(fetch).toHaveBeenCalledWith(
+ 'https://api.deepseek.com/v1/tools/search',
+ expect.objectContaining({
+ headers: { 'Authorization': 'Bearer test-search-key', 'Content-Type': 'application/json' },
+ method: 'POST',
+ }),
+ );
+ expect(getRequestBody()).toEqual({ count: 10, need_content: false, query: 'DeepSeek V4' });
+ expect(result.query).toBe('DeepSeek V4');
+ expect(result.resultNumbers).toBe(2);
+ expect(result.results).toEqual([
+ {
+ category: 'general',
+ content: 'Longer summary for the model',
+ engines: ['deepseek'],
+ parsedUrl: 'huggingface.co',
+ publishedDate: '2026-10-16T16:00:00+00:00',
+ score: 2.2,
+ title: 'DeepSeek-V4',
+ url: 'https://huggingface.co/collections/deepseek-ai/deepseek-v4',
+ },
+ {
+ category: 'general',
+ content: 'Only snippet',
+ engines: ['deepseek'],
+ parsedUrl: 'example.com',
+ publishedDate: undefined,
+ score: 0,
+ title: '',
+ url: 'https://example.com/a',
+ },
+ ]);
+ });
+
+ it('should fall back to the DeepSeek model provider key', async () => {
+ delete process.env.DEEPSEEK_SEARCH_API_KEY;
+ process.env.DEEPSEEK_API_KEY = 'model-key';
+ vi.mocked(fetch).mockResolvedValue(createMockResponse({ results: [] }));
+
+ const result = await impl.query('test');
+
+ expect(vi.mocked(fetch).mock.calls[0][1]!.headers).toMatchObject({
+ Authorization: 'Bearer model-key',
+ });
+ expect(result.resultNumbers).toBe(0);
+ });
+
+ it('should throw SERVICE_UNAVAILABLE on non-ok responses', async () => {
+ vi.mocked(fetch).mockResolvedValue(
+ createMockResponse(
+ { error: { message: 'Authentication Fails', type: 'authentication_error' } },
+ false,
+ 401,
+ 'Unauthorized',
+ ),
+ );
+
+ await expect(impl.query('test')).rejects.toMatchObject({
+ code: 'SERVICE_UNAVAILABLE',
+ message: 'DeepSeek request failed: Unauthorized',
+ });
+ });
+
+ it('should throw SERVICE_UNAVAILABLE when the request cannot be sent', async () => {
+ vi.mocked(fetch).mockRejectedValue(new TypeError('fetch failed'));
+
+ await expect(impl.query('test')).rejects.toBeInstanceOf(TRPCError);
+ await expect(impl.query('test')).rejects.toMatchObject({ code: 'SERVICE_UNAVAILABLE' });
+ });
+
+ it('should send the time range as an after: operator', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(new Date('2026-10-20T08:00:00Z'));
+ vi.mocked(fetch).mockResolvedValue(createMockResponse({ results: [] }));
+
+ await impl.query('news', { searchTimeRange: 'week' });
+
+ expect(getRequestBody().query).toBe('news after:2026-10-13');
+ });
+});
+
+describe('buildDeepSeekQuery', () => {
+ it('should keep short queries and ignore anytime', () => {
+ expect(buildDeepSeekQuery(' hello world ', { searchTimeRange: 'anytime' })).toBe(
+ 'hello world',
+ );
+ });
+
+ it('should truncate long queries to the 128 character limit', () => {
+ const query = buildDeepSeekQuery('搜'.repeat(200));
+
+ expect(Array.from(query)).toHaveLength(128);
+ });
+
+ it('should keep the time range operator when truncating', () => {
+ const query = buildDeepSeekQuery('a'.repeat(200), { searchTimeRange: 'day' });
+
+ expect(query).toHaveLength(128);
+ expect(query).toMatch(/ after:\d{4}-\d{2}-\d{2}$/);
+ });
+});
diff --git a/apps/server/src/services/search/impls/deepseek/index.ts b/apps/server/src/services/search/impls/deepseek/index.ts
new file mode 100644
index 00000000000..1a2ecd7b83e
--- /dev/null
+++ b/apps/server/src/services/search/impls/deepseek/index.ts
@@ -0,0 +1,149 @@
+import {
+ type SearchParams,
+ type UniformSearchResponse,
+ type UniformSearchResult,
+} from '@lobechat/types';
+import { TRPCError } from '@trpc/server';
+import debug from 'debug';
+import urlJoin from 'url-join';
+
+import { type SearchServiceImpl } from '../type';
+import { type DeepSeekSearchParameters, type DeepSeekSearchResponse } from './type';
+
+const log = debug('lobe-search:DeepSeek');
+
+/**
+ * DeepSeek rejects queries longer than this (counted in Unicode characters)
+ */
+const MAX_QUERY_LENGTH = 128;
+
+const TIME_RANGE_DAYS: Record<string, number> = { day: 1, month: 30, week: 7, year: 365 };
+
+/**
+ * DeepSeek has no time-range parameter; it filters by the `after:` query operator instead
+ */
+const getTimeRangeOperator = (searchTimeRange?: string): string | undefined => {
+ const days = searchTimeRange ? TIME_RANGE_DAYS[searchTimeRange] : undefined;
+ if (days === undefined) return;
+
+ const after = new Date(Date.now() - days * 86_400 * 1000).toISOString().slice(0, 10);
+
+ return `after:${after}`;
+};
+
+/**
+ * Build the query sent to DeepSeek: append the time-range operator and truncate the
+ * user's query so the whole string stays within the length limit instead of failing with 400
+ */
+export const buildDeepSeekQuery = (query: string, params: SearchParams = {}): string => {
+ const operator = getTimeRangeOperator(params.searchTimeRange);
+ const suffix = operator ? ` ${operator}` : '';
+ const base = Array.from(query.trim())
+ .slice(0, MAX_QUERY_LENGTH - suffix.length)
+ .join('')
+ .trim();
+
+ return `${base}${suffix}`;
+};
+
+/**
+ * DeepSeek implementation of the search service
+ * @see https://api-docs.deepseek.com/zh-cn/guides/search
+ */
+export class DeepSeekImpl implements SearchServiceImpl {
+ // DeepSeek picks its own sources, so retrying without `searchEngines` would repeat the same request
+ readonly useAutoSearchEngineSelection = true;
+
+ private get apiKey(): string | undefined {
+ // Fall back to the model provider key so a single DeepSeek key enables search too
+ return process.env.DEEPSEEK_SEARCH_API_KEY || process.env.DEEPSEEK_API_KEY;
+ }
+
+ private get baseUrl(): string {
+ return 'https://api.deepseek.com';
+ }
+
+ async query(query: string, params: SearchParams = {}): Promise<UniformSearchResponse> {
+ log(
+ 'Starting DeepSeek query (query length: %d, timeRange: %s)',
+ query.length,
+ params.searchTimeRange,
+ );
+ const endpoint = urlJoin(this.baseUrl, '/v1/tools/search');
+
+ const body: DeepSeekSearchParameters = {
+ count: 10,
+ need_content: false,
+ query: buildDeepSeekQuery(query, params),
+ };
+
+ let response: Response;
+ const startAt = Date.now();
+ let costTime: number;
+ try {
+ log('Sending request to endpoint: %s', endpoint);
+ response = await fetch(endpoint, {
+ body: JSON.stringify(body),
+ headers: {
+ 'Authorization': this.apiKey ? `Bearer ${this.apiKey}` : '',
+ 'Content-Type': 'application/json',
+ },
+ method: 'POST',
+ });
+ log('Received response with status: %d', response.status);
+ costTime = Date.now() - startAt;
+ } catch (error) {
+ log.extend('error')('DeepSeek fetch error: %o', error);
+ throw new TRPCError({
+ cause: error,
+ code: 'SERVICE_UNAVAILABLE',
+ message: 'Failed to connect to DeepSeek.',
+ });
+ }
+
+ if (!response.ok) {
+ const errorBody = await response.text();
+ log.extend('error')(
+ `DeepSeek request failed with status ${response.status}: %s`,
+ errorBody.length > 200 ? `${errorBody.slice(0, 200)}...` : errorBody,
+ );
+ throw new TRPCError({
+ cause: errorBody,
+ code: 'SERVICE_UNAVAILABLE',
+ message: `DeepSeek request failed: ${response.statusText}`,
+ });
+ }
+
+ try {
+ const deepseekResponse = (await response.json()) as DeepSeekSearchResponse;
+
+ const mappedResults = (deepseekResponse.results || []).map((result): UniformSearchResult => ({
+ category: 'general',
+ // `summary` is the longer excerpt DeepSeek prepares for model reading
+ content: result.summary || result.snippet || '',
+ engines: ['deepseek'],
+ parsedUrl: result.url ? new URL(result.url).hostname : '',
+ publishedDate: result.date || undefined,
+ score: result.rerank_score || 0,
+ title: result.title || '',
+ url: result.url,
+ }));
+
+ log('Mapped %d results to SearchResult format', mappedResults.length);
+
+ return {
+ costTime,
+ query,
+ resultNumbers: mappedResults.length,
+ results: mappedResults,
+ };
+ } catch (error) {
+ log.extend('error')('Error parsing DeepSeek response: %o', error);
+ throw new TRPCError({
+ cause: error,
+ code: 'INTERNAL_SERVER_ERROR',
+ message: 'Failed to parse DeepSeek response.',
+ });
+ }
+ }
+}
diff --git a/apps/server/src/services/search/impls/deepseek/type.ts b/apps/server/src/services/search/impls/deepseek/type.ts
new file mode 100644
index 00000000000..025b486f23a
--- /dev/null
+++ b/apps/server/src/services/search/impls/deepseek/type.ts
@@ -0,0 +1,39 @@
+export interface DeepSeekSearchParameters {
+ count?: number;
+ localization?: string;
+ need_content?: boolean;
+ ori_question?: string;
+ query: string;
+}
+
+interface DeepSeekSearchResult {
+ /**
+ * 0-4, -1 when unknown; >= 3 is highly authoritative
+ */
+ authority?: number;
+ content?: string;
+ /**
+ * UTC RFC 3339
+ */
+ date?: string | null;
+ /**
+ * 0-3; >= 1.5 is high quality
+ */
+ rerank_score?: number;
+ site_icon?: string | null;
+ site_name?: string | null;
+ /**
+ * ~100-200 characters, for display
+ */
+ snippet?: string;
+ /**
+ * ~600-800 characters, for the model to read
+ */
+ summary?: string;
+ title?: string;
+ url: string;
+}
+
+export interface DeepSeekSearchResponse {
+ results: DeepSeekSearchResult[];
+}
diff --git a/apps/server/src/services/search/impls/index.ts b/apps/server/src/services/search/impls/index.ts
index 81d462aeb95..7f06b1a9ad1 100644
--- a/apps/server/src/services/search/impls/index.ts
+++ b/apps/server/src/services/search/impls/index.ts
@@ -1,6 +1,7 @@
import { AnspireImpl } from './anspire';
import { BochaImpl } from './bocha';
import { BraveImpl } from './brave';
+import { DeepSeekImpl } from './deepseek';
import { ExaImpl } from './exa';
import { FirecrawlImpl } from './firecrawl';
import { GoogleImpl } from './google';
@@ -18,6 +19,7 @@ export enum SearchImplType {
Anspire = 'anspire',
Bocha = 'bocha',
Brave = 'brave',
+ DeepSeek = 'deepseek',
Exa = 'exa',
Firecrawl = 'firecrawl',
Google = 'google',
@@ -47,6 +49,10 @@ export const createSearchServiceImpl = (
return new BraveImpl();
}
+ case SearchImplType.DeepSeek: {
+ return new DeepSeekImpl();
+ }
+
case SearchImplType.Exa: {
return new ExaImpl();
}
diff --git a/docs/self-hosting/advanced/online-search.mdx b/docs/self-hosting/advanced/online-search.mdx
index 360edba94cd..64299afbb70 100644
--- a/docs/self-hosting/advanced/online-search.mdx
+++ b/docs/self-hosting/advanced/online-search.mdx
@@ -42,6 +42,7 @@ Supported crawler types are listed below:
| Value | Description | Environment Variable |
| ------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| `browserless` | Headless browser crawler based on [Browserless](https://www.browserless.io/), suitable for rendering complex pages. | `BROWSERLESS_TOKEN` |
+| `deepseek` | Web fetch API from [DeepSeek](https://api-docs.deepseek.com/guides/search), returns the page body as Markdown. | `DEEPSEEK_SEARCH_API_KEY` `DEEPSEEK_API_KEY` |
| `exa` | Crawler capabilities provided by [Exa](https://exa.ai/), API required. | `EXA_API_KEY` |
| `firecrawl` | [Firecrawl](https://firecrawl.dev/) headless browser API, ideal for modern websites. | `FIRECRAWL_API_KEY` |
| `jina` | Crawler service from [Jina AI](https://jina.ai/), supports fast content summarization. | `JINA_READER_API_KEY` |
@@ -98,19 +99,20 @@ SEARCH_PROVIDERS="searxng"
Supported search engines include:
-| Value | Description | Environment Variable |
-| ------------ | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
-| `anspire` | Search service provided by [Anspire](https://anspire.ai/). | `ANSPIRE_API_KEY` |
-| `bocha` | Search service from [Bocha](https://open.bochaai.com/). | `BOCHA_API_KEY` |
-| `brave` | [Brave](https://search.brave.com/help/api), a privacy-friendly search source. | `BRAVE_API_KEY` |
-| `exa` | [Exa](https://exa.ai/), a search API designed for AI. | `EXA_API_KEY` |
-| `firecrawl` | Search capabilities via [Firecrawl](https://firecrawl.dev/). | `FIRECRAWL_API_KEY` |
-| `google` | Uses [Google Programmable Search Engine](https://programmablesearchengine.google.com/). | `GOOGLE_PSE_API_KEY` `GOOGLE_PSE_ENGINE_ID` |
-| `jina` | Semantic search provided by [Jina AI](https://jina.ai/). | `JINA_READER_API_KEY` |
-| `kagi` | Premium search API by [Kagi](https://kagi.com/), requires a subscription key. | `KAGI_API_KEY` |
-| `search1api` | Aggregated search capabilities from [Search1API](https://www.search1api.com). | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
-| `searxng` | Use a self-hosted or public [SearXNG](https://searx.space/) instance. | `SEARXNG_URL` |
-| `tavily` | [Tavily](https://www.tavily.com/), offers fast web summaries and answers. | `TAVILY_API_KEY` |
+| Value | Description | Environment Variable |
+| ------------ | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
+| `anspire` | Search service provided by [Anspire](https://anspire.ai/). | `ANSPIRE_API_KEY` |
+| `bocha` | Search service from [Bocha](https://open.bochaai.com/). | `BOCHA_API_KEY` |
+| `brave` | [Brave](https://search.brave.com/help/api), a privacy-friendly search source. | `BRAVE_API_KEY` |
+| `deepseek` | Web search API from [DeepSeek](https://api-docs.deepseek.com/guides/search), returns summaries ready for model reading. | `DEEPSEEK_SEARCH_API_KEY` `DEEPSEEK_API_KEY` |
+| `exa` | [Exa](https://exa.ai/), a search API designed for AI. | `EXA_API_KEY` |
+| `firecrawl` | Search capabilities via [Firecrawl](https://firecrawl.dev/). | `FIRECRAWL_API_KEY` |
+| `google` | Uses [Google Programmable Search Engine](https://programmablesearchengine.google.com/). | `GOOGLE_PSE_API_KEY` `GOOGLE_PSE_ENGINE_ID` |
+| `jina` | Semantic search provided by [Jina AI](https://jina.ai/). | `JINA_READER_API_KEY` |
+| `kagi` | Premium search API by [Kagi](https://kagi.com/), requires a subscription key. | `KAGI_API_KEY` |
+| `search1api` | Aggregated search capabilities from [Search1API](https://www.search1api.com). | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
+| `searxng` | Use a self-hosted or public [SearXNG](https://searx.space/) instance. | `SEARXNG_URL` |
+| `tavily` | [Tavily](https://www.tavily.com/), offers fast web summaries and answers. | `TAVILY_API_KEY` |
> ⚠️ Some search providers require you to apply for an API Key and configure it in your `.env` file.
@@ -162,6 +164,18 @@ BROWSERLESS_STEALTH_MODE=1
---
+## `DEEPSEEK_SEARCH_API_KEY`
+
+API key for the [DeepSeek](https://api-docs.deepseek.com/guides/search) search (`SEARCH_PROVIDERS=deepseek`) and fetch (`CRAWLER_IMPLS=deepseek`) APIs. When it is not set, `DEEPSEEK_API_KEY` (the DeepSeek model provider key) is used instead, so one key covers chat, search and fetch.
+
+```env
+DEEPSEEK_SEARCH_API_KEY=sk-xxxxxx
+```
+
+> 💰 Search and fetch are billed per successful request by DeepSeek, separately from model tokens.
+
+---
+
## `GOOGLE_PSE_ENGINE_ID`
Configure the Search Engine ID for Google Programmable Search Engine (Google PSE), used to restrict the search scope. Must be used alongside `GOOGLE_PSE_API_KEY`.
diff --git a/docs/self-hosting/advanced/online-search.zh-CN.mdx b/docs/self-hosting/advanced/online-search.zh-CN.mdx
index 51b128c1574..723a8c7924e 100644
--- a/docs/self-hosting/advanced/online-search.zh-CN.mdx
+++ b/docs/self-hosting/advanced/online-search.zh-CN.mdx
@@ -34,15 +34,16 @@ CRAWLER_IMPLS="naive,search1api"
支持的爬虫类型如下:
-| 值 | 说明 | 环境变量 |
-| ------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------- |
-| `browserless` | 基于 [Browserless](https://www.browserless.io/) 的无头浏览器爬虫,适合渲染复杂页面。 | `BROWSERLESS_TOKEN` |
-| `exa` | 使用 [Exa](https://exa.ai/) 提供的爬虫能力,需申请 API。 | `EXA_API_KEY` |
-| `firecrawl` | [Firecrawl](https://firecrawl.dev/) 无头浏览器 API,适合现代网站抓取。 | `FIRECRAWL_API_KEY` |
-| `jina` | 使用 [Jina AI](https://jina.ai/) 的爬虫服务,支持快速提取摘要信息。 | `JINA_READER_API_KEY` |
-| `naive` | 内置简易通用爬虫,适用于标准网页结构。 | |
-| `search1api` | 利用 [Search1API](https://www.search1api.com) 提供的页面抓取能力,适合结构化内容提取。 | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
-| `tavily` | 使用 [Tavily](https://www.tavily.com/) 的网页抓取与摘要 API。 | `TAVILY_API_KEY` |
+| 值 | 说明 | 环境变量 |
+| ------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
+| `browserless` | 基于 [Browserless](https://www.browserless.io/) 的无头浏览器爬虫,适合渲染复杂页面。 | `BROWSERLESS_TOKEN` |
+| `deepseek` | [DeepSeek](https://api-docs.deepseek.com/zh-cn/guides/search) 提供的网页抓取 API,以 Markdown 返回正文。 | `DEEPSEEK_SEARCH_API_KEY` `DEEPSEEK_API_KEY` |
+| `exa` | 使用 [Exa](https://exa.ai/) 提供的爬虫能力,需申请 API。 | `EXA_API_KEY` |
+| `firecrawl` | [Firecrawl](https://firecrawl.dev/) 无头浏览器 API,适合现代网站抓取。 | `FIRECRAWL_API_KEY` |
+| `jina` | 使用 [Jina AI](https://jina.ai/) 的爬虫服务,支持快速提取摘要信息。 | `JINA_READER_API_KEY` |
+| `naive` | 内置简易通用爬虫,适用于标准网页结构。 | |
+| `search1api` | 利用 [Search1API](https://www.search1api.com) 提供的页面抓取能力,适合结构化内容提取。 | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
+| `tavily` | 使用 [Tavily](https://www.tavily.com/) 的网页抓取与摘要 API。 | `TAVILY_API_KEY` |
> 💡 设置多个爬虫可提升成功率,系统将根据优先级尝试不同爬虫。
@@ -93,19 +94,20 @@ SEARCH_PROVIDERS="searxng"
支持的搜索引擎如下:
-| 值 | 说明 | 环境变量 |
-| ------------ | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
-| `anspire` | 基于 [Anspire(安思派)](https://anspire.ai/) 提供的搜索服务。 | `ANSPIRE_API_KEY` |
-| `bocha` | 基于 [Bocha(博查)](https://open.bochaai.com/) 提供的搜索服务。 | `BOCHA_API_KEY` |
-| `brave` | [Brave](https://search.brave.com/help/api),隐私友好的搜索源。 | `BRAVE_API_KEY` |
-| `exa` | [Exa](https://exa.ai/),面向 AI 的搜索 API。 | `EXA_API_KEY` |
-| `firecrawl` | 支持 [Firecrawl](https://firecrawl.dev/) 提供的搜索服务。 | `FIRECRAWL_API_KEY` |
-| `google` | 使用 [Google Programmable Search Engine](https://programmablesearchengine.google.com/)。 | `GOOGLE_PSE_API_KEY` `GOOGLE_PSE_ENGINE_ID` |
-| `jina` | 使用 [Jina AI](https://jina.ai/) 提供的语义搜索服务。 | `JINA_READER_API_KEY` |
-| `kagi` | [Kagi](https://kagi.com/) 提供的高级搜索 API,需订阅 Key。 | `KAGI_API_KEY` |
-| `search1api` | 使用 [Search1API](https://www.search1api.com) 聚合搜索能力。 | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
-| `searxng` | 使用自托管或公共 [SearXNG](https://searx.space/) 实例。 | `SEARXNG_URL` |
-| `tavily` | [Tavily](https://www.tavily.com/),快速网页摘要与答案返回。 | `TAVILY_API_KEY` |
+| 值 | 说明 | 环境变量 |
+| ------------ | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
+| `anspire` | 基于 [Anspire(安思派)](https://anspire.ai/) 提供的搜索服务。 | `ANSPIRE_API_KEY` |
+| `bocha` | 基于 [Bocha(博查)](https://open.bochaai.com/) 提供的搜索服务。 | `BOCHA_API_KEY` |
+| `brave` | [Brave](https://search.brave.com/help/api),隐私友好的搜索源。 | `BRAVE_API_KEY` |
+| `deepseek` | [DeepSeek](https://api-docs.deepseek.com/zh-cn/guides/search) 提供的联网搜索 API,返回适合模型阅读的摘要。 | `DEEPSEEK_SEARCH_API_KEY` `DEEPSEEK_API_KEY` |
+| `exa` | [Exa](https://exa.ai/),面向 AI 的搜索 API。 | `EXA_API_KEY` |
+| `firecrawl` | 支持 [Firecrawl](https://firecrawl.dev/) 提供的搜索服务。 | `FIRECRAWL_API_KEY` |
+| `google` | 使用 [Google Programmable Search Engine](https://programmablesearchengine.google.com/)。 | `GOOGLE_PSE_API_KEY` `GOOGLE_PSE_ENGINE_ID` |
+| `jina` | 使用 [Jina AI](https://jina.ai/) 提供的语义搜索服务。 | `JINA_READER_API_KEY` |
+| `kagi` | [Kagi](https://kagi.com/) 提供的高级搜索 API,需订阅 Key。 | `KAGI_API_KEY` |
+| `search1api` | 使用 [Search1API](https://www.search1api.com) 聚合搜索能力。 | `SEARCH1API_API_KEY` `SEARCH1API_CRAWL_API_KEY` `SEARCH1API_SEARCH_API_KEY` |
+| `searxng` | 使用自托管或公共 [SearXNG](https://searx.space/) 实例。 | `SEARXNG_URL` |
+| `tavily` | [Tavily](https://www.tavily.com/),快速网页摘要与答案返回。 | `TAVILY_API_KEY` |
> ⚠️ 某些搜索提供商需要单独申请 API Key,并在 `.env` 中配置相关凭证。
@@ -157,6 +159,18 @@ BROWSERLESS_STEALTH_MODE=1
---
+## `DEEPSEEK_SEARCH_API_KEY`
+
+[DeepSeek](https://api-docs.deepseek.com/zh-cn/guides/search) 搜索(`SEARCH_PROVIDERS=deepseek`)与抓取(`CRAWLER_IMPLS=deepseek`)API 使用的密钥。未设置时会使用 `DEEPSEEK_API_KEY`(DeepSeek 模型服务商的密钥),一个密钥即可同时用于对话、搜索与抓取。
+
+```env
+DEEPSEEK_SEARCH_API_KEY=sk-xxxxxx
+```
+
+> 💰 搜索与抓取由 DeepSeek 按成功请求次数单独计费,与模型 token 费用分开。
+
+---
+
## `GOOGLE_PSE_ENGINE_ID`
配置 Google Programmable Search Engine(Google PSE)的搜索引擎 ID,用于限定搜索范围。需配合 `GOOGLE_PSE_API_KEY` 一起使用。
diff --git a/packages/web-crawler/src/crawImpl/__tests__/deepseek.test.ts b/packages/web-crawler/src/crawImpl/__tests__/deepseek.test.ts
new file mode 100644
index 00000000000..bf29189047b
--- /dev/null
+++ b/packages/web-crawler/src/crawImpl/__tests__/deepseek.test.ts
@@ -0,0 +1,123 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { createMockResponse } from '../../test-utils';
+import { NetworkConnectionError, PageNotFoundError } from '../../utils/errorType';
+import { withTimeout } from '../../utils/withTimeout';
+import { deepseek } from '../deepseek';
+
+vi.mock('../../utils/withTimeout', () => ({
+ DEFAULT_TIMEOUT: 10_000,
+ withTimeout: vi.fn((fn: (signal: AbortSignal) => Promise<Response>) =>
+ fn(new AbortController().signal),
+ ),
+}));
+
+const markdown = '# Example\n\nThis is a test markdown content with enough length to pass. '.repeat(
+ 3,
+);
+
+describe('deepseek crawler', () => {
+ const fetchMock = vi.fn();
+
+ beforeEach(() => {
+ vi.stubGlobal('fetch', fetchMock);
+ fetchMock.mockReset();
+ delete process.env.DEEPSEEK_SEARCH_API_KEY;
+ delete process.env.DEEPSEEK_API_KEY;
+ });
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it('should fetch the page with the search API key', async () => {
+ process.env.DEEPSEEK_SEARCH_API_KEY = 'search-key';
+ process.env.DEEPSEEK_API_KEY = 'model-key';
+ fetchMock.mockResolvedValue(createMockResponse({ content: markdown, title: 'Example' }));
+
+ const result = await deepseek('https://example.com/post', { filterOptions: {} });
+
+ expect(fetchMock).toHaveBeenCalledWith(
+ 'https://api.deepseek.com/v1/tools/fetch',
+ expect.objectContaining({
+ body: JSON.stringify({ url: 'https://example.com/post' }),
+ headers: { 'Authorization': 'Bearer search-key', 'Content-Type': 'application/json' },
+ method: 'POST',
+ }),
+ );
+ expect(withTimeout).toHaveBeenCalledWith(expect.any(Function), 20_000);
+ expect(result).toEqual({
+ content: markdown,
+ contentType: 'text',
+ length: markdown.length,
+ siteName: 'example.com',
+ title: 'Example',
+ url: 'https://example.com/post',
+ });
+ });
+
+ it('should fall back to the DeepSeek model provider key', async () => {
+ process.env.DEEPSEEK_API_KEY = 'model-key';
+ fetchMock.mockResolvedValue(createMockResponse({ content: markdown, title: 'Example' }));
+
+ await deepseek('https://example.com', { filterOptions: {} });
+
+ expect(fetchMock.mock.calls[0][1].headers.Authorization).toBe('Bearer model-key');
+ });
+
+ it('should undo the backslash escapes DeepSeek adds to the page text', async () => {
+ fetchMock.mockResolvedValue(
+ createMockResponse({
+ content: `\\# Search \\/ Fetch API\n\nPrice\\: 5 CNY \\(per 1\\,000 requests\\)\\. Path C\\:\\\\tmp\\. ${'x'.repeat(100)}`,
+ title: 'Search \\/ Fetch',
+ }),
+ );
+
+ const result = await deepseek('https://example.com', { filterOptions: {} });
+
+ expect(result?.title).toBe('Search / Fetch');
+ expect(result?.content).toBe(
+ `# Search / Fetch API\n\nPrice: 5 CNY (per 1,000 requests). Path C:\\tmp. ${'x'.repeat(100)}`,
+ );
+ });
+
+ it('should return undefined for short content', async () => {
+ fetchMock.mockResolvedValue(createMockResponse({ content: 'too short', title: '' }));
+
+ await expect(deepseek('https://example.com', { filterOptions: {} })).resolves.toBeUndefined();
+ });
+
+ it('should throw PageNotFoundError when DeepSeek cannot fetch usable content', async () => {
+ fetchMock.mockResolvedValue(
+ createMockResponse(
+ { error: { message: 'failed to fetch URL', type: 'not_found_error' } },
+ { ok: false, status: 404, statusText: 'Not Found' },
+ ),
+ );
+
+ await expect(deepseek('https://example.com', { filterOptions: {} })).rejects.toThrow(
+ PageNotFoundError,
+ );
+ });
+
+ it('should include the DeepSeek error body for other HTTP errors', async () => {
+ fetchMock.mockResolvedValue(
+ createMockResponse(
+ { error: { message: 'Insufficient Balance', type: 'invalid_request_error' } },
+ { ok: false, status: 402, statusText: 'Payment Required' },
+ ),
+ );
+
+ await expect(deepseek('https://example.com', { filterOptions: {} })).rejects.toThrow(
+ 'DeepSeek request failed with status 402: Payment Required. Response: {"error":{"message":"Insufficient Balance"',
+ );
+ });
+
+ it('should throw NetworkConnectionError for fetch failures', async () => {
+ fetchMock.mockRejectedValue(new TypeError('fetch failed'));
+
+ await expect(deepseek('https://example.com', { filterOptions: {} })).rejects.toThrow(
+ NetworkConnectionError,
+ );
+ });
+});
diff --git a/packages/web-crawler/src/crawImpl/deepseek.ts b/packages/web-crawler/src/crawImpl/deepseek.ts
new file mode 100644
index 00000000000..cec8ce215f4
--- /dev/null
+++ b/packages/web-crawler/src/crawImpl/deepseek.ts
@@ -0,0 +1,83 @@
+import type { CrawlImpl, CrawlSuccessResult } from '../type';
+import { PageNotFoundError, toFetchError } from '../utils/errorType';
+import { createHTTPStatusError, parseJSONResponse } from '../utils/response';
+import { DEFAULT_TIMEOUT, withTimeout } from '../utils/withTimeout';
+
+interface DeepSeekFetchResponse {
+ /**
+ * Page body as Markdown
+ */
+ content?: string;
+ title?: string;
+}
+
+/**
+ * DeepSeek renders uncached pages on demand, which regularly takes 5-10s+, so the
+ * shared 10s default cuts off pages it would have returned. Keep a larger
+ * `CRAWLER_TIMEOUT` when one is configured.
+ */
+const DEEPSEEK_TIMEOUT = Math.max(DEFAULT_TIMEOUT, 20_000);
+
+/**
+ * DeepSeek backslash-escapes every ASCII punctuation character in the page text
+ * (`\#`, `\.`, `\/`, ...), which shows up verbatim in previews and inflates the
+ * tokens handed to the model. Undo the escapes in a single left-to-right pass so
+ * an escaped backslash (`\\`) decodes back to one backslash.
+ */
+export const unescapeMarkdown = (text: string) =>
+ text.replaceAll(/\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, '$1');
+
+/**
+ * @see https://api-docs.deepseek.com/zh-cn/guides/search
+ */
+export const deepseek: CrawlImpl = async (url) => {
+ // Fall back to the model provider key so a single DeepSeek key enables crawling too
+ const apiKey = process.env.DEEPSEEK_SEARCH_API_KEY || process.env.DEEPSEEK_API_KEY;
+
+ let res: Response;
+
+ try {
+ res = await withTimeout(
+ (signal) =>
+ fetch('https://api.deepseek.com/v1/tools/fetch', {
+ body: JSON.stringify({ url }),
+ headers: {
+ 'Authorization': !apiKey ? '' : `Bearer ${apiKey}`,
+ 'Content-Type': 'application/json',
+ },
+ method: 'POST',
+ signal,
+ }),
+ DEEPSEEK_TIMEOUT,
+ );
+ } catch (e) {
+ throw toFetchError(e);
+ }
+
+ if (!res.ok) {
+ // DeepSeek answers 404 when no usable content could be fetched from the page
+ if (res.status === 404) {
+ throw new PageNotFoundError(res.statusText);
+ }
+
+ throw await createHTTPStatusError(res, 'DeepSeek');
+ }
+
+ const data = await parseJSONResponse<DeepSeekFetchResponse>(res, 'DeepSeek');
+
+ const content = data.content ? unescapeMarkdown(data.content) : '';
+
+ // Check if content is empty or too short
+ if (content.length < 100) {
+ return;
+ }
+
+ return {
+ content,
+ contentType: 'text',
+ length: content.length,
+ siteName: new URL(url).hostname,
+ title: data.title ? unescapeMarkdown(data.title) : '',
+ url,
+ } satisfies CrawlSuccessResult;
+};
diff --git a/packages/web-crawler/src/crawImpl/index.ts b/packages/web-crawler/src/crawImpl/index.ts
index 208b44d5254..adbfe682483 100644
--- a/packages/web-crawler/src/crawImpl/index.ts
+++ b/packages/web-crawler/src/crawImpl/index.ts
@@ -1,4 +1,5 @@
import { browserless } from './browserless';
+import { deepseek } from './deepseek';
import { exa } from './exa';
import { firecrawl } from './firecrawl';
import { jina } from './jina';
@@ -8,6 +9,7 @@ import { tavily } from './tavily';
export const crawlImpls = {
browserless,
+ deepseek,
exa,
firecrawl,
jina,
diff --git a/src/features/ToolSetting/const.tsx b/src/features/ToolSetting/const.tsx
index 3a08093d78d..17a23509bb3 100644
--- a/src/features/ToolSetting/const.tsx
+++ b/src/features/ToolSetting/const.tsx
@@ -1,4 +1,4 @@
-import { Bing, Exa, Google, Jina, Search1API, Tavily } from '@lobehub/icons';
+import { Bing, DeepSeek, Exa, Google, Jina, Search1API, Tavily } from '@lobehub/icons';
import { Icon } from '@lobehub/ui';
import { Globe } from 'lucide-react';
import type { ReactNode } from 'react';
@@ -14,6 +14,7 @@ const CHANNEL_DISPLAY_NAME: Record<string, string> = {
bocha: 'Bocha',
brave: 'Brave',
browserless: 'Browserless',
+ deepseek: 'DeepSeek',
exa: 'Exa',
firecrawl: 'Firecrawl',
google: 'Google',
@@ -36,6 +37,9 @@ export const getChannelIcon = (id: string, size = 24): ReactNode => {
case 'bing': {
return <Bing.Avatar size={size} />;
}
+ case 'deepseek': {
+ return <DeepSeek.Avatar size={size} />;
+ }
case 'exa': {
return <Exa.Avatar size={size} />;
}