Perplexity's Agent API Now Writes JavaScript to Call Its Own Tools
Perplexity's Agent API now runs JavaScript programs in a QuickJS runtime that call tools in parallel, filter payloads and continue in the background after 10 seconds — cutting WANDR research costs up to 53% in its own tests.

Why it matters
- Perplexity launched Code Mode (`programmatic_tool_calling`) in its Agent API on December 2, 2026, reporting benchmark cost cuts of up to 53%.
- At xhigh effort, WANDR soft recall rose from 76.5% to 80.5% while cost fell from $7.30 to $3.85 per task with Sol-6.2 plus Code Mode.
- Background `exec` returns partial output after 10 seconds; 95th-percentile task duration fell 40.9%, from 97.3 to 57.5 minutes.
- Scripts run in an embedded QuickJS WebAssembly runtime, with no module imports, no fetch, and no cross-program state.
- Perplexity's Python SDK 0.50.0 and TypeScript SDK 0.45.0 lack Code Mode types; documentation examples use direct HTTP requests.
Perplexity added Code Mode to its Agent API on December 2, 2026, letting models write JavaScript programs that call multiple tools in parallel — and the company reports benchmark costs falling by as much as 53% against its November 5, 2026 presets. The feature, formally named programmatic_tool_calling, replaces the repeated round-trip pattern of tool calling with scripts that branch, deduplicate and filter results before anything reaches the model's context window.
The stakes are straightforward for anyone building research agents. Tool-call loops dominate the cost and latency of deep-research systems, because every round trip feeds raw payloads back into context that the model then has to re-read, at token prices, to decide the next step. Cutting that overhead changes the economics of long-form agentic research. The caveat: every number here comes from Perplexity's own experiments inside Perplexity's own stack.
How Code Mode actually works
Scripts run inside an embedded QuickJS WebAssembly runtime placed directly in the agent loop. A single program can fire tool calls in parallel with Promise.all, branch on intermediate results, remove duplicates and strip raw payloads down to compact output before selected data returns to the model. Enabled tools surface through one typed tools.* interface, covering web search, URL fetching, people search, finance search, MCP (Model Context Protocol, the open standard for connecting models to external tools and data) servers, and sandbox file or shell tools.
The design descends from Perplexity's earlier Search as Code system, which executed Python against pplx_sdk inside a Linux sandbox container. Code Mode removes both the container boot and the separate Python search library from the critical path.
Perplexity's worked example is a finance research trajectory: the model batches quarterly segment and earnings-transcript calls across six tickers, saves raw payloads to disk and emits compact summaries rather than streaming large filings into context. In plain terms, the script does the filing-reading so the model does not have to.
What did the WANDR benchmarks show?
Perplexity evaluated the change on the first 100 of 500 tasks in WANDR (Wide ANnd Deep Research), a benchmark requiring agents to discover broad collections of entities and back each record with evidence. Its grader re-fetches cited pages and checks whether the pages and selected excerpts support the submitted claims. The reported metric is soft recall, a quality-adjusted completion measure that gives partial credit for incomplete records but counts any shortfall as zero.
The results at the xhigh effort level trace the full progression:
- November 5, 2026 preset: 76.5% soft recall at $7.30 per task
- Sol-6.2: 78.7% at $5.57
- Sol-6.2 plus Code Mode: 80.5% at $3.85
At the ultra effort level:
- November 5 preset: 85.9% at $21.71
- Opus 5.5 plus 3 Sol-6.2: 88.5% at $12.12
- Opus 5.5 plus 3 Sol-6.2 plus Code Mode: 89.4% at $10.30
Read the table carefully and the picture is more modest than the headline 53%. The first two configurations in each tier show newer reasoning models already improving scores and costs before Code Mode enters; the third row adds Code Mode on top of those same models. Model upgrades and execution mode are separate contributors, and the cost curve bends at both steps. Perplexity states that every experiment held the prompt, agent harness, search backend and grading pipeline fixed, varying only model generation, execution mode or cell scheduling — that controls variables, but only inside one harness.
The mid-tier result is the more notable claim. At the high effort level, Code Mode reached 47.7% soft recall at $0.38 per task, 2.9 percentage points above baseline, with what Perplexity describes as no hand-crafted research workflows or prompts. That claim comes with a disclosed failure mode: earlier experiments at high and lower effort levels scored worse and cost more than direct tool calling, as models made syntax mistakes, misread tool outputs and burned extra steps recovering from their own script errors. The technique, in other words, only pays off once the model can actually write the code.
How does background execution cut latency?
Long fan-out or sandbox jobs otherwise block the entire agent loop while the agent waits on a single script. Code Mode's exec call returns partial output after 10 seconds and leaves the script running in the background, so the agent can pursue other research branches, then collect results later with exec_wait or cancel a stalled script outright.
Paired WANDR runs at identical spend showed the effect concentrated in the tail:
- Median duration fell 12.5%, from 28.9 to 25.3 minutes
- 95th percentile duration fell 40.9%, from 97.3 to 57.5 minutes
- Maximum duration fell 56.6%, from 174.2 to 75.6 minutes
The mechanism explains the shape of those numbers: work that would have left the whole loop idle now overlaps with other research. The medians barely move; the worst cases nearly halve.
What are the limits developers will hit?
Enabling the feature requires a programmatic_tool_calling object in the tools array of a POST /v1/agent request, plus programmatic in the allowed_callers array of each tool a script may call. The documentation lets a tool be programmatic-only, available through both direct and programmatic calls, or direct-only. Programs call tools with await tools.<name>(args) and return data with text(value).
The sandbox walls are strict:
- No module imports
- No access to
processorfetch - No external data except through tools
- No variables retained across programs
- Identical requests can produce different programs
Two operational quirks deserve attention. When a model is supplied without an effort level, max_steps must allow at least two steps, so the model can read one program's output and write another. And version 0.50.0 of Perplexity's Python library and version 0.45.0 of its TypeScript library lack Code Mode types, which is why the official examples use direct HTTP requests — SDK support, not stated in the announcement, remains an open gap.
Custom functions pause a program until the developer returns function_call_output items carrying the original caller information. Programmatic-only MCP tools that require approval need defer_loading set to true; without it, the approval request returns HTTP 400. A program error does not necessarily fail the whole response — the response can still return completed status with incomplete program_output, preserving any text emitted before the error.
Code Mode ships enabled by default in the latest high, xhigh and ultra effort levels, and is available in custom Agent API requests.
The question the benchmarks don't answer
Perplexity's tests establish the gains inside one fixed research stack, on one benchmark, with one grading pipeline. Whether those gains persist across developers' own tool mixes and task shapes — particularly where custom functions and MCP approvals add human handoffs — is now the central deployment question, and it is the one Perplexity's own announcement leaves untested.
Source: unite.ai
More from James Calloway
Show full bio
News editor covering people, launches and day-to-day practice in artificial intelligence and machine learning at AI In Context.
1,002 articles
Related articles
- Perplexity's Monitor API turns web search into an always-on watchdog for AI agents
- Perplexity brings its full Computer agent to local Apple Silicon Macs
- Perplexity Launches Multiagent Mode to Coordinate Frontier AI Models
- DeepSeek V4.1-Flash-1017 Outscores Larger Rivals on Agentic Benchmarks
- Brain auto-writes skills: 72.9% of Perplexity test users got one