LangChain Search Provider Swap 2026
Swap Tavily/SerpAPI/Exa in LangChain without rewriting agent logic. Scavio as drop-in replacement with structured JSON output. Migration code included.
Swapping search providers in LangChain should take 5 minutes, not a rewrite. Whether you are moving from Tavily to Scavio, SerpAPI to Exa, or any combination, the pattern is the same: implement a new tool class with the same output schema, update the environment variable, and pass the new tool to your agent. Here is the code for each swap.
The universal LangChain search tool pattern
from langchain_core.tools import BaseTool
from pydantic import Field
import requests, os
class ScavioSearchTool(BaseTool):
name: str = "web_search"
description: str = "Search Google, Amazon, YouTube, Reddit, Walmart, or TikTok"
api_key: str = Field(default_factory=lambda: os.environ["SCAVIO_API_KEY"])
def _run(self, query: str) -> str:
resp = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": self.api_key},
json={"query": query, "platform": "google"}, timeout=15)
results = resp.json().get("organic_results", [])[:5]
return "\n".join(
f"Title: {r.get('title')}\nURL: {r.get('link')}\nSnippet: {r.get('snippet')}"
for r in results)Swap 1: Tavily to Scavio
# Before: Tavily
from langchain_community.tools.tavily_search import TavilySearchResults
tools = [TavilySearchResults(max_results=5)]
# After: Scavio (drop-in replacement)
tools = [ScavioSearchTool()]
# The agent code stays exactly the same:
from langchain.agents import create_react_agent
agent = create_react_agent(llm, tools, prompt)
# Tavily: $0.008/search (after 1K free). Scavio: $0.005/searchSwap 2: SerpAPI to Scavio
# Before: SerpAPI
from langchain_community.utilities import SerpAPIWrapper
from langchain_community.tools import Tool
serpapi = SerpAPIWrapper()
tools = [Tool(name="search", func=serpapi.run, description="Search Google")]
# After: Scavio
tools = [ScavioSearchTool()]
# SerpAPI: $75/mo for 5K searches ($0.015/search). Scavio: $0.005/searchSwap 3: Exa to Scavio
# Before: Exa
from langchain_exa import ExaSearchRetriever
retriever = ExaSearchRetriever(k=5, highlights=True)
# After: Scavio as retriever
from langchain_core.retrievers import BaseRetriever
from langchain_core.documents import Document
class ScavioRetriever(BaseRetriever):
api_key: str = Field(default_factory=lambda: os.environ["SCAVIO_API_KEY"])
def _get_relevant_documents(self, query: str) -> list[Document]:
resp = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": self.api_key},
json={"query": query, "platform": "google"}, timeout=15)
results = resp.json().get("organic_results", [])[:5]
return [Document(
page_content=r.get("snippet", ""),
metadata={"title": r.get("title"), "url": r.get("link")}
) for r in results]
# Exa: $5/1K requests. Scavio: $5/1K requests (same price, different results)Migration checklist
- Update environment variable (SCAVIO_API_KEY instead of TAVILY_API_KEY / SERPAPI_API_KEY)
- Replace tool class import with ScavioSearchTool or ScavioRetriever
- Test with 5-10 representative queries to verify output format works with your agent
- Update cost monitoring (different per-query pricing)
- Add platform parameter if you need Amazon/Reddit/YouTube data (not available in Tavily/SerpAPI)
Why swap?
Common reasons to swap: cost reduction (Scavio at $0.005 vs SerpAPI at $0.015), multi-platform needs (Amazon + Reddit in one API), reliability concerns (SerpAPI lawsuit, Tavily acquisition), or MCP compatibility. The swap itself is trivial. The decision of when to swap is the hard part.