Exa is a Websearch API. Add Exa websearch tool to your LLMs in just a few lines of code. Giving your AI apps websearch capabilites. Works with AI SDK by Vercel.
npm install @exalabs/ai-sdkimport{generateText,stepCountIs}from"ai";import{webSearch}from"@exalabs/ai-sdk";import{openai}from"@ai-sdk/openai";const{ text }=awaitgenerateText({model: openai('gpt-5-nano'),prompt: 'Tell me the latest developments in AI',system: "Only use web search once per turn. Answer based on the information you have.",tools: {webSearch: webSearch(),},stopWhen: stepCountIs(3),});console.log(text);Get your API key from the Exa Dashboard.
Defaults when you use webSearch():
- Type:
auto(best search) - Results:
10 - Text:
3000 characters per result - Livecrawl:
fallback(fresh content when needed)
- Get your API key from the Exa Dashboard
- Add it to your
.envfile:
EXA_API_KEY=your-api-key-hereThat's it! The package reads it automatically.
Here's a full-featured example combining the most useful search settings:
const{ text }=awaitgenerateText({model: openai('gpt-5-nano'),prompt: 'Find the top AI companies in Europe founded after 2018',tools: {webSearch: webSearch({type: "auto",// intelligent hybrid searchnumResults: 6,// return up to 6 resultscategory: "company",// focus on companiescontents: {text: {maxCharacters: 1000},// get up to 1000 chars per resultlivecrawl: "preferred",// always get fresh content if possiblesummary: true,// return an AI-generated summary for each result},}),},stopWhen: stepCountIs(5),});console.log(text);webSearch({// Search settingstype: "auto",// "auto", "keyword", "neural", "fast", "deep"category: "news",// "company", "research paper", "news", "pdf", // "github", "personal site", "linkedin profile", "financial report"numResults: 10,// Filter by domainincludeDomains: ["linkedin.com","github.com"],excludeDomains: ["wikipedia.com"],// Filter by date (ISO 8601)startPublishedDate: "2025-01-01T00:00:00.000Z",endPublishedDate: "2025-12-31T23:59:59.999Z",startCrawlDate: "2025-01-01T00:00:00.000Z",endCrawlDate: "2025-12-31T23:59:59.999Z",// Filter by textincludeText: ["AI"],// Must containexcludeText: ["spam"],// Must not contain// LocationuserLocation: "US",// Two-letter country code// Content optionscontents: {text: {maxCharacters: 1000,includeHtmlTags: false,},summary: {query: "Main points",},livecrawl: "fallback",// "never", "fallback", "always", "preferred"livecrawlTimeout: 10000,subpages: 5,subpageTarget: "about",extras: {links: 5,imageLinks: 3,},},})Full TypeScript types included:
import{webSearch,ExaSearchConfig,ExaSearchResult}from"@exalabs/ai-sdk";constconfig: ExaSearchConfig={numResults: 10,type: "auto",};constsearch=webSearch(config);- GitHub Repository - View source code of this npm package
- Try npm Package - View on npm
- Vercel AI SDK Cookbook - Web search agent example featuring Exa
- API Dashboard - Try Exa API on the dashboard
- Get your API Keys - Get your API keys
- Documentation - Exa API documentation
- Exa Website - Learn more about Exa
MIT