PARAS MADAN
All writing

Latest in AI

Perplexity Agent API Code Mode vs direct tool calling: When to use it

Compare the two routes on a read-only product lookup, and measure completed work instead of assuming that parallel calls make every task cheaper.

Perplexity's Agent API now lets a model write JavaScript that calls several permitted tools in one step. Code Mode can help when an agent needs many independent lookups and only a few fields back. For a single lookup, direct tool calling is a better baseline.

What changes in Code Mode

In a direct flow, the model makes a tool call and sees its result before deciding what to do next. With Code Mode, a generated script can handle independent lookups in parallel, remove duplicates and return a compact result to the model. Perplexity's launch write-up says the JavaScript runs in an embedded QuickJS WebAssembly runtime.

This differs from Perplexity's earlier Search as Code experiment, which ran Python with a search library in a separate sandbox container. You can now choose which eligible API tools the program may call. The feature changes the way tool calls are coordinated; it doesn't make the underlying data sources more accurate.

Set up an honest comparison

Use a synthetic catalog where Alpha, Beta and Gamma each have a known price and currency. Ask for the three prices and their corresponding IDs. In a custom Agent API request, add the tool type programmatic_tool_calling for the Code Mode variant and put programmatic in the eligible lookup tool's allowed_callers. The comparison variant should use direct calls to the same read-only lookup. Keep the model, catalog and prompt fixed.

Don't use the updated high, xhigh or ultra presets as your direct-call control. Perplexity says those presets already use Code Mode. Check the trace to confirm both variants actually took different paths. Use synthetic records and leave out tools that can make changes.

Verify what the script kept

Add two cases to the catalog test: a duplicated ID and a lookup that returns no price. The script should preserve the currency along with the price, deduplicate the repeated ID and carry through the missing value. A short response that quietly omits Gamma is cheaper to read and still wrong.

Track exact field matches, missing records, tool calls, end-to-end latency and cost per complete result. Compare a one-record task and a 20-record task. If the smaller job slows down while the wider job gets faster, you have a useful routing rule rather than one average hiding both outcomes.

Read the published cost comparison carefully

On Perplexity's WANDR subset, the reported xhigh result for Sol-6.2 moved from 78.7% at $5.57 per task before Code Mode to 80.5% at $3.85 when it was enabled. That is around 31% less in the same-model comparison. The larger 47% figure in the announcement uses older November 5 tooling and models as the baseline. Use the first comparison for a rough sense of Code Mode's effect there; neither makes a price promise for your catalog.

I'd enable it for wide, read-only lookups once the compressed output preserves the fields your application needs to audit. Keep the direct path for small tasks until there's evidence that changing it makes the result better or cheaper.

I'm Paras. I work at the intersection of AI, engineering and distribution.

I help developers explain agent APIs with tests that show what changes in a real workflow.

Book a 30-minute call