DeepSeek 網頁搜尋與擷取
選擇直接搜尋、擷取網頁,或讓模型使用網頁工具產生回答。
選擇呼叫方式
| 需求 | 呼叫方式 |
|---|---|
| 依關鍵字尋找網頁,自行處理結果 | Search 傳回連結、摘要與選用正文,不需要 model |
| 已有 URL,需要讀取正文 | Fetch 傳回網頁標題與 Markdown 正文,不需要 model |
| 需要模型查資料後直接回答 | 透過 Responses 或 Messages 宣告伺服器端網頁工具,由模型選擇並執行操作 |
以下請求使用平台 API Key;獨立介面與模型工具均可能產生呼叫費用。
直接搜尋與擷取
1. 搜尋網頁
curl 'https://api.agtcloud.ai/v1/tools/search' \
-H 'Authorization: Bearer your-api-key' \
-H 'Content-Type: application/json' \
--data '{
"query": "DeepSeek site:api-docs.deepseek.com",
"count": 5,
"need_content": false
}'從 results 選擇相關網頁,讀取其 url。沒有符合結果時,調整搜尋詞或範圍;需要在搜尋結果中同時取得正文,可設定 need_content: true。
2. 擷取選定網頁
將下方 URL 替換為上一步選定的 results[].url:
curl 'https://api.agtcloud.ai/v1/tools/fetch' \
-H 'Authorization: Bearer your-api-key' \
-H 'Content-Type: application/json' \
--data '{
"url": "https://example.com/"
}'讀取 title 與 content,將 Markdown 正文用於顯示、檢索或後續模型輸入。每次成功搜尋與擷取分別計費,搜尋傳回多筆結果仍只計一次搜尋請求。
讓模型呼叫網頁工具
將 MODEL_ID 替換為支援對應工具的完整模型 ID。工具由伺服器端執行,用戶端不需要自行搜尋或回傳工具結果。
選擇 deepseek-v4-pro。web_search 可執行搜尋與開啟網頁,不需要另外宣告 Fetch 工具。
curl 'https://api.agtcloud.ai/v1/responses' \
-H 'Authorization: Bearer your-api-key' \
-H 'Content-Type: application/json' \
--data '{
"model": "MODEL_ID",
"reasoning": {"effort": "none"},
"max_output_tokens": 4096,
"tools": [{"type": "web_search"}],
"input": "搜尋 Python 官方網站,讀取相關網頁後簡要介紹它的用途,並提供來源連結。"
}'完整請求與回應結構見 Responses 與 Messages。
查看結果與用量
| 呼叫方式 | 讀取位置與意義 |
|---|---|
| 獨立 Search/Fetch | Search 讀取 results,Fetch 讀取 title/content;回應不額外傳回 usage |
| Responses 結果 | output 中的 web_search_call 描述網頁操作,最終回答位於 message 的文字內容中 |
| Responses 用量 | usage.server_tool_use.tool_search 為成功搜尋查詢次數,一次工具呼叫包含多個查詢時可能計為多次;tool_fetch 為成功讀取網頁的次數,包括開啟網頁與在網頁內尋找文字。兩項均為零時,會省略 server_tool_use |
| Messages 結果 | content 中包含 server_tool_use、web_search_tool_result 與最終回答的文字區塊 |
| Messages 用量 | usage.server_tool_use.web_search_requests 統計嘗試次數,可能包含失敗或超過 max_uses 的嘗試;tool_search 統計成功且有結果的搜尋次數,平台依成功次數計搜尋費 |
| 串流用量 | Responses 從最後的 response.completed/incomplete/failed 的 response.usage 讀取;Messages 從最後的 message_delta.usage 讀取累積值,不與初始事件相加 |
宣告工具不保證模型一定執行搜尋,實際次數以傳回用量為準。Responses 的 max_tool_calls 會被忽略,提示詞中的次數要求也不能作為計費次數上限。