Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Production-ready Tavily API integration patterns for search, extract, crawl, map, and research in Python and JavaScript.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/integrations.md
1# Framework Integrations23## Table of Contents45- [LangChain](#langchain)6- [Pydantic AI](#pydantic-ai)7- [LlamaIndex](#llamaindex)8- [Agno](#agno)9- [OpenAI Function Calling](#openai-function-calling)10- [Anthropic Tool Calling](#anthropic-tool-calling)11- [Google ADK](#google-adk)12- [Vercel AI SDK](#vercel-ai-sdk)13- [CrewAI](#crewai)14- [No-Code Platforms](#no-code-platforms)1516---1718## LangChain1920We recommend the official `langchain-tavily` package for LangChain integrations.2122> Warning: `langchain_community.tools.tavily_search.tool` is deprecated. Migrate to `langchain-tavily` for actively maintained Search, Extract, Map, Crawl, and Research tools.2324### Installation2526```bash27pip install -U langchain-tavily28```2930### Credentials3132```python33import getpass34import os3536if not os.environ.get("TAVILY_API_KEY"):37os.environ["TAVILY_API_KEY"] = getpass.getpass("Tavily API key:\n")38```3940### Tavily Search4142**Available parameters**43- `max_results` (default: `5`)44- `topic` (`"general"`, `"news"`, `"finance"`)45- `include_answer`46- `include_raw_content`47- `include_images`48- `include_image_descriptions`49- `search_depth` (`"basic"` or `"advanced"`)50- `time_range` (`"day"`, `"week"`, `"month"`, `"year"`)51- `start_date` (`YYYY-MM-DD`)52- `end_date` (`YYYY-MM-DD`)53- `include_domains`54- `exclude_domains`55- `include_usage`5657**Instantiation**5859```python60from langchain_tavily import TavilySearch6162tavily_search = TavilySearch(63max_results=5,64topic="general"65)66```6768**Invoke directly with args**69- Required: `query`70- Can also be overridden at invocation: `include_images`, `search_depth`, `time_range`, `include_domains`, `exclude_domains`, `start_date`, `end_date`71- `include_answer` and `include_raw_content` should be set at instantiation time for predictable response sizes7273```python74result = tavily_search.invoke({"query": "What happened at the last Wimbledon?"})75```7677**Use with agent**7879```python80from langchain.agents import create_agent81from langchain_openai import ChatOpenAI8283agent = create_agent(84model=ChatOpenAI(model="gpt-5"),85tools=[tavily_search],86system_prompt="You are a helpful research assistant. Use web search to find accurate, up-to-date information.",87)88response = agent.invoke({89"messages": [{90"role": "user",91"content": "What is the most popular sport in the world? Include only Wikipedia sources.",92}]93})94```9596Tip: include today's date in the system prompt for time-aware queries.9798### Tavily Extract99100**Available parameters**101- `extract_depth` (`"basic"` or `"advanced"`)102- `include_images`103104```python105from langchain_tavily import TavilyExtract106107tavily_extract = TavilyExtract(108extract_depth="basic", # or "advanced"109# include_images=False,110)111112result = tavily_extract.invoke({113"urls": ["https://en.wikipedia.org/wiki/Lionel_Messi"]114})115```116117### Tavily Map/Crawl118119```python120from langchain_tavily import TavilyMap121122tavily_map = TavilyMap()123124result = tavily_map.invoke({125"url": "https://docs.example.com",126"instructions": "Find all documentation and tutorial pages"127})128# Returns: {"base_url": ..., "results": [urls...], "response_time": ...}129```130131```python132from langchain_tavily import TavilyCrawl133134tavily_crawl = TavilyCrawl()135136result = tavily_crawl.invoke({137"url": "https://docs.example.com",138"instructions": "Extract API documentation and code examples"139})140# Returns: {"base_url": ..., "results": [{url, raw_content}...], "response_time": ...}141```142143### Tavily Research144145**Available parameters**146- `input` (required)147- `model` (`"mini"`, `"pro"`, `"auto"`)148- `output_schema`149- `stream`150- `citation_format` (`"numbered"`, `"mla"`, `"apa"`, `"chicago"`)151152```python153from langchain_tavily import TavilyResearch154155tavily_research = TavilyResearch()156157result = tavily_research.invoke({158"input": "Research the latest developments in AI and summarize key trends.",159"model": "mini",160"citation_format": "apa"161})162```163164### Tavily Get Research165166```python167from langchain_tavily import TavilyGetResearch168169tavily_get_research = TavilyGetResearch()170final = tavily_get_research.invoke({"request_id": result["request_id"]})171```172173---174175## Pydantic AI176177Tavily is available for integration through Pydantic AI.178179### Introduction180181Integrate Tavily with Pydantic AI to enhance your AI agents with powerful web search capabilities. Pydantic AI provides a framework for building AI agents with tools, making it easy to incorporate real-time web search and data extraction into your applications.182183### Step-by-Step Integration Guide184185#### Step 1: Install Required Packages186187Install the necessary Python packages:188189```bash190pip install "pydantic-ai-slim[tavily]"191```192193#### Step 2: Set Up API Keys194195- Tavily API Key: [Get your Tavily API key](https://app.tavily.com/home)196197Set this as an environment variable:198199```bash200export TAVILY_API_KEY=your_tavily_api_key201```202203#### Step 3: Initialize Pydantic AI Agent with Tavily Tools204205```python206import os207from pydantic_ai.agent import Agent208from pydantic_ai.common_tools.tavily import tavily_search_tool209210# Get API key from environment211api_key = os.getenv("TAVILY_API_KEY")212assert api_key is not None213214# Initialize the agent with Tavily tools215agent = Agent(216"openai:o3-mini",217tools=[tavily_search_tool(api_key)],218system_prompt="Search Tavily for the given query and return the results.",219)220```221222#### Step 4: Example Use Cases223224```python225# Example 1: Basic search for news226result = agent.run_sync("Tell me the top news in the GenAI world, give me links.")227print(result.output)228```229230---231232## LlamaIndex233234```python235from llama_index.tools.tavily_research import TavilyToolSpec236237# Initialize tools238tavily_tool = TavilyToolSpec(api_key="tvly-YOUR_API_KEY")239tools = tavily_tool.to_tool_list()240241# Use with agent242from llama_index.agent.openai import OpenAIAgent243244agent = OpenAIAgent.from_tools(tools)245response = agent.chat("What are the latest AI developments?")246```247248---249250## Agno251252Tavily is available for integration through Agno, a lightweight framework for building agents with tools, memory, and reasoning.253254### Introduction255256Integrate Tavily with Agno to enhance your AI agents with powerful web search capabilities. Agno makes it easy to incorporate real-time web search and data extraction into your AI applications.257258### Step-by-Step Integration Guide259260#### Step 1: Install Required Packages261262```bash263pip install agno tavily-python264```265266#### Step 2: Set Up API Keys267268- Tavily API Key: [Get your Tavily API key](https://app.tavily.com/home)269- OpenAI API Key: [Get your OpenAI API key](https://platform.openai.com/api-keys)270271Set these as environment variables:272273```bash274export TAVILY_API_KEY=your_tavily_api_key275export OPENAI_API_KEY=your_openai_api_key276```277278#### Step 3: Initialize Agno Agent with Tavily Tools279280```python281from agno.agent import Agent282from agno.tools.tavily import TavilyTools283284# Initialize the agent with Tavily tools285agent = Agent(286tools=[287TavilyTools(288search=True, # Enable search functionality289max_tokens=8000, # Increase max tokens for detailed results290search_depth="advanced", # Use advanced search for comprehensive results291format="markdown", # Format results as markdown292)293],294show_tool_calls=True,295)296```297298#### Step 4: Example Use Cases299300```python301# Example 1: Basic search with default parameters302agent.print_response("Latest developments in quantum computing", markdown=True)303304# Example 2: Market research with multiple parameters305agent.print_response(306"Analyze the competitive landscape of AI-powered customer service solutions in 2026, "307"focusing on market leaders and emerging trends",308markdown=True,309)310311# Example 3: Technical documentation search312agent.print_response(313"Find the latest documentation and tutorials about Python async programming, "314"focusing on asyncio and FastAPI",315markdown=True,316)317318# Example 4: News aggregation319agent.print_response(320"Gather the latest news about artificial intelligence from tech news websites "321"published in the last week",322markdown=True,323)324```325326### Additional Use Cases327328- Content curation: Gather and organize information from multiple sources329- Real-time data integration: Keep your AI agents up to date with the latest information330- Technical documentation: Search and analyze technical documentation331- Market analysis: Conduct comprehensive market research and analysis332333---334335## OpenAI Function Calling336337Define Tavily as an OpenAI function:338339```python340from openai import OpenAI341from tavily import TavilyClient342import json343344openai_client = OpenAI()345tavily_client = TavilyClient()346347tools = [{348"type": "function",349"function": {350"name": "web_search",351"description": "Search the web for current information",352"parameters": {353"type": "object",354"properties": {355"query": {356"type": "string",357"description": "The search query"358}359},360"required": ["query"]361}362}363}]364365def handle_tool_call(tool_call):366if tool_call.function.name == "web_search":367args = json.loads(tool_call.function.arguments)368return tavily_client.search(args["query"])369370# Chat completion with tools371response = openai_client.chat.completions.create(372model="gpt-4",373messages=[{"role": "user", "content": "What are the latest AI trends?"}],374tools=tools375)376377if response.choices[0].message.tool_calls:378tool_call = response.choices[0].message.tool_calls[0]379search_results = handle_tool_call(tool_call)380381# Continue conversation with results382messages = [383{"role": "user", "content": "What are the latest AI trends?"},384response.choices[0].message,385{"role": "tool", "tool_call_id": tool_call.id, "content": json.dumps(search_results)}386]387final = openai_client.chat.completions.create(388model="gpt-4",389messages=messages390)391```392393---394395## Anthropic Tool Calling396397Integrate Tavily with Anthropic Claude to add real-time web search in tool-calling workflows.398399### Installation400401```bash402pip install anthropic tavily-python403```404405### Setup406407```bash408export ANTHROPIC_API_KEY="your-anthropic-api-key"409export TAVILY_API_KEY="your-tavily-api-key"410```411412### Using Tavily With Anthropic Tool Calling413414```python415import json416import os417from anthropic import Anthropic418from tavily import TavilyClient419420client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])421tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])422MODEL_NAME = "claude-sonnet"423```424425### Implementation426427#### System prompt428429```python430SYSTEM_PROMPT = (431"You are a research assistant. Use the tavily_search tool when needed. "432"After tools run and tool results are provided back to you, produce a concise, "433"well-structured summary with key bullets and a Sources section listing URLs."434)435```436437#### Tool schema438439```python440tools = [441{442"name": "tavily_search",443"description": "Search the web using Tavily and return relevant links and summaries.",444"input_schema": {445"type": "object",446"properties": {447"query": {"type": "string", "description": "Search query string."},448"max_results": {"type": "integer", "default": 5},449"search_depth": {450"type": "string",451"enum": ["basic", "advanced"],452"default": "basic",453},454},455"required": ["query"],456},457}458]459```460461#### Tool execution462463```python464def tavily_search(**kwargs):465return tavily_client.search(**kwargs)466467def process_tool_call(name, args):468if name == "tavily_search":469return tavily_search(**args)470raise ValueError(f"Unknown tool: {name}")471```472473#### Main chat function474475```python476def chat_with_claude(user_message: str):477# Call 1: allow tool use478initial_response = client.messages.create(479model=MODEL_NAME,480max_tokens=4096,481system=SYSTEM_PROMPT,482messages=[{"role": "user", "content": [{"type": "text", "text": user_message}]}],483tools=tools,484)485486# If Claude answers without tools, return text directly487if initial_response.stop_reason != "tool_use":488return "".join(489block.text for block in initial_response.content490if getattr(block, "type", None) == "text"491)492493# Execute all requested tools494tool_result_blocks = []495for block in initial_response.content:496if getattr(block, "type", None) == "tool_use":497result = process_tool_call(block.name, block.input)498tool_result_blocks.append(499{500"type": "tool_result",501"tool_use_id": block.id,502"content": json.dumps(result),503}504)505506# Call 2: send tool results and ask Claude for final synthesis507final_response = client.messages.create(508model=MODEL_NAME,509max_tokens=4096,510system=SYSTEM_PROMPT,511messages=[512{"role": "user", "content": [{"type": "text", "text": user_message}]},513{"role": "assistant", "content": initial_response.content},514{"role": "user", "content": tool_result_blocks},515{516"role": "user",517"content": [{518"type": "text",519"text": "Please synthesize the final answer now based on the tool results above. Include 3-7 bullets and a Sources section with URLs.",520}],521},522],523)524525return "".join(526block.text for block in final_response.content527if getattr(block, "type", None) == "text"528)529```530531### Usage example532533```python534chat_with_claude("What is trending now in the agents space in 2026?")535```536537Reference: https://docs.tavily.com/documentation/integrations/anthropic538539---540541## Google ADK542543Google ADK can connect to Tavily through Tavily's remote MCP server, giving your Gemini-based agent live search, extraction, and site exploration capabilities.544545### Prerequisites546547- Python 3.9+548- Tavily API key: https://app.tavily.com/home549- Gemini API key: https://aistudio.google.com/app/apikey550551### Installation552553```bash554pip install google-adk mcp555```556557### Agent Setup558559```python560import os561from google.adk.agents import Agent562from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams563from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset564565tavily_api_key = os.getenv("TAVILY_API_KEY")566567root_agent = Agent(568model="gemini-2.5-pro",569name="tavily_agent",570instruction=(571"You are a helpful assistant that uses Tavily to search the web, "572"extract content, and explore websites. Use Tavily tools to provide "573"up-to-date information."574),575tools=[576MCPToolset(577connection_params=StreamableHTTPServerParams(578url="https://mcp.tavily.com/mcp/",579headers={"Authorization": f"Bearer {tavily_api_key}"},580)581)582],583)584```585586### Environment Variables587588```bash589export GOOGLE_API_KEY="your_gemini_api_key_here"590export TAVILY_API_KEY="your_tavily_api_key_here"591```592593### Run594595```bash596adk create my_agent597adk run my_agent598# Optional web UI:599adk web --port 8000600```601602### Available Tavily MCP tools603604- `tavily-search`605- `tavily-extract`606- `tavily-map`607- `tavily-crawl`608609Reference: https://docs.tavily.com/documentation/integrations/google-adk610611---612613## Vercel AI SDK614615The `@tavily/ai-sdk` package provides pre-built tools for Vercel AI SDK v5.616617### Installation618619```bash620npm install ai @ai-sdk/openai @tavily/ai-sdk621```622623### Usage624625```typescript626import { tavilySearch, tavilyCrawl } from "@tavily/ai-sdk";627import { generateText } from "ai";628import { openai } from "@ai-sdk/openai";629630// Search631const result = await generateText({632model: openai("gpt-4"),633prompt: "What are the latest AI developments?",634tools: {635tavilySearch: tavilySearch({636maxResults: 5,637searchDepth: "advanced",638}),639},640});641642// Crawl643const crawlResult = await generateText({644model: openai("gpt-4"),645prompt: "Crawl tavily.com and summarize their features",646tools: {647tavilyCrawl: tavilyCrawl({648maxDepth: 2,649limit: 50,650}),651},652});653```654655**Available tools:** `tavilySearch`, `tavilyExtract`, `tavilyCrawl`, `tavilyMap`656657---658659## CrewAI660661CrewAI provides built-in Tavily tools for multi-agent workflows.662663### Installation664665```bash666pip install 'crewai[tools]'667```668669### Usage670671```python672import os673from crewai import Agent, Task, Crew674from crewai_tools import TavilySearchTool, TavilyExtractTool675676os.environ["TAVILY_API_KEY"] = "your-api-key"677678# Search tool679search_tool = TavilySearchTool()680681# Create agent with Tavily682researcher = Agent(683role="Research Analyst",684goal="Find and analyze information on given topics",685tools=[search_tool],686backstory="Expert at finding relevant information online"687)688689task = Task(690description="Research the latest developments in quantum computing",691expected_output="A comprehensive summary with sources",692agent=researcher693)694695crew = Crew(agents=[researcher], tasks=[task])696result = crew.kickoff()697```698699---700701## No-Code Platforms702703Tavily integrates with popular no-code automation platforms:704705| Platform | Features | Best For |706|----------|----------|----------|707| **Zapier** | Search, Extract | CRM enrichment, automated research |708| **Make** | Search, Extract | Complex workflows, multi-step automations |709| **n8n** | Search, Extract, AI Agent tool | Self-hosted, AI agent workflows |710| **Dify** | Search, Extract | No-code AI apps, chatflows |711| **FlowiseAI** | Search | Visual LLM builders, RAG systems |712| **Langflow** | Search, Extract | Visual agent building |713714---715716## Additional Integrations717See the [full integrations documentation](https://docs.tavily.com/documentation/integrations) for complete guides.718