Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Search API Agent Tool Integration, Results and Snippet Extraction

When to use raw web search vs grounded agents, wire Search API into tool loops, and handle snippets, limits, and verification.

This page summarizes Perplexity documentation on the Search API: ranked web results you process yourself, versus the Agent API, which returns a researched answer with built-in tools such as web_search. The material below focuses on choosing between those surfaces, calling POST /search, and registering search as a function tool in your own agent loop.

Search API vs Agent API: which endpoint answers your question

Section titled “Search API vs Agent API: which endpoint answers your question”

The Search API and Agent API are different products with different response shapes. Use Search when you want structured hits; use Agent when you want the model to search and write the answer for you.

Search API — Returns structured JSON results[] with title, url, snippet, date, and last_updated. Call https://api.perplexity.ai/search directly — no router required. Agent API — Researched answers with built-in web search. Returns a prose answer with citations, not a results array.

— Perplexity, Search the Web

Use the Search API when you need raw results for your own processing. For an LLM-generated answer with citations, use the Agent API.

— Perplexity, Perplexity Search API

Need Use
Ranked title / url / snippet JSON for your pipeline Search API (client.search.create or POST /search)
Model decides when to search and returns grounded prose Agent API with {"type": "web_search"}
No LLM, fastest raw index access Standalone Search-only API (introduced in Perplexity’s changelog as search without LLM processing)
Repeatable Python retrieval stages with checkpointing Perplexity Search SDK (“Search as Code”)

POST /search: response fields and what snippet means

Section titled “POST /search: response fields and what snippet means”

A Search response is built around results[]. Each item includes title, url, and snippet; date and last_updated are optional freshness signals.

Everything your agent needs from a Search response is title, url, and snippet.

— Perplexity, Search API Overview

POST /search takes queries, not URLs. Each result’s snippet is text extracted from that page that is relevant to your query, cut to max_tokens_per_page. It is not the full page, and there is no parameter to re-fetch a page live or to control cache age.

— Perplexity, Search API Overview

Cap how much text reaches your model with max_tokens_per_page (per result) and max_tokens (whole response). Those parameters change extracted content, not price, per the same overview page.

search_type: "fast": when to prefer the fast index path

Section titled “search_type: "fast": when to prefer the fast index path”

Fast Search uses the same response shape as standard web search but targets lower latency.

Set search_type to "fast" on a POST /search request. Results use the same response format as standard web search.

— Perplexity, Use Fast Search

Passing search_type="fast" requires Perplexity Python library 0.43.6 or later, or TypeScript SDK 0.38.6 or later. max_results for fast search accepts 1–20 (values above 20 apply only with search_type: "people", as documented on Use Fast Search).

Multi-query search: billing vs rate limits

Section titled “Multi-query search: billing vs rate limits”

You can pass up to five related strings in one query array (fan-out in a single HTTP call).

Pass up to five related queries in one request to explore different angles of a topic. Each query is processed independently.

— Perplexity, Perplexity Search API

A successful multi-query request is billed as one Search API request, while rate limiting counts each query in the array.

— Perplexity, Perplexity Search API

The overview recommends deduplicating by url before passing context to your model, and skipping rows whose snippet is empty while still keeping the url if you want the model to cite it—see Search API Overview.

Register Search API as a web_search tool in your agent loop

Section titled “Register Search API as a web_search tool in your agent loop”

Perplexity documents the same pattern for OpenAI’s Responses API, Anthropic Messages, and Google’s google-genai SDK: define a web_search function whose handler calls client.search.create, then run the provider’s tool loop until the model stops requesting tools.

This guide shows how to expose Perplexity’s Search API to an OpenAI model as a function tool. The Responses API uses a manual tool-call loop: the model emits a function_call item with a call_id, you execute the tool (in this case, call client.search.create), and you send the result back as a function_call_output item paired by call_id.

— Perplexity, Use Search API with the OpenAI SDK

The Anthropic and Gemini guides describe the same division of labor: the model emits tool/function calls; your code calls Perplexity Search; you return formatted text in tool_result or function_response parts—see Use Search API with the Anthropic SDK and Use Search API with the Google Gemini SDK.

Common conclusion: all three integrations share one handler shape—a thin wrapper around perplexity.search.create that formats title, url, and trimmed snippet for the model—and one loop that continues until no pending tool calls remain. Perplexity supplies a verbatim tool description tuned for short keyword queries; the docs ask you to keep that wording for reliable query style (full text in the OpenAI integration page).

Tool description limits: three queries from the model, five on the wire

Section titled “Tool description limits: three queries from the model, five on the wire”

In the SDK integration guides, the tool schema asks the model for at most three queries per call (maxItems: 3 in examples). The Search API itself accepts up to five queries in query. Handlers typically pass the model’s array through; the OpenAI guide adds a defensive queries[:3] cap because strict JSON Schema cannot encode maxItems when strict: true.

The recommended query style is keyword-focused, not conversational:

Preferred: ["inflation rate Canada"] — Not recommended: ["What is the inflation rate in Canada?"]

— Perplexity, Use Search API with the OpenAI SDK

SDK Model emits You return Correlation key
OpenAI Responses function_call function_call_output call_id
Anthropic Messages tool_use tool_result tool_use_id
Google Gemini function_call parts function_response parts name + turn position

OpenAI’s Responses loop appends the assistant’s function_call items to input, then adds paired outputs—see the loop section in Use Search API with the OpenAI SDK. Anthropic requires every tool_use in a turn to get a matching tool_result in the next user message. Gemini’s manual loop must include both the model’s function_call and your function_response in the following generate_content call.

Query-relevant text from URLs you already have

Section titled “Query-relevant text from URLs you already have”

When you already know URLs, POST /search alone does not fetch them. Perplexity documents two CLI/SDK paths:

pplx content snippets "<query>" <url> [<url> ...] returns query-relevant passages from up to 50 URLs you name, with total and per-page token budgets and failures reported per URL.

— Perplexity, Search API Overview

The Perplexity CLI exposes the same ideas for shell and coding agents: pplx search web returns ranked JSON hits; pplx content snippets extracts passages. Extra positional queries on pplx search web are rephrasings of one question (one ranked set), while extra URLs on content snippets are independent pages snipped against the same query.

For Agent API runs where the model should read a page during generation, use the built-in fetch_url tool (Give it tools), which is separate from the Search API HTTP contract.

Ways to invoke search without writing the full tool loop

Section titled “Ways to invoke search without writing the full tool loop”

Perplexity lists several entry points that all surface the same ranked index or snippets:

Framework wrappers (for example CAMEL-AI’s search_perplexity, Mastra’s createPerplexitySearchTool, or Haystack’s PerplexityWebSearch) call the same POST https://api.perplexity.ai/search endpoint; see Perplexity with CAMEL-AI and Perplexity with Mastra.

Common mistakes when wiring Search into agents

Section titled “Common mistakes when wiring Search into agents”
  1. Expecting a generated answer from Search — Search returns results[], not assistant prose; generation stays on your side (Search the Web).
  2. Treating empty snippet as a hard failure — Keep or drop rows deliberately; empty snippets mean no extracted text for that hit (Search API Overview).
  3. Using long natural-language queries in tool calls — Perplexity’s tool descriptions optimize for short keyword arrays (Use Search API with the Anthropic SDK).
  4. Mixing allowlist and denylist domains in one search_domain_filter — CAMEL’s integration notes you must use one mode per request (Perplexity with CAMEL-AI).
  5. Defining custom functions named web_search on Agent API — Reserved built-in names include web_search, fetch_url, people_search, and finance_search (Perplexity with OpenClaw).
  6. Assuming multi-query billing equals rate-limit cost — One billed request can consume multiple rate-limit units (Perplexity Search API).
  1. Set PERPLEXITY_API_KEY and run a minimal Search call from Quickstart or Search the Web; confirm each result has title, url, and that non-empty snippet values look query-relevant.

  2. If you use fast search, repeat with search_type: "fast" per Use Fast Search and confirm your SDK version meets the stated minimum.

  3. In your agent integration, log one full tool round-trip using the loop from Use Search API with the OpenAI SDK (or Anthropic/Gemini equivalent) and verify call_id / tool_use_id pairing before the final answer.

  4. For known URLs, run pplx content snippets from Perplexity CLI and inspect each result for error vs text.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match the official docs, or you need a clarification on Search API tool integration, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.