Tavily Search
Why? WebFetch can only grab a single known URL. Tavily searches the entire web, returns ranked results with relevance scores, and can generate AI-powered answers -- all in one API call. Essential for answering "what's the latest on X?" or powering research workflows.
Quick Start
"Search the web for latest AI agent frameworks"
"What's the latest news about OpenAI?"
"Extract the main content from these 5 URLs"
Setup — resolving the key (robust in ANY session)
The key lives in ~/.swarm-ai/SwarmWS/.claude/settings.local.json → env.TAVILY_API_KEY.
The harness injects it as $TAVILY_API_KEY **only on sessions spawned AFTER the key was
saved** — an older tab's process env is empty, so echo $TAVILY_API_KEY can be blank even
though the key is configured. Never conclude "key not set" from an empty env var alone.
Always resolve the key env-first, settings-file-fallback — this one line works in every
session, old or new. Put it at the top of any Tavily call:
TAVILY_API_KEY="${TAVILY_API_KEY:-$("$SWARM_BACKEND_BIN" py -c "import json,os;print(json.load(open(os.path.expanduser('~/.swarm-ai/SwarmWS/.claude/settings.local.json')))['env']['TAVILY_API_KEY'])" 2>/dev/null)}"
(settings.local.json is gitignored → the key never leaves the machine.)
💰 Free-tier only — do NOT incur paid usage
This account is on the free Researcher plan (1,000 credits/month). Keep it free:
- NEVER upgrade the plan or enable pay-as-you-go (paygo) to work around a credit limit.
- On a
432 Credit limiterror → STOP and tell the user; wait for the monthly reset.
Do not auto-fall-back to any paid tier.
- Default to
search_depth: "basic"(1 credit) — reserveadvanced(2 credits) for when
the user explicitly needs depth.
- Check remaining credits any time (read-only, costs nothing):
```bash
curl -s https://api.tavily.com/usage -H "Authorization: Bearer $TAVILY_API_KEY"
```
account.plan_usage / plan_limit = free-tier counter; paygo_usage must stay 0.
Basic search = 1 credit. Advanced search = 2 credits.
API Reference
Search
POST https://api.tavily.com/search
curl -s -X POST https://api.tavily.com/search \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "latest AI agent frameworks 2026",
"search_depth": "basic",
"max_results": 5,
"include_answer": "basic"
}'
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
| query | string | (required) | Search query |
| search_depth | string | basic | basic (fast, 1 credit) or advanced (thorough, 2 credits) |
| max_results | int | 5 | Number of results (0-20) |
| include_answer | bool/string | false | true, "basic", or "advanced" -- returns AI-generated answer |
| include_raw_content | bool/string | false | true, "markdown", or "text" -- returns full page content |
| topic | string | general | "general" or "news" |
| time_range | string | none | "day", "week", "month", "year" |
| country | string | none | ISO country code to boost results (e.g., "us", "tw", "cn") |
| include_images | bool | false | Return related images |
| exclude_domains | array | none | Domains to exclude (e.g., ["pinterest.com"]) |
| include_domains | array | none | Limit search to specific domains |
Response:
{
"query": "latest AI agent frameworks 2026",
"answer": "AI-generated summary of search results...",
"results": [
{
"title": "Page Title",
"url": "https://example.com/article",
"content": "Relevant snippet from the page...",
"score": 0.95,
"published_date": "2026-03-07"
}
],
"response_time": 1.23
}
Extract
POST https://api.tavily.com/extract
curl -s -X POST https://api.tavily.com/extract \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://example.com/article1",
"https://example.com/article2"
],
"format": "markdown"
}'
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
| urls | string/array | (required) | Single URL or up to 20 URLs |
| query | string | none | Reranks extracted chunks by relevance |
| chunks_per_source | int | 3 | Chunks per URL (1-5, requires query) |
| extract_depth | string | basic | "basic" (1 credit/5 URLs) or "advanced" (2 credits/5 URLs) |
| format | string | markdown | "markdown" or "text" |
| include_images | bool | false | Include image URLs from pages |
Response:
{
"results": [
{
"url": "https://example.com/article1",
"raw_content": "# Article Title\n\nFull markdown content..."
}
],
"failed_results": [],
"response_time": 2.1
}
Workflow
Step 1: Determine Search Type
| User Request | Search Configuration |
|---|---|
| General question | search_depth: "basic", include_answer: "basic" |
| Current events / news | topic: "news", time_range: "week" |
| Thorough research | search_depth: "advanced", max_results: 10 |
| Region-specific | Add country parameter |
| Domain-specific | Use include_domains |
| Competitive analysis | Multiple searches + extract |
Step 2: Execute Search
curl -s -X POST https://api.tavily.com/search \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "user query here",
"search_depth": "basic",
"max_results": 5,
"include_answer": "basic"
}'
Step 3: Present Results
Format results clearly:
## Search Results: [query]
**AI Answer:** [Tavily's generated answer if requested]
**Sources:**
1. [Title](url) (relevance: 95%)
Key snippet from the page...
2. [Title](url) (relevance: 88%)
Key snippet from the page...
3. ...
Step 4: Offer Follow-ups
After presenting results:
- "Want me to extract the full content from any of these?"
- "Should I do a deeper search?"
- "Want me to summarize the top results?"
Common Patterns
Quick Answer
When user just wants a fast answer:
curl -s -X POST https://api.tavily.com/search \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "what is the current population of Taiwan",
"include_answer": "advanced",
"max_results": 3
}'
Present the answer field directly, with sources listed below.
News Check
curl -s -X POST https://api.tavily.com/search \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "OpenAI latest announcements",
"topic": "news",
"time_range": "week",
"max_results": 5,
"include_answer": "basic"
}'
Batch Content Extraction
When you have multiple URLs and need their content:
curl -s -X POST https://api.tavily.com/extract \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://article1.com",
"https://article2.com",
"https://article3.com"
],
"format": "markdown",
"query": "focus topic for relevance ranking"
}'
Search + Extract Pipeline
For thorough research on a topic:
- Search to find relevant URLs
- Extract full content from top results
- Summarize or analyze
# Step 1: Search
RESULTS=$(curl -s -X POST https://api.tavily.com/search \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "topic", "max_results": 5}')
# Step 2: Extract top URLs (parse from results)
curl -s -X POST https://api.tavily.com/extract \
-H "Authorization: Bearer $TAVILY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"urls": ["url1", "url2", "url3"], "format": "markdown"}'
# Step 3: Summarize extracted content
Powering Other Skills
Tavily is a building block for other skills:
| Skill | How Tavily Helps |
|---|---|
| s_deep-research | Primary search engine for multi-round research |
Cost Management
| Operation | Credits |
|---|---|
| Basic search | 1 |
| Advanced search | 2 |
| Basic extract (per 5 URLs) | 1 |
| Advanced extract (per 5 URLs) | 2 |
Free tier: 1,000 credits/month
Tips to conserve credits:
- Use
basicsearch depth for most queries (1 credit vs 2) - Use
max_results: 3-5unless you need more - Batch URL extractions (5 URLs = 1 credit vs 5 separate WebFetch calls)
- Use
include_answerto get a quick answer without extracting full pages - Don't set
include_raw_content: trueon search unless you need full page text
Troubleshooting
| Problem | Solution |
|---------|----------|
| $TAVILY_API_KEY empty | Old-session env not injected — use the env-first/settings-fallback resolver in Setup. Do NOT conclude the key is missing. |
| 401 Unauthorized | Key actually invalid/expired (resolver returned a bad value). Check at app.tavily.com |
| 429 Rate limited | Too many requests. Wait and retry |
| 432 Credit limit | Free monthly credits exhausted. STOP, tell the user, wait for reset — never upgrade/enable paygo to bypass. |
| Empty results | Try broader query, remove domain restrictions, check spelling |
| Extract fails for URL | Site may block bots. Try extract_depth: "advanced" |
| Slow response | Use search_depth: "basic" or reduce max_results |
| Results not recent enough | Add time_range: "day" or "week" |
Quality Rules
- Resolve the key env-first/settings-fallback (see Setup) — never assume an empty env var means "not configured"
- Free-tier only: never upgrade the plan or enable paygo; on a 432 credit limit, stop and tell the user
- Present AI-generated answers with source attribution
- Show relevance scores to help user gauge result quality
- For news queries, always include published dates
- Don't over-fetch: use minimal
max_resultsneeded - When used as building block for other skills, keep credit usage efficient
- Never expose the API key in output or messages
- Offer to go deeper (extract, advanced search) after initial results
- For Chinese queries, consider adding
country: "tw"or"cn"for better regional results
Verification
Before marking this task complete, show evidence for each:
- [ ] Search query shown — the exact query string sent to Tavily API is displayed (not just the user's natural-language request)
- [ ] Results returned with URLs — each result includes a title, URL, relevance score, and content snippet
- [ ] Relevance confirmed — results are on-topic for the user's intent; off-topic or low-score results are filtered or flagged
- [ ] Key resolved robustly — resolved env-first/settings-fallback (not assumed from an empty env var); call returned no auth error
- [ ] Free-tier respected — no plan upgrade / paygo enabled; a 432 limit was surfaced to the user, not bypassed
- [ ] Credit-efficient — search used appropriate depth (basic vs advanced) and minimal
max_resultsfor the task