Home/Tools/@perplexity-ai/ai-sdk

perplexitySearch

@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

search
v0.1.2
MIT

Interactive Playground

Test @perplexity-ai/ai-sdk (perplexitySearch) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @perplexity-ai/ai-sdk
pnpm add @perplexity-ai/ai-sdk
yarn add @perplexity-ai/ai-sdk
bun add @perplexity-ai/ai-sdk
deno add npm:@perplexity-ai/ai-sdk

2. Import the tool

import { perplexitySearch } from '@perplexity-ai/ai-sdk';

3. Use with 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);

AI Agent Integration

How AI agents can use this tool

Use Case

Use for comprehensive web search with filtering capabilities

Examples

  • Find latest AI developments
  • Search with date range filters
  • Domain-specific searches

Signature

(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>

Tags

ai
ai-sdk
api
information
news
perplexity
perplexity-ai
real
research
sdk
search
time
web
web-search

Parameters

Available configuration options

Auto-extracted
query
Required
Type: object

Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries.

max_results
Optional
Type: number

Maximum number of search results to return (1-20, default: 10)

max_tokens_per_page
Optional
Type: number

Maximum number of tokens to extract per search result page (256-2048, default: 1024)

country
Optional
Type: string

Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')

search_domain_filter
Optional
Type: array

List 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_filter
Optional
Type: array

List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']

search_after_date
Optional
Type: string

Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter.

search_before_date
Optional
Type: string

Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter.

search_recency_filter
Optional
Type: string

Filter 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

README

Perplexity Search for the Vercel AI SDK

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.

Installation

pnpm install @perplexity-ai/ai-sdk

Usage

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(),
  },
});

Options

You can configure the API key for your tool. The perplexitySearch tool accepts an optional configuration object:

type PerplexitySearchConfig = {
  apiKey?: string;
};

Features

  • Real-time web search using Perplexity's continuously refreshed index
  • Multi-query support - search with multiple queries in a single request
  • Advanced filtering - domain, language, date range, and recency filters
  • Regional search - get geographically relevant results by country
  • Flexible content extraction - control how much content is extracted per page
  • Type-safe - Full TypeScript support with comprehensive type definitions

Advanced Usage

Regional Search

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" }

Domain Filtering

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"] 
// }

Multi-Query Search

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"] 
// }

Configuration Options

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")

API Configuration

You can also pass the API key directly:

import { perplexitySearch } from "@perplexity-ai/ai-sdk";

const search = perplexitySearch({
  apiKey: "your-api-key-here"
});

Response Format

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"
}

Development

Setup

  1. Clone the repository
  2. Install dependencies:
pnpm install
  1. Create a .env file:
cp env.example .env
  1. Add your Perplexity API key to .env

Testing

Test your tool locally:

pnpm test

Building

Build the package:

pnpm build

Publishing

Before publishing, update the package name in package.json to your desired package name.

The package automatically builds before publishing:

pnpm publish

Project Structure

.
├── 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

License

MIT

Links

Statistics

Downloads/month

24,757

GitHub Stars

0

Executions

1

Quality Score

90%

Bundle Size

NPM Keywords

ai
ai-sdk
tools
perplexity-ai
search
web-search

Maintainers

kesku(gogeta1183@gmail.com)

Frameworks

vercel-ai