Tavily AI Search
Overview
Tavily is a search engine specifically optimized for Large Language Models and AI applications. Unlike traditional search APIs, Tavily provides AI-ready results with optional answer generation, clean content extraction, and domain filtering capabilities.
Key capabilities:
- - AI-generated answer summaries from search results
- Clean, structured results optimized for LLM processing
- Fast (
basic) and comprehensive (advanced) search modes - Domain filtering (include/exclude specific sources)
- News-focused search for current events
- Image search with relevant visual content
- Raw content extraction for deeper analysis
Architecture
CODEBLOCK0
Quick Start
Basic Search
CODEBLOCK1
Advanced Search
CODEBLOCK2
Domain Filtering
CODEBLOCK3
With Images
CODEBLOCK4
Search Modes
Basic vs Advanced
| Mode | Speed | Coverage | Use Case |
|---|
| basic | 1-2s | Good | Quick facts, simple queries |
| advanced |
5-10s | Excellent | Research, complex topics, comprehensive analysis |
Decision tree:
- 1. Need a quick fact or definition? → Use INLINECODE2
- Researching a complex topic? → Use INLINECODE3
- Need multiple perspectives? → Use INLINECODE4
- Time-sensitive query? → Use INLINECODE5
General vs News
| Topic | Time Range | Sources | Use Case |
|---|
| general | All time | Broad web | Evergreen content, tutorials, documentation |
| news |
Last 7 days | News sites | Current events, recent developments, breaking news |
Decision tree:
- 1. Query contains "latest", "recent", "current", "today"? → Use INLINECODE6
- Looking for historical or evergreen content? → Use INLINECODE7
- Need up-to-date information? → Use INLINECODE8
API Key Setup
Option 1: Clawdbot Config (Recommended)
Add to your Clawdbot config:
CODEBLOCK5
Access in scripts via Clawdbot's config system.
Option 2: Environment Variable
CODEBLOCK6
Add to ~/.clawdbot/.env or your shell profile.
Getting an API Key
- 1. Visit https://tavily.com
- Sign up for an account
- Navigate to your dashboard
- Generate an API key (starts with
tvly-) - Note your plan's rate limits and credit allocation
Common Use Cases
1. Research & Fact-Finding
CODEBLOCK7
2. Current Events
CODEBLOCK8
3. Domain-Specific Research
CODEBLOCK9
4. Visual Research
CODEBLOCK10
5. Content Extraction
CODEBLOCK11
Response Handling
AI Answer
The AI-generated answer provides a concise summary synthesized from search results:
CODEBLOCK12
Use when:
- - Need a quick summary
- Want synthesized information from multiple sources
- Looking for a direct answer to a question
Skip when (--no-answer):
- - Only need source URLs
- Want to form your own synthesis
- Conserving API credits
Structured Results
Each result includes:
- -
title: Page title - INLINECODE13 : Source URL
- INLINECODE14 : Extracted text snippet
- INLINECODE15 : Relevance score (0-1)
- INLINECODE16 : Full HTML (if
--raw-content enabled)
Images
When --images is enabled, returns URLs of relevant images found during search.
Best Practices
1. Choose the Right Search Depth
- - Start with
basic for most queries (faster, cheaper) - Escalate to
advanced only when:
- Initial results are insufficient
- Topic is complex or nuanced
- Need comprehensive coverage
2. Use Domain Filtering Strategically
Include domains for:
- - Academic research (
.edu domains) - Official documentation (official project sites)
- Trusted news sources
- Known authoritative sources
Exclude domains for:
- - Known low-quality content farms
- Irrelevant content types (Pinterest for non-visual queries)
- Sites with paywalls or access restrictions
3. Optimize for Cost
- - Use
basic depth as default - Limit
max_results to what you'll actually use - Disable
include_raw_content unless needed - Cache results locally for repeated queries
4. Handle Errors Gracefully
The script provides helpful error messages:
CODEBLOCK13
Integration Patterns
Programmatic Usage
CODEBLOCK14
JSON Output for Parsing
CODEBLOCK15
Chaining with Other Tools
CODEBLOCK16
Comparison with Other Search APIs
vs Brave Search:
- - ✅ AI answer generation
- ✅ Raw content extraction
- ✅ Better domain filtering
- ❌ Slower than Brave
- ❌ Costs credits
vs Perplexity:
- - ✅ More control over sources
- ✅ Raw content available
- ✅ Dedicated news mode
- ≈ Similar answer quality
- ≈ Similar speed
vs Google Custom Search:
- - ✅ LLM-optimized results
- ✅ Answer generation
- ✅ Simpler API
- ❌ Smaller index
- ≈ Similar cost structure
Troubleshooting
Script Won't Run
CODEBLOCK17
API Key Issues
CODEBLOCK18
Rate Limit Errors
- - Check your plan's credit allocation at https://tavily.com
- Reduce
max_results to conserve credits - Use
basic depth instead of INLINECODE27 - Implement local caching for repeated queries
Resources
See api-reference.md for:
- - Complete API parameter documentation
- Response format specifications
- Error handling details
- Cost and rate limit information
- Advanced usage examples
Dependencies
- - Python 3.6+
- INLINECODE28 package (install:
pip install tavily-python) - Valid Tavily API key
Credits & Attribution
- - Tavily API: https://tavily.com
- Python SDK: https://github.com/tavily-ai/tavily-python
- Documentation: https://docs.tavily.com
Tavily AI 搜索
概述
Tavily 是一个专门为大型语言模型和 AI 应用优化的搜索引擎。与传统搜索 API 不同,Tavily 提供 AI 就绪的结果,具有可选的答案生成、干净的内容提取和域名过滤功能。
主要功能:
- - 从搜索结果中生成 AI 答案摘要
- 为 LLM 处理优化的干净、结构化结果
- 快速(basic)和全面(advanced)搜索模式
- 域名过滤(包含/排除特定来源)
- 针对当前事件的新闻搜索
- 带相关视觉内容的图片搜索
- 用于深度分析的原始内容提取
架构
mermaid
graph TB
A[用户查询] --> B{搜索模式}
B -->|basic| C[快速搜索
1-2秒响应]
B -->|advanced| D[全面搜索
5-10秒响应]
C --> E[Tavily API]
D --> E
E --> F{主题过滤}
F -->|general| G[广泛网页搜索]
F -->|news| H[新闻来源
最近7天]
G --> I[域名过滤]
H --> I
I --> J{包含域名?}
J -->|是| K[过滤到特定域名]
J -->|否| L{排除域名?}
K --> M[搜索结果]
L -->|是| N[移除不需要的域名]
L -->|否| M
N --> M
M --> O{响应选项}
O --> P[AI 答案
摘要]
O --> Q[结构化结果
标题、URL、内容、评分]
O --> R[图片
如果请求]
O --> S[原始 HTML 内容
如果请求]
P --> T[返回给代理]
Q --> T
R --> T
S --> T
style E fill:#4A90E2
style P fill:#7ED321
style Q fill:#7ED321
style R fill:#F5A623
style S fill:#F5A623
快速开始
基本搜索
bash
带 AI 答案的简单查询
scripts/tavily_search.py 什么是量子计算?
多个结果
scripts/tavily_search.py Python 最佳实践 --max-results 10
高级搜索
bash
全面研究模式
scripts/tavily_search.py 气候变化解决方案 --depth advanced
新闻聚焦搜索
scripts/tavily_search.py AI 发展 2026 --topic news
域名过滤
bash
仅搜索可信域名
scripts/tavily_search.py Python 教程 \
--include-domains python.org docs.python.org realpython.com
排除低质量来源
scripts/tavily_search.py 如何编程 \
--exclude-domains w3schools.com geeksforgeeks.org
带图片
bash
包含相关图片
scripts/tavily_search.py 埃菲尔铁塔建筑 --images
搜索模式
基础 vs 高级
| 模式 | 速度 | 覆盖范围 | 使用场景 |
|---|
| basic | 1-2秒 | 良好 | 快速事实、简单查询 |
| advanced |
5-10秒 | 优秀 | 研究、复杂主题、全面分析 |
决策树:
- 1. 需要快速事实或定义?→ 使用 basic
- 研究复杂主题?→ 使用 advanced
- 需要多角度信息?→ 使用 advanced
- 时间敏感查询?→ 使用 basic
通用 vs 新闻
| 主题 | 时间范围 | 来源 | 使用场景 |
|---|
| general | 所有时间 | 广泛网页 | 常青内容、教程、文档 |
| news |
最近7天 | 新闻网站 | 当前事件、最新发展、突发新闻 |
决策树:
- 1. 查询包含最新、最近、当前、今天?→ 使用 news
- 寻找历史或常青内容?→ 使用 general
- 需要最新信息?→ 使用 news
API 密钥设置
选项 1:Clawdbot 配置(推荐)
添加到您的 Clawdbot 配置:
json
{
skills: {
entries: {
tavily: {
enabled: true,
apiKey: tvly-您的API密钥
}
}
}
}
通过 Clawdbot 的配置系统在脚本中访问。
选项 2:环境变量
bash
export TAVILYAPIKEY=tvly-您的API密钥
添加到 ~/.clawdbot/.env 或您的 shell 配置文件。
获取 API 密钥
- 1. 访问 https://tavily.com
- 注册账户
- 导航到您的仪表板
- 生成 API 密钥(以 tvly- 开头)
- 注意您计划的速率限制和信用额度
常见用例
1. 研究与事实查找
bash
带答案的全面研究
scripts/tavily_search.py 解释量子纠缠 --depth advanced
多个权威来源
scripts/tavily_search.py REST API 设计最佳实践 \
--max-results 10 \
--include-domains github.com microsoft.com google.com
2. 当前事件
bash
最新新闻
scripts/tavily_search.py AI 政策更新 --topic news
领域最新发展
scripts/tavily_search.py 量子计算突破 \
--topic news \
--depth advanced
3. 特定领域研究
bash
仅学术来源
scripts/tavily_search.py 机器学习算法 \
--include-domains arxiv.org scholar.google.com ieee.org
技术文档
scripts/tavily_search.py React hooks 指南 \
--include-domains react.dev
4. 视觉研究
bash
收集视觉参考
scripts/tavily_search.py 现代网页设计趋势 \
--images \
--max-results 10
5. 内容提取
bash
获取原始 HTML 内容进行深度分析
scripts/tavily_search.py Python async/await \
--raw-content \
--max-results 5
响应处理
AI 答案
AI 生成的答案提供从搜索结果中综合的简洁摘要:
python
{
answer: 量子计算是一种利用量子力学现象的计算方式...
}
使用场景:
- - 需要快速摘要
- 想要从多个来源获取综合信息
- 寻找问题的直接答案
跳过时(--no-answer):
- - 只需要来源 URL
- 想要自行综合
- 节省 API 信用额度
结构化结果
每个结果包括:
- - title:页面标题
- url:来源 URL
- content:提取的文本片段
- score:相关性评分(0-1)
- raw_content:完整 HTML(如果启用 --raw-content)
图片
当启用 --images 时,返回搜索过程中找到的相关图片 URL。
最佳实践
1. 选择合适的搜索深度
- - 大多数查询从 basic 开始(更快、更便宜)
- 仅在以下情况升级到 advanced:
- 初始结果不足
- 主题复杂或微妙
- 需要全面覆盖
2. 策略性使用域名过滤
包含域名用于:
- - 学术研究(.edu 域名)
- 官方文档(官方项目网站)
- 可信新闻来源
- 已知权威来源
排除域名用于:
- - 已知低质量内容农场
- 不相关内容类型(非视觉查询的 Pinterest)
- 有付费墙或访问限制的网站
3. 优化成本
- - 默认使用 basic 深度
- 将 maxresults 限制为实际需要
- 除非必要,禁用 includeraw_content
- 对重复查询本地缓存结果
4. 优雅处理错误
脚本提供有用的错误消息:
bash
缺少 API 密钥
错误:需要 Tavily API 密钥
设置:设置 TAVILY
APIKEY 环境变量或传递 --api-key
包未安装
错误:未安装 tavily-python 包
安装:pip install tavily-python
集成模式
编程使用
python
from tavily_search import search
result = search(
query=什么是机器学习?,
api_key=tvly-...,
search_depth=advanced,
max_results=10
)
if result.get