search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Search Skill

搜索Skill

Search the web and get relevant results optimized for LLM consumption.
使用网页搜索并获取针对LLM使用优化的相关结果。

Prerequisites

前提条件

Tavily API Key Required - Get your key at https://tavily.com
Add to
~/.claude/settings.json
:
json
{
  "env": {
    "TAVILY_API_KEY": "tvly-your-api-key-here"
  }
}
需要Tavily API密钥 - 前往https://tavily.com获取你的密钥。
添加到
~/.claude/settings.json
json
{
  "env": {
    "TAVILY_API_KEY": "tvly-your-api-key-here"
  }
}

Quick Start

快速开始

Using the Script

使用脚本

bash
./scripts/search.sh '<json>'
Examples:
bash
undefined
bash
./scripts/search.sh '<json>'
示例:
bash
undefined

Basic search

基础搜索

./scripts/search.sh '{"query": "python async patterns"}'
./scripts/search.sh '{"query": "python async patterns"}'

With options

带选项的搜索

./scripts/search.sh '{"query": "React hooks tutorial", "max_results": 10}'
./scripts/search.sh '{"query": "React hooks tutorial", "max_results": 10}'

Advanced search with filters

带过滤器的高级搜索

./scripts/search.sh '{"query": "AI news", "topic": "news", "time_range": "week", "max_results": 10}'
./scripts/search.sh '{"query": "AI news", "topic": "news", "time_range": "week", "max_results": 10}'

Domain-filtered search

域名过滤搜索

./scripts/search.sh '{"query": "machine learning", "include_domains": ["arxiv.org", "github.com"], "search_depth": "advanced"}'
undefined
./scripts/search.sh '{"query": "machine learning", "include_domains": ["arxiv.org", "github.com"], "search_depth": "advanced"}'
undefined

Basic Search

基础搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "latest developments in quantum computing",
    "max_results": 5
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "latest developments in quantum computing",
    "max_results": 5
  }'

Advanced Search

高级搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "machine learning best practices",
    "max_results": 10,
    "search_depth": "advanced",
    "include_domains": ["arxiv.org", "github.com"],
    "chunks_per_source": 3
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "machine learning best practices",
    "max_results": 10,
    "search_depth": "advanced",
    "include_domains": ["arxiv.org", "github.com"],
    "chunks_per_source": 3
  }'

API Reference

API参考

Endpoint

端点

POST https://api.tavily.com/search
POST https://api.tavily.com/search

Headers

请求头

HeaderValue
Authorization
Bearer <TAVILY_API_KEY>
Content-Type
application/json
请求头
Authorization
Bearer <TAVILY_API_KEY>
Content-Type
application/json

Request Body

请求体

FieldTypeDefaultDescription
query
stringRequiredSearch query (keep under 400 chars)
max_results
integer5Maximum results (0-20)
search_depth
string
"basic"
ultra-fast
,
fast
,
basic
,
advanced
topic
string
"general"
general
,
news
,
finance
chunks_per_source
integer3Chunks per source (advanced/fast only)
time_range
stringnull
day
,
week
,
month
,
year
include_domains
array[]Domains to include (max 300)
exclude_domains
array[]Domains to exclude (max 150)
include_answer
booleanfalseInclude AI-generated answer
include_raw_content
booleanfalseInclude full page content
include_images
booleanfalseInclude image results
字段类型默认值描述
query
字符串必填搜索查询(保持在400字符以内)
max_results
整数5最大结果数(0-20)
search_depth
字符串
"basic"
ultra-fast
,
fast
,
basic
,
advanced
topic
字符串
"general"
general
,
news
,
finance
chunks_per_source
整数3每个来源的内容块数(仅advanced/fast模式可用)
time_range
字符串null
day
,
week
,
month
,
year
include_domains
数组[]要包含的域名(最多300个)
exclude_domains
数组[]要排除的域名(最多150个)
include_answer
布尔值false包含AI生成的答案
include_raw_content
布尔值false包含完整页面内容
include_images
布尔值false包含图片结果

Response Format

响应格式

json
{
  "query": "latest developments in quantum computing",
  "results": [
    {
      "title": "Page Title",
      "url": "https://example.com/page",
      "content": "Extracted text snippet...",
      "score": 0.85
    }
  ],
  "response_time": 1.2
}
json
{
  "query": "latest developments in quantum computing",
  "results": [
    {
      "title": "Page Title",
      "url": "https://example.com/page",
      "content": "Extracted text snippet...",
      "score": 0.85
    }
  ],
  "response_time": 1.2
}

Search Depth

搜索深度

DepthLatencyRelevanceContent Type
ultra-fast
LowestLowerNLP summary
fast
LowGoodChunks
basic
MediumHighNLP summary
advanced
HigherHighestChunks
When to use each:
  • ultra-fast
    : Real-time chat, autocomplete
  • fast
    : Need chunks but latency matters
  • basic
    : General-purpose, balanced
  • advanced
    : Precision matters (default recommendation)
深度延迟相关性内容类型
ultra-fast
最低较低NLP摘要
fast
良好内容块
basic
中等NLP摘要
advanced
较高最高内容块
使用场景:
  • ultra-fast
    : 实时聊天、自动补全
  • fast
    : 需要内容块但对延迟有要求
  • basic
    : 通用用途,平衡延迟与相关性
  • advanced
    : 对精度有要求(推荐默认使用)

Examples

示例

News Search

新闻搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "AI news today",
    "topic": "news",
    "time_range": "day",
    "max_results": 10
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "AI news today",
    "topic": "news",
    "time_range": "day",
    "max_results": 10
  }'

Domain-Filtered Search

域名过滤搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "Python async best practices",
    "include_domains": ["docs.python.org", "realpython.com", "github.com"],
    "search_depth": "advanced"
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "Python async best practices",
    "include_domains": ["docs.python.org", "realpython.com", "github.com"],
    "search_depth": "advanced"
  }'

Search with Full Content

包含完整内容的搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "React hooks tutorial",
    "max_results": 3,
    "include_raw_content": true
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "React hooks tutorial",
    "max_results": 3,
    "include_raw_content": true
  }'

Finance Search

金融搜索

bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "AAPL earnings Q4 2024",
    "topic": "finance",
    "max_results": 10
  }'
bash
curl --request POST \
  --url https://api.tavily.com/search \
  --header "Authorization: Bearer $TAVILY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "query": "AAPL earnings Q4 2024",
    "topic": "finance",
    "max_results": 10
  }'

Tips

提示

  • Keep queries under 400 characters - Think search query, not prompt
  • Break complex queries into sub-queries - Better results than one massive query
  • Use
    include_domains
    to focus on trusted sources
  • Use
    time_range
    for recent information
  • Filter by
    score
    (0-1) to get highest relevance results
  • 保持查询在400字符以内 - 思考搜索查询,而不是提示词
  • 将复杂查询拆分为子查询 - 比单个庞大的查询效果更好
  • 使用
    include_domains
    聚焦可信来源
  • 使用
    time_range
    获取最新信息
  • score
    (0-1)过滤
    获取最高相关性结果