Innovation & Tech

Perplexity's Code Mode Cuts Agent API Costs Up to 53%

Perplexity's Code Mode, added to the Agent API on December 2, 2026, runs tool calls as parallel JavaScript in an embedded QuickJS runtime, cutting benchmark costs up to 53% and trimming tail latency by 56.6%.

By Nathan Brooks

4 min read

Perplexity's Code Mode Cuts Agent API Costs Up to 53%
AI-generated

What's News

  • Code Mode launched in Perplexity's Agent API on December 2, 2026 as programmatic_tool_calling, cutting WANDR benchmark costs by up to 53%.
  • At xhigh effort, soft recall rose from 78.7% to 80.5% while cost per task fell from $5.57 to $3.85.
  • Maximum benchmark task duration fell 56.6%, from 174.2 to 75.6 minutes, with exec returning partial output after 10 seconds.
  • Scripts run in an embedded QuickJS WebAssembly runtime and cannot import modules, use fetch, or access external data except through tools.
  • Code Mode is enabled by default in the latest high, xhigh and ultra effort levels.

Perplexity's new Code Mode cut benchmark costs by up to 53% and lifted research scores across every effort level, according to the company's own launch experiments. The feature, added to the Agent API on December 2, 2026, lets models write JavaScript programs that call tools in parallel instead of chaining repeated round-trips.

At the top ultra effort level, soft recall on Perplexity's WANDR research benchmark rose from 88.5% to 89.4% while average cost per task fell from $12.12 to $10.30. The xhigh tier gained more: 80.5% soft recall at $3.85 per task, against 78.7% at $5.57 for the same Sol-6.2 model without Code Mode.

The feature appears in API requests as programmatic_tool_calling. Scripts run inside an embedded QuickJS WebAssembly runtime within the agent loop, so a single program can execute tool calls in parallel, branch on results, remove duplicates and filter raw payloads before anything reaches the model's context. That last step is the cost lever — the model reads compact summaries, not streamed filings.

What's in the toolbox?

Enabled tools are exposed through one typed tools.* interface:

  • web search
  • URL fetching
  • people and finance search
  • MCP servers
  • sandbox file and shell tools

Code Mode extends Perplexity's earlier Search as Code system, which ran Python against pplx_sdk inside a Linux sandbox container. The new mode skips the container boot and the separate Python library entirely.

The announcement's finance example shows the operational shift: the model batches quarterly segment and earnings-transcript calls across six tickers, saves raw payloads to disk and emits compact summaries. Perplexity's framing is that agents stop paying context tokens for documents they only need to extract a few numbers from.

What does the 53% mean in practice?

The headline number comes from the jump at xhigh: $7.30 per task under the November 5, 2026 preset versus $3.85 with Sol-6.2 plus Code Mode — roughly a 47% cut on that pair, and up to 53% across the reported configurations. Perplexity's tables attribute part of the gain to the newer models themselves; Code Mode stacks on top.

The mid-tier result may matter more for practitioners. At the high effort level, Code Mode pushed soft recall to 47.7% at $0.38 per task — 2.9 percentage points above baseline, with no hand-crafted research workflows or prompts. Earlier experiments at high and lower effort had actually scored worse and cost more than direct tool calling, because models made syntax mistakes, misread tool outputs and burned extra steps recovering from script errors.

Perplexity evaluated the changes on the first 100 of 500 WANDR tasks. The benchmark, short for Wide ANd Deep Research, requires agents to collect broad entity sets and support each record with evidence, with a grader that re-fetches cited pages and checks whether pages and excerpts back the claims. Soft recall, the reported metric, gives partial credit for incomplete records and counts shortfalls as zero. Prompts, agent harness, search backend and grading stayed fixed across runs; only model generation, execution mode and cell scheduling varied.

Background execution trims the tail

Long fan-out or sandbox jobs can otherwise freeze the whole agent loop. Perplexity said exec returns partial output after 10 seconds while the script keeps running, letting the agent pursue other research branches before collecting results with exec_wait or cancelling a stalled script.

In paired WANDR runs at identical spend, the latency numbers moved most at the tail:

  • median duration fell 12.5%, from 28.9 to 25.3 minutes
  • the 95th percentile fell 40.9%, from 97.3 to 57.5 minutes
  • maximum duration fell 56.6%, from 174.2 to 75.6 minutes

The bigger tail reductions follow from the mechanism itself: work that would have left the loop idle now overlaps with other research.

The fine print for developers

Setup requires a programmatic_tool_calling object in the tools array of a POST /v1/agent request, plus programmatic in each tool's allowed_callers array. Tools can be programmatic-only, available through both direct and programmatic calls, or direct-only.

The constraints are real. Programs cannot import modules, use process or fetch, obtain external data except through tools, or retain variables for a later program. Identical requests can produce different programs. 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.

Version 0.50.0 of Perplexity's Python library and 0.45.0 of its TypeScript library lack Code Mode types, so the documentation's examples use direct HTTP requests. Custom functions pause a program until the developer returns function_call_output items. Programmatic-only MCP tools requiring approval need defer_loading set to true, or the approval request returns HTTP 400. A program error doesn't necessarily kill the response: it can still reach completed status with incomplete program_output, preserving text emitted before the error.

Code Mode is on by default in the latest high, xhigh and ultra effort levels and available in custom Agent API requests. Perplexity's tests fix the research stack, so whether the gains hold across developers' own tool mixes — particularly where custom functions and MCP approvals add handoffs — is now the central deployment question.

Source: unite.ai

Share this article:

More from Nathan Brooks

Nathan Brooks

Show full bio

News editor covering regulation, policy and their impact on entrepreneurship, startups and venture funding at Business Bearings.

3,168 articles

Related articles

« Previous articleNext article »