The Agent API provides tools that extend model capabilities beyond their training data. Tools must be explicitly configured in your API request—once enabled, models autonomously decide when to use them based on your instructions.
Type
Tools
Use Case
Built-in
web_search, fetch_url
Real-time web information retrieval
Custom
Your functions
Connect to databases, APIs, business logic
Enable tools by adding them to the tools array in your request:
from perplexity import Perplexityclient = Perplexity()response = client.responses.create( model="openai/gpt-5.4", input="What are the latest AI developments?", tools=[ {"type": "web_search"}, {"type": "fetch_url"} ], instructions="Use web_search for current information. Use fetch_url when you need full article content.")print(response.output_text)
The web_search tool allows models to perform web searches with advanced filtering capabilities. Use it when you need current information, news, or data beyond the model’s training cutoff.Pricing: $5.00 per 1,000 search calls ($0.005 per search), plus token costs.
The fetch_url tool fetches and extracts content from specific URLs. Use it when you need the full content of a particular web page, article, or document rather than search results.Pricing: $0.50 per 1,000 requests ($0.0005 per fetch), plus token costs.
from perplexity import Perplexityclient = Perplexity()response = client.responses.create( model="openai/gpt-5.4", input="Summarize the content at https://example.com/article", tools=[ { "type": "fetch_url" } ], instructions="Use fetch_url to retrieve and summarize the article.")print(response.output_text)
Function calling allows you to define custom functions that models can invoke during a conversation. Unlike built-in tools, custom functions let you connect the model to your own systems—databases, APIs, business logic, or any external service.Pricing: No additional cost (standard token pricing applies).
from perplexity import Perplexityimport jsonclient = Perplexity()# Define your function toolstools = [ { "type": "function", "name": "get_horoscope", "description": "Get today's horoscope for an astrological sign.", "parameters": { "type": "object", "properties": { "sign": { "type": "string", "description": "An astrological sign like Taurus or Aquarius" } }, "required": ["sign"] } }]# Your actual function implementationdef get_horoscope(sign: str) -> str: return f"{sign}: Today brings new opportunities for growth."# Send initial request with toolsresponse = client.responses.create( model="openai/gpt-5.4", tools=tools, input="What is my horoscope? I am an Aquarius.")# Process the response and handle function callsnext_input = [item.model_dump() for item in response.output]for item in response.output: if item.type == "function_call": # Execute the function args = json.loads(item.arguments) result = get_horoscope(args["sign"]) # Add the function result to the input next_input.append({ "type": "function_call_output", "call_id": item.call_id, "output": json.dumps({"horoscope": result}) })# Send the function results back to get the final responsefinal_response = client.responses.create( model="openai/gpt-5.4", input=next_input)print(final_response.output_text)
Clear description of what the function does and when to use it
parameters
object
Yes
JSON Schema defining the function’s parameters
strict
boolean
No
Enable strict schema validation
The arguments field in function calls is a JSON string, not a parsed object. Always use json.loads() (Python) or JSON.parse() (JavaScript) to parse it.
Write clear, specific function descriptions. The model uses these to decide when to call each function. Include details about what the function returns and any constraints.