Perplexity Agent API Code Mode for Parallel Tools
Learn when to use Perplexity Code Mode, how to enable programmatic tools, and which usage to measure.
By the buymeatokens team2 min read
Short answer
Code Mode lets a Perplexity agent run JavaScript that calls enabled tools in parallel and returns selected results to the model.
On this page
Perplexity added Code Mode to the Agent API in December. For a research job that needs several independent sources, the model can write a short JavaScript program, call tools concurrently, and filter the results before they enter its context. This can reduce the number of model turns spent on intermediate responses. Perplexity Code Mode announcement
Enable Code Mode on a small workflow
The feature is available through updated high, xhigh, and ultra presets or a custom request with programmatic_tool_calling. In the custom configuration, use the programmatic entry in allowed_callers for each tool you intend to expose. Start with read-only search or a custom inventory lookup. Give the agent a clear stop condition and a compact result schema. Perplexity API changelog
Test where parallelism actually helps
For a dependency research report, give it three package names. Search all three in parallel, fetch the official release notes, and return a version, release date, and link for each. Compare the response to a regular tool-calling run and measure wall-clock time, total tool calls, and whether the links support the claims. Make the program return failed lookups explicitly so a timeout cannot silently erase a package. Understand MCP tool token overhead
Follow the cost past the model response
Record model usage and separately billed tools. Include sandbox charges if your workflow uses billable sandbox tools. Fan-out can send ten search requests in the time one model turn would take, and the number of requests still contributes to the bill. Set a call limit on the application side for a predictable pilot. Track LLM token usage
Frequently asked questions
Can Code Mode call MCP tools?
Perplexity supports enabled MCP tools alongside built-in and custom tools. Limit the set to tools needed for the workflow.
Does historical retrieval work in Code Mode?
Perplexity lists snapshot_as_of as incompatible with Code Mode. Use a compatible request configuration if historical snapshots are central to the task.
When should I keep ordinary tool calls?
Use the simpler workflow for a single lookup or a short sequence with a required human decision between calls.