Exa AI SDK (英语)
Exa是一个Websearch API. 仅在几行代码中将 Exa Websearch 工具添加到您的 LLMS 中 。 提供你的AI应用程序 网络搜索的卡比利人。 由Vercel与AI SDK合作.
目录
安装
npm install @exalabs/ai-sdk
快速启动
import { generateText, stepCountIs } from "ai";
import { webSearch } from "@exalabs/ai-sdk";
import { openai } from "@ai-sdk/openai";
const { text } = await generateText({
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);
从中获取您的 API 密钥 Exa 板盘。 。 。 .
使用时的默认 webSearch()数字 :
- 类型 :
auto(最佳搜索结果) - 结果:
10 - 文本 :
3000 characters per result - 活爬行 :
fallback(必要时更新内容)
设置
- 从中获取您的 API 密钥 Exa 板盘
- 把它加进你的
.env文件 :
EXA_API_KEY=your-api-key-here
就这样! 包会自动读取.
示例
以下是一个综合了最有用的搜索设置的全功能实例:
const { text } = await generateText({
model: openai('gpt-5-nano'),
prompt: 'Find the top AI companies in Europe founded after 2018',
tools: {
webSearch: webSearch({
type: "auto", // intelligent hybrid search
numResults: 6, // return up to 6 results
category: "company", // focus on companies
contents: {
text: { maxCharacters: 1000 }, // get up to 1000 chars per result
livecrawl: "preferred", // always get fresh content if possible
summary: true, // return an AI-generated summary for each result
},
}),
},
stopWhen: stepCountIs(5),
});
console.log(text);
所有选项
webSearch({
// Search settings
type: "auto", // "auto", "keyword", "neural", "fast", "deep"
category: "news", // "company", "research paper", "news", "pdf",
// "github", "personal site", "linkedin profile", "financial report"
numResults: 10,
// Filter by domain
includeDomains: ["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 text
includeText: ["AI"], // Must contain
excludeText: ["spam"], // Must not contain
// Location
userLocation: "US", // Two-letter country code
// Content options
contents: {
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,
},
},
})
类型脚本支持
完整类型脚本类型包括:
import { webSearch, ExaSearchConfig, ExaSearchResult } from "@exalabs/ai-sdk";
const config: ExaSearchConfig = {
numResults: 10,
type: "auto",
};
const search = webSearch(config);
链接
- GitHub 仓库 查看 npm 包的源代码
- 尝试 npm 软件包 - 在npm上查看
- Vercel AI SDK 烹饪本 - 以Exa为主角的网络搜索代理实例
- API 发光板 - 在仪表盘上试试Exa API
- 获取您的 API 密钥 - 拿你的API钥匙
- 文档 - Exa API文档
- Exa 网址 - 了解更多埃克萨
许可证
麻省理工学院