Shape the output - Perplexity

· Source: perplexity.ai via Google News · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering, Cloud Computing & IT Infrastructure · Depth: Intermediate, short

Summary

Perplexity's API offers robust controls for managing output, addressing common needs beyond a single text block. Developers can enable streaming by setting "stream: true", receiving incremental Server-Sent Events with distinct types like "response.output_text.delta" for text chunks and "response.completed" for final usage data. For long-running tasks, "background: true" allows server-side execution and polling, supporting durable streams that can be reconnected using "GET /v1/responses/{id}?stream=true&starting_after=N". Response length is managed via "max_output_tokens" for a hard token cap and "text.verbosity" (low, medium, high) for soft preferences. Crucially, structured JSON output can be enforced using "response_format" with a defined "json_schema", ensuring machine-readable results and improving downstream system integration.

Key takeaway

For AI Engineers integrating the Perplexity API, understanding output control is crucial for optimizing application performance and user experience. You should implement streaming for interactive interfaces or long answers, and utilize background runs for computationally intensive tasks to maintain client responsiveness. Use structured JSON output with a defined schema to ensure seamless integration with downstream systems, avoiding brittle parsing and improving data reliability.

Key insights

Perplexity API offers granular control over response delivery and format, including streaming, background processing, and structured JSON.

Principles

Method

To control Perplexity API output, set "stream: true" for incremental events, "background: true" for server-side processing, or define "response_format" with a "json_schema" object. Manage length with "max_output_tokens" or "text.verbosity".

In practice

Topics

Best for: AI Engineer, Machine Learning Engineer, Software Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by perplexity.ai via Google News.