@perplexity-ai/ai-sdk
Search the web using Perplexity's Search API for real-time information, news, research papers, and articles. Provides ranked search results with advanced filtering options including domain, language, date range, and recency filters.
by Perplexity AI
Test @perplexity-ai/ai-sdk (perplexitySearch) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @perplexity-ai/ai-sdkpnpm add @perplexity-ai/ai-sdkyarn add @perplexity-ai/ai-sdkbun add @perplexity-ai/ai-sdkdeno add npm:@perplexity-ai/ai-sdkimport { perplexitySearch } from '@perplexity-ai/ai-sdk';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { perplexitySearch } from '@perplexity-ai/ai-sdk';
const result = await generateText({
model: openai('gpt-4o'),
tools: { perplexitySearch },
prompt: 'Your prompt here...',
});
console.log(result.text);How AI agents can use this tool
Use for comprehensive web search with filtering capabilities
(query: { }, country?: string, max_results?: number, search_after_date?: string, search_before_date?: string, max_tokens_per_page?: number, search_domain_filter?: string[], search_recency_filter?: string, search_language_filter?: string[]) => Promise<unknown>Available configuration options
queryobjectSearch query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries.
max_resultsnumberMaximum number of search results to return (1-20, default: 10)
max_tokens_per_pagenumberMaximum number of tokens to extract per search result page (256-2048, default: 1024)
countrystringTwo-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')
search_domain_filterarrayList of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']
search_language_filterarrayList of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']
search_after_datestringInclude only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter.
search_before_datestringInclude only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter.
search_recency_filterstringFilter results by relative time period. Cannot be used with search_after_date or search_before_date.
Schema extracted: 3/1/2026, 1:19:31 AM
A powerful web search tool powered by Perplexity's Search API for use with the Vercel AI SDK. Search the web for real-time information, news, research papers, and articles with advanced filtering options including domain, language, date range, and recency filters.
pnpm install @perplexity-ai/ai-sdk
import { perplexitySearch } from "@perplexity-ai/ai-sdk"; import { generateText, gateway } from "ai"; const result = await generateText({ model: gateway("openai/gpt-4o-mini"), prompt: "What are the latest AI developments? Use search to find current information.", tools: { search: perplexitySearch(), }, });
You can configure the API key for your tool. The perplexitySearch tool accepts an optional configuration object:
type PerplexitySearchConfig = { apiKey?: string; };
const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'What are the latest government policies on renewable energy in the US?', tools: { search: perplexitySearch(), }, });
The AI can use the country parameter to get region-specific results:
// The AI will automatically use parameters like: // { query: "government policies renewable energy", country: "US" }
const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Find recent climate change research from scientific journals only.', tools: { search: perplexitySearch(), }, });
The AI can filter to specific domains:
// The AI might use: // { // query: "climate change research", // search_domain_filter: ["nature.com", "science.org", "pnas.org"] // }
const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Research AI safety, AGI development, and AI regulation. Use multiple searches.', tools: { search: perplexitySearch(), }, });
The AI can perform multiple searches:
// The AI might use: // { // query: ["AI safety research", "AGI development timeline", "AI regulation 2025"] // }
The AI can use these parameters when calling the search tool:
query - Search query (string or array of up to 5 strings)max_results - Number of results (1-20, default: 10)max_tokens_per_page - Content extraction limit (256-2048, default: 1024)country - ISO country code for regional results (e.g., "US", "GB")search_domain_filter - Include/exclude domains (max 20)search_language_filter - Language filtering (max 10 ISO codes)search_after_date - Results after date (MM/DD/YYYY format)search_before_date - Results before date (MM/DD/YYYY format)search_recency_filter - Time-based filtering ("day", "week", "month", "year")You can also pass the API key directly:
import { perplexitySearch } from "@perplexity-ai/ai-sdk"; const search = perplexitySearch({ apiKey: "your-api-key-here" });
The tool returns structured search results:
{ results: [ { title: "Article Title", url: "https://example.com/article", snippet: "Content preview...", date: "2025-01-15", last_updated: "2025-01-20" } ], id: "search-request-id" }
pnpm install
.env file:cp env.example .env
.envTest your tool locally:
pnpm test
Build the package:
pnpm build
Before publishing, update the package name in package.json to your desired package name.
The package automatically builds before publishing:
pnpm publish
.
├── src/
│ ├── tools/
│ │ └── perplexity-search.ts # Perplexity search tool implementation
│ ├── types.ts # TypeScript type definitions
│ ├── index.ts # Tool exports
│ └── test.ts # Test script
├── dist/ # Build output (generated)
├── package.json
├── tsconfig.json
├── env.example
├── .gitignore
└── README.md
MIT
Downloads/month
24,757
GitHub Stars
0
Executions
1
Quality Score