AI Gateway Web Search
AI Gateway Web Search
AI Gateway provides built-in search tools that let AI models access current web information and source-grounded data. Use them when you need information that may not be in the model's training data.
AI Gateway supports two types of web search:
- Search for all providers: Use Perplexity Search, Exa Search, Tako Search, or Parallel Search with any model regardless of provider. This gives you consistent web search behavior across different models.
- Provider-specific search: Use native web search tools from Anthropic, OpenAI, Google, or SpaceXAI. These tools are optimized for their respective providers and may offer additional features.
Search across API formats
Search tool definitions differ by API and provider. The TypeScript AI SDK example uses AI Gateway's Perplexity tool. The Python beta example uses Anthropic's native web search tool. Chat Completions uses its server-tool format. Messages uses Anthropic's native web search tool. Responses uses OpenAI's native web search with an OpenAI model. Don't copy a tool definition between these formats. The Python beta example supports Anthropic's native web search. Gateway's Perplexity search helper is not supported in this beta agent loop.
For provider-specific search, follow the Anthropic, OpenAI, and Google sections. Use the Responses tool reference for function tools. Native search tool availability depends on the selected provider and model.
Search Tool Examples
TypeScript Example
import { generateText, gateway, isStepCount } from 'ai';
const { text } = await generateText({
tools: { search: gateway.tools.perplexitySearch({ maxResults: 1 }) },
stopWhen: isStepCount(3),
model: "anthropic/claude-sonnet-5",
prompt: "Search the web for Vercel AI Gateway and summarize it in one sentence.",
});
console.log(text);
Python Example
import asyncio
import ai
from ai.providers.anthropic import tools as anthropic_tools
async def main():
model = ai.get_model("anthropic/claude-sonnet-5")
messages = [ai.user_message("Search the web for Vercel AI Gateway and summarize it in one sentence.")]
agent = ai.Agent(tools=[anthropic_tools.web_search(max_uses=1)])
async with agent.run(model, messages) as stream:
async for event in stream:
if isinstance(event, ai.events.TextDelta):
print(event.chunk, end="", flush=True)
print()
asyncio.run(main())
Using Perplexity Search
The perplexitySearch tool can be used with any model regardless of the model provider or creator. This makes it a flexible option when you want consistent web search behavior across different models, or when you want to use web search with a model whose provider doesn't offer native web search capabilities.
To use Perplexity Search, import gateway from ai and pass gateway.tools.perplexitySearch() to the tools parameter. When the model needs current information, it calls the tool and AI Gateway routes the request to Perplexity's search API.
Perplexity web search requests are charged at $5 per 1,000 requests. See Perplexity's pricing for more details.
Exa Search
The exaSearch tool can be used with any model regardless of the model provider or creator. Exa returns web results and extracted content for agent workflows that need current information, domain filters, date filters, and token-efficient excerpts.
To use Exa Search, import gateway from ai and pass gateway.tools.exaSearch() to the tools parameter. When the model needs current information, it calls the tool and AI Gateway routes the request to Exa's Search API.
Exa web search requests are charged at $7 per 1,000 requests. Each request includes up to 10 results. Additional requested results beyond 10 are charged at $1 per 1,000 additional results.
Tako Search
The takoSearch tool searches the web and Tako's curated, real-time knowledge graph in one call. It returns token-efficient web excerpts and knowledge graph results backed by structured data, source attribution, and embed-ready visualizations. Use it when your agent needs access to authoritative, real-time finance, sports, weather, macroeconomics, and politics data or results from the web.
To use Tako Search, import gateway from ai and pass gateway.tools.takoSearch() to tools.
Parallel Search
The parallelSearch tool can be used with any model regardless of the model provider or creator. Parallel AI provides LLM-optimized web search that extracts relevant excerpts from web pages, making it ideal for research tasks and information retrieval.
To use Parallel Search, import gateway from ai and pass gateway.tools.parallelSearch() to the tools parameter. When the model needs current information, it calls the tool and AI Gateway routes the request to Parallel's search API.
Parallel web search requests are charged at $5 per 1,000 requests (includes up to 10 results per request). Additional results beyond 10 are charged at $1 per 1,000 additional results.
Provider-specific Search
Use native web search tools from Anthropic, OpenAI, Google, or SpaceXAI. These tools are optimized for their respective providers and may offer additional features. Pricing for provider-specific web search tools depends on the model you use. See the Web Search price column on the model detail pages for exact pricing.