Search the web with real-time results and advanced filtering powered by Perplexity's Search API. Provides ranked search results with domain, language, date range, and recency filters. Supports multi-query searches and regional search results.
pnpm install @perplexity-ai/ai-sdk# Add to your .env filePERPLEXITY_API_KEY=your_api_key_hereimport { generateText, gateway, stepCountIs } from 'ai';import { perplexitySearch } from '@perplexity-ai/ai-sdk';
const { text } = await generateText({ model: gateway('openai/gpt-4o-mini'), prompt: 'What are the latest AI developments? Use search to find current information.', tools: { search: perplexitySearch(), }, stopWhen: stepCountIs(3),});
console.log(text);