What you need
- Python 3.14 and a shell. The example runs on Linux.
- A Perplexity API key.
httpx in a virtual environment and set your API key. The script sends HTTP requests with httpx because version 0.50.0 of the Perplexity Python library does not have types for the Code Mode tool and output items.
How the request works
The script sends ten package names toPOST /v1/agent. It adds programmatic_tool_calling to tools and puts programmatic in allowed_callers on web_search and fetch_url.
The instructions ask the model to write one program. The program searches for each package with tools.search_web and Promise.all, then fetches the matching PyPI pages with tools.fetch_url. It calls text() with the page URLs, version headings, and release dates instead of the full tool results.
The response contains the JavaScript in a program item and its status in a program_output item with the same call_id. The script reads the table from the assistant’s message, not from either program item. The request’s JSON Schema defines the table fields, and the script checks the package order, date format, and source URLs.
Run the script
Save this script asrelease_watchlist.py in your working directory.
release_watchlist.py
release_watchlist.py
release_watchlist.py
unverified for that row’s version, date, and URL. The script does not check whether a release is compatible with your project.
Compare with direct tool calls
Use--compare to send a second request with the same model, tools, package list, and output schema. The second request omits the Code Mode marker, caller restrictions, and program instructions.
usage.tool_calls_details and total cost from usage.cost.total_cost.
In this recorded run, both requests returned the same ten rows. The program sent the model only the selected evidence, while direct tool calls sent fetched page text.
Results and metrics can change on each run. Check the release rows before you compare the request metrics.
Next steps
- See Code Mode for the
allowed_callersrules, the response items, streaming events, and error messages. - See Fetch URL Content and Web Search for the two tools that the program calls.