简介
Tavily Search 是为 AI agent 和 RAG 设计的搜索 API。不像 Google Custom Search 或 Bing API,Tavily 返回精选的内容片段直接喂 LLM —— 不是要再去 scrape 的 URL 列表。可选的 include_answer 给出综合答案。适合需要新事实、引用、实时信息的 AI agent。兼容 Tavily REST API / Python / TypeScript SDK / MCP server。装机时间 2 分钟。
Hello world
from tavily import TavilyClient
client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
response = client.search(
query="What is the latest version of Python?",
search_depth="advanced",
include_answer=True,
include_raw_content=False,
max_results=5,
)
print(response["answer"])
# "As of October 2024, the latest stable version of Python is 3.13.0..."
for r in response["results"]:
print(f"{r['title']} — {r['url']}")
print(r["content"][:200])搜索深度
| 模式 | 用途 | 成本 |
|---|---|---|
basic |
快速事实查询 | 1 credit |
advanced |
多源研究、RAG | 2 credits |
advanced 模式爬更多源 + 重排,答案质量更好,延迟和成本略高。
按域名过滤
# 白名单
response = client.search(
query="Latest LangChain release notes",
include_domains=["python.langchain.com", "github.com"],
)
# 黑名单
response = client.search(
query="Best vector databases",
exclude_domains=["medium.com"], # 避开 SEO blogspam
)当 MCP
{
"mcpServers": {
"tavily": {
"command": "npx",
"args": ["-y", "tavily-mcp"],
"env": { "TAVILY_API_KEY": "tvly-..." }
}
}
}Claude Code / Cursor 直接调 tavily_search / tavily_extract / tavily_crawl。
FAQ
Q: Tavily 免费吗? A: 免费 —— 免费档每月 1000 API credit,不要信用卡。付费档加更高配额和团队功能。价格见 tavily.com。
Q: Tavily 跟 SerpAPI 调 Google 啥区别? A: SerpAPI 返回 Google 的 HTML 自然结果,你自己 scrape + 清洗。Tavily 已经做了清洗、排序、可选的综合。Tavily 为 LLM 消费打造;SerpAPI 为 SERP scraping 打造。
Q: 能配 LangChain 用吗?
A: 能 —— langchain_community.tools.tavily_search.TavilySearchResults 是 LangChain 内置工具。LlamaIndex / CrewAI / Pydantic AI 同样。