In short.
Function Calling End-to-End is a Perplexity tutorial for developers connecting AI models to application functions, but its examples need real services and additional error handling before deployment. It explains matching calls to results, preserving conversation context, repeating requests across turns and mixing server-side web search with application-side execution. Its strongest value is as an implementation reference. The displayed code has limitations around argument parsing, turn-limit handling and adapting TypeScript handlers to asynchronous work. Runtime correctness, performance, costs and current model compatibility are not established.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete captured article at [https://docs.perplexity.ai/docs/cookbook/articles/function-calling-e2e/README.md], including prerequisites, Python and TypeScript examples, multi-turn orchestration, mixed web search and custom functions, error handling, parallel processing and accompanying notes. Linked documentation, the documentation index, model catalog and API-key portal are excluded. The article states that Agent API familiarity is assumed and contains no license notice or publication date. No code or API requests were executed; runtime behavior, current compatibility, costs and performance are not assessed.
The overview
Identity
Function Calling End-to-End is a cookbook article on Perplexity's documentation site at [https://docs.perplexity.ai/docs/cookbook/articles/function-calling-e2e/README.md]. It teaches function-calling patterns for the Perplexity Agent API through Python and TypeScript examples.
The article concentrates on application code that receives model requests to call functions, executes those functions and returns their results. It also explains how this interacts with built-in tools such as web_search.
Practical assessment
This is useful for developers moving beyond a basic tool definition to a repeated execution loop. It connects several details that are easy to miss: preserving the original request, replaying function calls, matching results through call_id and handling more than one call before requesting another model response.
The page describes its patterns as production-ready, but the examples use sample data, simulated failures and placeholder service operations. Some important failure paths remain outside the shown error handling. Treat it as a reference to adapt before deployment.
Who it suits
The intended reader already understands the Agent API and tool definitions; the page explicitly assumes that familiarity. Developers building order-support assistants, research workflows, scheduling helpers or applications that combine several data sources have directly relevant examples.
Beginners will need enough Python or TypeScript to follow function dispatch, JSON parsing, request construction and loops. The parallel section additionally introduces Python threads and JavaScript promises. Basic API setup and parameter reference are delegated to linked documentation.
What it covers
The article covers a single-function order lookup, orchestration across weather, calendar and email functions, web research followed by a custom save operation, structured function errors and processing multiple independent calls from one response. Each main pattern has Python and TypeScript code.
The mixed-tool walkthrough uses web_search alongside save_to_db. The parallel walkthrough uses stock-price and company-information functions, with ThreadPoolExecutor in Python and a Promise.all pattern in TypeScript. Fetch URL Content, Finance Search and People Search are linked, but their use is not demonstrated in equivalent walkthroughs on this page.
Using it
What you need
The examples require a Perplexity API key and a Python or TypeScript environment using the corresponding Perplexity SDK. The packages shown are perplexityai for Python and @perplexity-ai/perplexity_ai for TypeScript.
Useful deployment also requires implementations of the custom functions and access to the services they represent, such as an order system, database or email service. The article does not specify supported runtime versions, pin SDK versions or establish the current availability of its example model.
How function calling works
Each custom tool supplies a name, description and JSON parameter schema. A model response can contain function_call items whose arguments field is a JSON string. Application code parses that string, dispatches the named function and returns a serialized result in a function_call_output item carrying the matching call_id.
The repeated-turn examples send the original request and accumulated conversation back through client.responses.create until no custom function calls remain. Built-in web_search runs server-side, while custom functions execute in the application. When several calls arrive together, the examples collect their results before making the next request.
The Python examples preserve all response output items through model_dump. The TypeScript examples reconstruct the function-call items and preserve thought_signature when present. Compatibility of this replay difference across models and mixed-tool responses is not established by the page.
Getting started
The page specifies pip install perplexityai for Python or npm install @perplexity-ai/perplexity_ai for TypeScript. It directs readers to create a key at [https://console.perplexity.ai/project/keys] and set the PERPLEXITY_API_KEY environment variable.
The examples then initialize a Perplexity client, define function schemas and provide matching implementations. Start with the order-lookup pattern to understand the request and result format, then use a repeated-turn pattern when later calls can depend on earlier results.
A worked example
The research walkthrough asks for recent solid-state battery developments, supplies web_search and save_to_db, and instructs the model to search before saving a summary and source URLs. The application handles the custom save call and sends its result back through the conversation loop.
The shown save_to_db implementation constructs a record identifier and prints or logs a message; it performs no database write. Likewise, the order, weather, calendar, email and stock functions return fixed sample data or simulated outcomes. These examples illustrate orchestration without establishing working business integrations.
Assessment & evidence
Limitations
The first order-lookup example processes one batch of calls and makes one follow-up request. It does not handle another function call returned by that follow-up. Several later examples supply repeated loops, but most have no turn cap.
The error-handling dispatcher does not cover failures from JSON parsing or responses.create, which occur outside its protected execution block. Comprehensive application-side argument validation is also not demonstrated. Its capped loop returns an exceeded-limit error whenever the counter reaches ten, even if the last response has already finished without further calls.
The TypeScript parallel example uses synchronous mock handlers and immediately serializes the return from functionMap. Asynchronous replacements need their results awaited before serialization. Promise.all around the existing wrapper does not make synchronous work execute in parallel, and no speed improvement is measured.
The examples do not demonstrate authorization or duplicate-operation handling for real email sends or database writes. The page also provides no reliability measurements or evidence that model tool selection and ordering will always be correct.
Why the patterns matter
The guide makes the division of responsibility clear: the model requests a custom function, the application executes it and call_id connects its result to the request. Preserving the conversation lets a later decision use earlier results.
Repeated turns suit dependent work, such as using weather information to decide whether an email reminder is warranted. Batching suits independent lookups, such as retrieving stock prices and company details. These examples help readers choose an orchestration shape, while correctness still depends on the real functions and how the application handles their results.
Other starting points
For introductory setup, the article links to the Agent API Quickstart at [https://docs.perplexity.ai/docs/agent-api/quickstart.md]. For basic usage, request parameters and tool schemas, it points to the Agent API Reference at [https://docs.perplexity.ai/api-reference/agent-post.md].
It also links to Output Control at [https://docs.perplexity.ai/docs/agent-api/output-control.md] for combining function calling with structured outputs. These linked pages are outside the supplied evidence, so their contents and suitability are not assessed. The article provides no comparison with other providers or frameworks.
Evidence and confidence
The evidence consists of the complete Perplexity article and its embedded Python and TypeScript examples, supplied as selected-page.txt. It supports the described request structures, intended control flow and observations about the displayed code.
No code was executed. The supplied article contains no runtime logs, automated test results, benchmarks or independent validation. API compatibility, actual error recovery, reliability and performance remain unassessed.
Access & freshness
Costs
The page provides no model prices, built-in tool charges, free-tier allowance or measured usage. Total cost is unknown from this evidence.
Repeated-turn workflows make additional API requests and resend accumulated conversation content. Turn count, conversation size and output limits therefore matter to a budget, but the sample token caps are limits rather than measured consumption. Costs for real databases, email services and other integrations are also unspecified.
Usage rights
The supplied page states no license or explicit reuse permission for its prose or embedded code. Permission to copy, modify or redistribute that material is unknown. Public access to the documentation does not establish those rights.
SDK licenses and API service terms are not included in the supplied evidence, so their conditions are not assessed.
Currency
The supplied capture is dated 2026-11-25. The article gives no publication date, last-updated date or pinned SDK version, so the capture date does not establish when its examples were written or last verified.
The examples use the model identifier anthropic/claude-sonnet-5-5. Its current availability and compatibility with the shown requests are not established here. Calendar dates, delivery dates and stock prices in the mock functions are demonstration values rather than current information.
Next actions
Confirm a currently supported model and compatible SDK before adapting the examples. The article links to the model documentation at [https://docs.perplexity.ai/docs/agent-api/models.md], whose contents are not included here. Replace the sample functions with the specific services your application needs.
Handle argument-parsing and API-request failures, validate inputs and define a turn limit that accepts a completed final response. Await asynchronous TypeScript handler results before serializing them, and confirm that calls grouped together are independent.
For real email or database operations, define authorization and duplicate-call handling. Obtain current model, tool and connected-service prices separately before estimating a budget.
