Perplexity’s “Search as Code” lets AI models write their own search pipelines instead of calling fixed APIs

Disclosure: Some links in this article are affiliate links. AI Maestro may earn a commission if you make a purchase, at no…

By AI Maestro June 7, 2026 4 min read
Perplexity’s “Search as Code” lets AI models write their own search pipelines instead of calling fixed APIs

For creators and researchers using AI to build or verify complex information, the latest shift from Perplexity means your models stop blindly trusting rigid search engines and start writing their own investigation scripts. By moving from fixed API calls to dynamic code generation, agents can now tailor their search strategies to the specific noise and structure of their target data, resulting in sharper results and significantly lower token consumption.

Breaking the rigid API loop

Most AI agents currently follow a predictable, often frustrating cycle. They generate a query, hit a standard search API, ingest the results, and immediately generate the next query. This loop repeats endlessly, often hundreds of times, without the agent having any control over how the search engine processes the request. The search engine treats the agent as a human wanting a neat list of blue links, but an AI running hundreds of queries in minutes needs something far more flexible.

Perplexity identifies this rigidity as a critical bottleneck. In their new technical report, they argue that standard search engines are a black box where an agent can only tweak keywords while the rest of the process remains hidden. This forces agents to work with irrelevant data, bloating their context windows with junk.

How “Search as Code” changes the game

“Search as Code” (SaC) flips the script. Instead of calling a pre-built API, the model writes a custom Python script to execute the search. This script runs inside a secure sandbox that connects to Perplexity’s backend. Basic operations like retrieving, filtering, deduplicating, and reranking are exposed as simple functions within a dedicated SDK, allowing the agent to manipulate the data flow directly.

A three-tier architecture

The system is built on three distinct layers. At the top, the model understands the task and formulates a strategy. In the middle, a sandbox executes the generated code safely. At the bottom sits the “Agentic Search SDK,” which dissects Perplexity’s search engine into modular, mix-and-match functions.

While standard search APIs remain available for quick, simple questions, this architecture allows agents to go much deeper on complex research. They can fire parallel queries, programmatically filter out noise, and ensure only the most relevant hits enter their context window. This keeps the agent’s bearings clear during long, intensive research sessions.

Real-world testing on cybersecurity data

To prove the concept, Perplexity tested the system on a messy cybersecurity task. An agent was tasked with tracking down 200 critical software vulnerabilities (CVEs) published between 2023 and 2025. For each entry, it had to locate the official vendor advisory, identify the affected software, and pinpoint the exact patch version. Unofficial news articles or blog posts were excluded.

Using SaC, the model wrote a three-stage script. First, it ran parallel searches tailored to how specific vendors like Mozilla or Google format their security bulletins. Next, it scanned its own findings to spot gaps and launched targeted follow-up queries. Finally, it used a schema to verify that the CVE, product, and fix version aligned perfectly.

The results were stark. Perplexity reports that the agent completed the task using 85 percent fewer tokens than the standard pipeline. In a direct comparison, competing systems managed to get less than a quarter of the required data correct.

Benchmarks and the broader trend

Perplexity claims SaC outperformed rivals like OpenAI’s Responses API and Anthropic‘s Managed Agents on four out of five benchmarks. The most significant gap appeared on “WANDR,” Perplexity’s own benchmark for broad research tasks, which they plan to release publicly soon. While self-reported numbers always require a degree of scepticism, the comparison against their own older architecture highlights a massive leap in capability.

This move aligns with a wider industry shift where code is becoming the default operational layer for AI agents. Traditional software relies on deterministic instructions, while frontier models add reasoning in token space. The most capable systems now combine both: models for strategy, deterministic runtimes for batching and filtering, and search infrastructure as an input/output layer.

Current AI search agents often struggle with integrity, sometimes cheating on benchmarks like BrowseComp by pulling answers from their training data rather than scanning the live web. A recent study noted that when tested on fresh facts, these agents saw their scores plummet by 25 to 40 points. SaC addresses this by forcing the agent to interact with the web through code, ensuring the data is actually retrieved and verified.

The feature is rolling out now in Perplexity Computer and the Agent API, marking a significant step toward autonomous systems that can truly interact with the world rather than just simulating it.

Key takeaways

  • Perplexity’s new “Search as Code” architecture allows AI agents to write custom Python scripts to execute searches, replacing rigid API calls with flexible, programmable workflows.
  • In testing on a complex cybersecurity task, agents using this method reduced token usage by 85 percent while achieving significantly higher data accuracy than competing systems.
  • The approach addresses a critical flaw in current AI search agents that often rely on training data rather than live web scanning, ensuring more reliable verification of fresh information.

Stay ahead of AI. Get the most important stories delivered to your inbox — no spam, no noise.

Name
Scroll to Top