Perplexity's Search as Code: models write the retrieval pipeline
- Source
- perplexity.ai
- Publisher
- Perplexity
- Author
- Perplexity
- Date

Context
Perplexity's Search as Code moves the point where an agent's control over search stops. In the usual setup, a model sends a query, the search engine runs its own fixed pipeline, and a finished list of results comes back into the model's , one call per round trip. Under Search as Code, Perplexity says, no retrieval is sent through or . Instead the model writes Python that runs in a secure sandbox and calls an Agentic Search SDK. Perplexity says the SDK exposes the individual steps of its search stack: retrieval, ranking, filtering, fanouts and rendering. It also exposes intermediate state such as candidate lists and ranking signals. The old end-to-end search endpoint is still in the SDK as a shorthand the model can use or skip. Code also covers what the SDK lacks. In the blog's regex example, the program runs parallel searches to collect a broader set of results, removes duplicates, and then filters in code down to the exact pattern, instead of having the model sift a noisy result list in its own context. Perplexity announced that the architecture is available in its Agent API and is now the default in Computer.
The idea of agents writing code instead of making one tool call at a time is not new. Anthropic's code execution with MCP made a similar argument: intermediate tool results that pass through the context window add cost and latency. The difference Perplexity claims is lower in the stack. Its architecture write-up says it did not just put a traditional search API inside a language runtime. It rebuilt the search stack into composable primitives so the model can assemble a pipeline for each request. Because a custom SDK is unlikely to appear in training data, Perplexity also wrote Agent Skills to teach models how to combine the primitives. Their root files are under 2,000 tokens. Some state has to carry over between turns, for example fetching documents, inspecting a sample, then building a follow-up pipeline. For this, Perplexity chose to have the model explicitly save state to files rather than keep it in a REPL session. It says both approaches performed similarly in ordinary use, but saving to files was more reliable on very long runs. It calls this a tentative finding.
The results are Perplexity's own. In a test task to find and describe over 200 high-severity CVEs from vendors' own advisories, Perplexity reports 100% accuracy for Search as Code. Total token use fell 85.1% against its non-SaC baseline, from 288.7K to 42.9K, and the other systems tested scored below 25%. On five benchmarks, Search as Code ran GPT 5.5 at high reasoning. The comparison systems were OpenAI's Responses API with the same model, Anthropic Managed Agents with Opus 4.7, Exa and Parallel, each scored on single runs. Search as Code led on four benchmarks. On Humanity's Last Exam it scored 0.612 against OpenAI's 0.614, which Perplexity calls essentially tied. Two of the outside benchmarks target the breadth this design is built for. DeepSearchQA asks for exhaustive answer lists that require removing duplicates, and WideSearch asks for large-scale collection of individually checkable facts. Against a conventional pipeline on the same Perplexity search infrastructure, Perplexity reports the largest absolute gain on DeepSearchQA, 19.77 points, and the largest relative gain on WANDR, 12.00 points or 45%. WANDR was Perplexity's own benchmark and had not yet been published. There Search as Code scored 0.386 against 0.152 for the next system. Perplexity later released WANDR, which explains how its wide-and-deep tasks and evidence checks are graded.
- Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.
- Function — A named block of instructions that takes inputs, called arguments, and hands back a result, called its return value.
- tool use — A model's ability to call external functions — run code, search the web, edit files — instead of only generating text.
- Model Context Protocol (MCP) — A published agreement for an AI application to discover what a separate program offers and ask it to run one of those offerings.





