This guide shows how to extract structured, typed JSON from the Agent API using theDocumentation Index
Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt
Use this file to discover all available pages before exploring further.
response_format parameter with JSON schemas. You will learn practical patterns for product data extraction, research findings, comparison tables, and building reliable data pipelines — all with guaranteed schema conformance.
The Agent API enforces your JSON schema at generation time, so responses always conform to the specified structure. For the full parameter reference, see Output Control.
Prerequisites
Install the Perplexity SDK:Get your Perplexity API Key
Navigate to the API Keys tab in the API Portal and generate a new key.
How Structured Outputs Work
When you passresponse_format with type: "json_schema", the Agent API constrains the model’s output to match your schema exactly. The response in output_text is a valid JSON string you can parse directly.
The schema format follows JSON Schema with a few constraints specific to the Perplexity API:
- No recursive schemas. The schema cannot reference itself.
- No unconstrained objects. Avoid
additionalProperties: trueor bareobjecttypes without defined properties. - Named schemas required. Each schema needs a
namefield for identification.
Basic: Extracting a Single Entity
Extract structured data about a single topic with web search grounding.Extracting Lists: Product Comparisons
Extract a structured comparison of multiple items from a single query.Research Findings Extraction
Parse search-grounded research into a structured format suitable for reports or databases.Building a Data Pipeline
Chain structured output extraction into a pipeline that queries, extracts, and stores structured data.Schema Design Constraints
Patterns That Work
Patterns to Avoid
Combining Structured Output with Function Calling
You can useresponse_format alongside custom tools. The model calls your functions first, then formats the final response according to your schema.
Next Steps
Output Control
Full reference for response_format, streaming, and output shaping.
Function Calling
Combine structured outputs with multi-turn function calling.
Agent API Quickstart
Get started with the Agent API in minutes.
Models
Choose the right model for structured extraction tasks.