A search API optimized for AI Agents, returning clean, structured results suitable for direct consumption by LLMs.
Use Cases
- Need high-quality search results for complex tasks such as research and writing
- An upgrade option when ddg-search results are not precise enough
- The search backend in the deep-research workflow
Prerequisites
Need to set the environment variable TAVILY_API_KEY:
- Visit https://tavily.com/ to sign up (free plan: 1000 times per month)
- Setup:
export TAVILY_API_KEY="tvly-xxxxx"
How to Run
Basic Search
curl -s -X POST "https://api.tavily.com/search" \
-H "Content-Type: application/json" \
-d '{
"api_key": "'$TAVILY_API_KEY'",
"query": "搜索内容",
"search_depth": "basic",
"max_results": 5
}'
Deep Search
curl -s -X POST "https://api.tavily.com/search" \
-H "Content-Type: application/json" \
-d '{
"api_key": "'$TAVILY_API_KEY'",
"query": "搜索内容",
"search_depth": "advanced",
"max_results": 10,
"include_raw_content": true
}'
Python SDK
from tavily import TavilyClient
client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
response = client.search(
query="AI agent 市场分析 2026",
search_depth="advanced",
max_results=10,
)
for result in response["results"]:
print(f"Title: {result['title']}")
print(f"URL: {result['url']}")
print(f"Content: {result['content'][:200]}")
print("---")
Parameter Description
| Parameter | Value | Description |
|---|---|---|
search_depth |
basic / advanced |
basic is fast but shallow, advanced is slow but thorough |
max_results |
1-20 | Number of results to return |
include_raw_content |
bool | Whether to return the raw content of the web pages |
include_domains |
list | Limit search to specific domains |
exclude_domains |
list | Exclude domains |
Output Specifications
- Search results are annotated with the source URL and relevance score
- advanced search is used for deep research, basic is used for quick queries
- The free quota is limited; for simple queries, prioritize ddg-search