Perplexity AI's Search as Code cuts token use 85% for AI agents
AI agents can now write their own search workflows in Python, cutting tokens by 85%.
Perplexity AI has introduced Search as Code (SaC), a new architecture that enables AI models to write their own search pipelines in Python instead of calling fixed APIs. Announced on June 6, SaC addresses a fundamental flaw in how AI agents interact with search infrastructure: the standard loop of writing a query, getting results, and iterating was designed for humans, not autonomous systems performing hundreds of rapid searches. By letting models control ranking, filtering, and deduplication through code, SaC eliminates the context-window bloat caused by rigid backend logic.
In benchmark tests, SaC achieved 100% accuracy on a task of tracking 200 high-severity CVEs while consuming only 42,900 tokens — an 85% reduction from Perplexity's own standard pipeline's 288,700 tokens. Competing systems from OpenAI and Anthropic scored below 25% on the same task. On the WANDR broad-research benchmark, SaC showed a 45% absolute improvement over Perplexity's baseline. The architecture operates in three layers: a reasoning model that decomposes tasks and generates Python code, a compute sandbox with a persistent filesystem for cross-turn state, and an agentic search SDK exposing atomic primitives like retrieve, filter, rerank, and dedupe.
For developers, SaC marks a shift from black-box search APIs to programmable infrastructure. Now rolling out in Perplexity Computer, the approach allows AI agents to design custom search strategies — essentially codifying the intuition of a human engineer. This puts pressure on API providers to expose internals as programmable primitives, and favors frontier models with strong code-generation capabilities. As Perplexity notes, 'Code is a powerful medium for orchestrating preexisting capabilities — it can also serve as a gap-filler for capabilities not present in the search stack.'
- Reduces token usage by 85% (from 288,700 to 42,900) on complex vulnerability research tasks.
- Achieves 100% accuracy on 200 CVE tasks, outperforming OpenAI and Anthropic systems that scored below 25%.
- Uses three-layer architecture: Model (control plane), Compute Sandbox with persistent filesystem, and Agentic Search SDK with atomic primitives.
Why It Matters
AI agents can now design custom search pipelines, shifting the bottleneck from API limitations to model reasoning capabilities.