Skip to main content

[DRAFT] Tavily

Overview

Tavily is a search API built for LLM agents: fast, JSON-first, and tuned to return concise, RAG-friendly snippets.

Why Tavily

  • Purpose-built for agentic search with high-signal snippets.
  • Simple REST interface; generous free tier for prototyping.
  • Good latency; avoids browser automation.

Sign up

  • Create an API key at https://tavily.com
  • Check free quota; add billing for higher limits.

Example (Python)

import os, requests

TAVILY_API_KEY = os.environ["TAVILY_API_KEY"]

def search(query: str, max_results: int = 5):
resp = requests.post(
"https://api.tavily.com/search",
headers={"Content-Type": "application/json"},
json={
"api_key": TAVILY_API_KEY,
"query": query,
"max_results": max_results,
"include_answer": True,
"search_depth": "basic", # or "advanced"
},
timeout=15,
)
resp.raise_for_status()
return resp.json()

if __name__ == "__main__":
data = search("langgraph vs langchain 2025")
for r in data["results"]:
print(r["title"], "-", r["url"])

Response highlights

  • answer: model-generated concise summary (when include_answer true).
  • results: list with title, url, content/snippet, score.
  • follow_up_questions: suggested next queries.

Tips for RAG

  • Keep max_results small (3–8) and re-rank with embeddings.
  • Cache responses for hot queries to save quota.
  • Strip/normalize URLs, fetch full page for grounding if needed.
  • Combine answer + results snippets to build context for the LLM.

Error handling

  • Handle 429 with backoff.
  • Validate results exists; if empty, retry with search_depth="advanced".

Comparison (Tavily vs Serper)

  • Tavily: LLM-tuned snippets and optional auto-answers.
  • Serper: closer to raw Google results; broader fields (news, answerBox, etc.).

References