Streaming Responses
Streaming allows you to receive partial responses from the Perplexity API as they are generated, rather than waiting for the complete response. This is particularly useful for real-time user experiences, long responses, and interactive applications.Streaming is supported across all models available through the Agent API.
stream=True (Python) or stream: true (TypeScript) when creating responses:
Error Handling
Handle errors gracefully during streaming:Structured Outputs
Structured outputs enable you to enforce specific response formats from Perplexity’s models, ensuring consistent, machine-readable data that can be directly integrated into your applications without manual parsing. We currently support JSON Schema structured outputs. To enable structured outputs, add aresponse_format field to your request:
name field is required and must be 1-64 alphanumeric characters. The schema should be a valid JSON schema object. LLM responses will match the specified format unless the output exceeds max_tokens.
The first request with a new JSON Schema expects to incur delay on the first token. Typically, it takes 10 to 30 seconds to prepare the new schema, and may result in timeout errors. Once the schema has been prepared, the subsequent requests will not see such delay.
Example
Next Steps
Agent API Quickstart
Get started with the Agent API.
Models
Explore direct model selection and third-party models.