Skip to content
AnswerWell geo Documentation

Research · 11 min read · Answerwell

Hosted LLM APIs: Agent Responses, Chat Completions, Reasoning, and Tools

How Perplexity Agent, Orchestrator, and Sonar APIs differ from Cloudflare Workers AI chat completions—and how to set tools, reasoning, streaming, and batch jobs.

This page summarizes Perplexity documentation on the Agent API, Orchestrator gateway, legacy Sonar, and Decisions API, together with Cloudflare Workers AI model parameter references. Both ecosystems expose OpenAI-shaped chat or response objects, but paths, state handling, built-in search, and reasoning knobs differ. The goal is to pick the right surface, send a valid body, and read output[] or choices[] without surprise 400 responses.

Agent API vs chat completions: which API to call

Section titled “Agent API vs chat completions: which API to call”

The Perplexity Agent API runs a multi-step loop with built-in tools (web_search, finance_search, MCP, sandbox, skills) and returns a response object with heterogeneous output[] items. Orchestrator routes third-party catalog models through OpenAI Chat Completions, Anthropic Messages, or a stateless OpenAI Responses schema. Legacy Sonar is a dedicated search-augmented chat completion family. Decisions API scores text against named questions—it does not run an agent loop.

Dimension Agent API (/v1/agent, /v1/responses) Orchestrator Responses (/orchestrator/v1/responses) Decisions API Legacy Sonar
Primary output Multi-step agent + tools + messages Model response (object: "response") Probabilities per named question Async or sync chat completion
Finance data finance_search tool Not in Agent tool set on this path N/A search_mode: "sec" (search context)
Batch JSONL via /v1/batches Not covered in cluster Not in cluster Not in cluster
Conversation state previous_response_id, background poll Stateless—resend full input Single state + questions Messages in request

url Must be /v1/responses. This is the same Agent API endpoint as /v1/agent.

— Perplexity, Batch API

Use the Agent API when you need tool loops, USD cost breakdown per tool, or batch JSONL at scale. Use Orchestrator chat or messages when you already integrate the OpenAI or Anthropic SDK against a catalog model. Use Answer questions (Decisions) for structured yes/no, multiple-choice, or score questions on fixed text. Use legacy Sonar when you want citations and web_search_options on Sonar models without the Agent tool loop.

SDK entry points for the Agent API include client.responses.create(...) in Python and JavaScript, with HTTP POST to https://api.perplexity.ai/v1/agent (equivalent to /v1/responses). See the Agent API quickstart and Create Agent Response.

Create Agent Response: model, effort, max_steps, and tools

Section titled “Create Agent Response: model, effort, max_steps, and tools”

A Create Agent Response body uses ResponsesRequest JSON. You must supply input (string or typed item array) and either model (provider/model), a fallback chain models[] (1–5 entries, takes precedence over model), or effort (pre-configured model, system prompt, and search). profile holds a saved configuration and cannot be combined with effort.

max_steps ranges from 1–500, overrides effort defaults, and defaults to 1 for a bare model without effort. For finance_search with a direct model, set max_steps to at least 3:

Set max_steps to at least 3 when using finance_search with a direct model so the agent has enough steps to initialize and run the tool.

— Perplexity, Create Agent Response

Retrieve structured financial and market data using the finance_search tool. Direct-model requests should set max_steps to at least 3 so the tool has enough steps to initialize and run. See the Finance Search guide for capabilities and recommended configurations.

— Perplexity, Agent API quickstart

Anthropic models (anthropic/*) require max_output_tokens; otherwise the API returns HTTP 400 with a validation message stating that max_output_tokens is required.

type Notable limits
web_search max_results 1–50; domain filters max 20; search_type web | fast — fast billed $1.00 / 1,000 invocations plus model tokens
image_search max_results default 5, max 30
people_search max_tokens up to 120000
fetch_url max_urls 1–10 per call
mcp HTTPS Streamable HTTP only (not legacy SSE); server_label pattern ^[a-zA-Z0-9_-]{1,64}$
sandbox Isolated code execution
connector Project-scoped MCP connector

Skills: at most 16; selecting any skill enables sandbox. Builtin skills include office, office/docx, office/pdf, office/pptx, office/xlsx.

Document inputs: input_file up to 30 parts and 50 MiB combined; browser tools are unavailable with document inputs or continuations.

Set tools_disabled: true to run without tools when using an effort level—an empty tools: [] does not clear effort defaults:

To run without tools, set tools_disabled: true on the request. Passing tools: [] does not clear effort level tools. An empty array is treated the same as omitting the field, and the effort level’s defaults still apply.

— Perplexity, Prompt Guide

For geographic or domain constraints on Agent web_search, prefer tool parameters over prose:

For source, date, or region constraints, prefer the web_search parameters over describing the constraint in prose. Parameters are applied by the search backend on every call, while prose-based filters are interpreted by the model and may not carry through every turn of the loop.

— Perplexity, Prompt Guide

Agent API streaming, background mode, and multi-turn

Section titled “Agent API streaming, background mode, and multi-turn”

stream: true yields SSE text/event-stream (lifecycle events such as response.created, response.output_text.delta, response.completed). background: true returns immediately with status: "queued"; poll GET /v1/responses/{id} until a terminal status.

Run the response asynchronously. With stream: false, the request returns immediately with status: "queued"; poll GET /v1/responses/{id} until the response reaches a terminal status.

— Perplexity, Create Agent Response

previous_response_id chains turns when the prior response is completed, same account, and not failed or in progress. Invalid IDs yield HTTP 400. store: false hides responses from list/retrieve but still allows continuation sources.

MCP approval: an mcp_approval_request output item means the call did not run; send mcp_approval_response on the next request before approved MCP calls execute.

Non-streaming responses use object: "response" with output[] item types including message, search_results, finance_results, function_call, sandbox_results, mcp_call, and others. Finance tool runs emit:

Intermediate output item emitted when the finance_search tool runs. One item is emitted per tool invocation; the requested categories and tickers are echoed at the envelope level alongside the per-result entries.

— Perplexity, Create Agent Response

Retrieve Agent Response returns a JSON snapshot when stream was false on create. HTTP 404 applies when the id is unknown, belongs to another account, or the response was created with store: false. usage.cost lists USD fields including tool_calls_cost and per-tool details.

When the request used effort, the stored response may echo effort as name@<version> so you can replay that configuration.

Orchestrator gateway: Chat Completions, Messages, and Responses

Section titled “Orchestrator gateway: Chat Completions, Messages, and Responses”

Chat Completions (/orchestrator/v1/chat/completions)

Section titled “Chat Completions (/orchestrator/v1/chat/completions)”

Send a conversation to any Orchestrator API model using the OpenAI Chat Completions schema. Set stream: true to receive server-sent events; add stream_options: {"include_usage": true} to get token usage in the final chunk.

— Perplexity, Create Chat Completion

Rejected with 400 on this path include web_search_options (use legacy Sonar for rich search knobs), deprecated functions / function_call, and unsupported fields such as seed. Function tools require a description. response_format.json_schema always runs in strict mode. Replay assistant reasoning_content in follow-up messages to preserve reasoning context.

Invalid model ids return HTTP 400 with a pointer to the models documentation.

Authenticate with your Perplexity API key. Both Authorization: Bearer and the Anthropic SDK’s default x-api-key header are accepted, so the stock SDK api_key parameter works unchanged. No anthropic-version header is required.

— Perplexity, Create Message

Only thinking: {"type": "disabled"} is honored; enabled returns 400. cache_control on blocks or tools is rejected despite appearing in schema examples. The Orchestrator path does not emit citations on documents.

Generate a model response using the OpenAI Responses schema. Set stream: true to receive typed server-sent events followed by data: [DONE].

— Perplexity, Create Response

The Orchestrator API accepts the OpenAI Responses schema with a defined subset of parameters. This endpoint is stateless: send the full conversation in input on each request.

— Perplexity, Create Response

Rejected with 400 include non-null previous_response_id, store: true, background: true, truncation: "auto" (only truncation: "disabled" is honored), tool_choice with allowed_tools, text.format json_object, text.format.strict: false, and file or video input. For models like gpt-5.3-codex, preserve and resend assistant phase (commentary | final_answer) on follow-ups.

Streaming ends with data: [DONE] on success; after a mid-stream error, the stream emits an error event and response.failed without [DONE].

Decisions API: structured questions on text

Section titled “Decisions API: structured questions on text”

Decisions POST evaluates state against 1–128 named questions. Models include pplx-decider-v1.2 and pplx-decider-flash-v1.2 (with *-latest aliases). Body must stay under 32 MiB; state plus any one question must stay under 256K input tokens.

The state plus any one question must stay under 256K input tokens; on pplx-decider-v1.2, questions that do not fit together are answered in groups, and each group counts the state again. pplx-decider-flash-v1.2 answers each question separately and counts the state again for every question.

— Perplexity, Answer questions

Question types: noul (probability 0–1; needs instructions and/or criteria), choice (1–255 options), score (ordered criteria levels). For noul, values near 0.5 mean the model is unsure. Authenticate with Authorization: Bearer; sending the key only as x-api-key yields 401.

Use Decisions when you need calibrated probabilities on fixed content. Use the Agent API when the model must search, call tools, or produce a long synthesized answer.

Legacy Sonar chat completion supports search_mode web | academic | sec, rich web_search_options, and response fields citations, search_results, and usage.cost in USD.

Search Filters document web_search_options.user_location with country (ISO 3166), optional region and city, and latitude / longitude for precision:

For best accuracy, provide as many location fields as possible. City and region significantly improve location precision.

— Perplexity, Search Filters

Async Sonar wraps a chat request; poll until status is COMPLETED before reading nested response (Get Async Chat Completion). Sonar is not the Agent tool loop on /v1/responses.

Cloudflare Workers AI: chat completion parameters

Section titled “Cloudflare Workers AI: chat completion parameters”

Cloudflare model pages (qwen3.8-27b, glm-5.3-flash, kimi-k2.6, gpt-oss-120b) document the same OpenAI-style completion schema with two input shapes:

  • prompt: single-turn string (required, minLength: 1).
  • messages: multi-turn array with roles developer, system, user, assistant, tool, and function.

Synchronous — Send a request and receive a complete response

— Cloudflare, qwen3.8-27b

Streaming — Send a request with stream: true and receive server-sent events

— Cloudflare, qwen3.8-27b

Batch — Send multiple requests in a single API call

— Cloudflare, qwen3.8-27b

Streaming uses contentType text/event-stream. Batch sends requests[] where each element mirrors a full single request (prompt- or messages-based).

Prefer max_completion_tokens over deprecated max_tokens on OpenAI-compatible Cloudflare models:

Deprecated in favor of max_completion_tokens.

— Cloudflare, glm-5.3-flash

Reasoning behavior is model-specific:

Model reasoning_effort Disable reasoning?
GLM 5.2 max, high, none none or alias minimal→none
GLM 5.3 max, high, low No—aliases like none map to max
GLM 5.3 Flash max, high, low enable_thinking enum only true
Kimi K2.6 high, none none supported
Kimi K2.7 Code — Reasoning always on
Qwen3.8-27b low, medium, xhigh Via enable_thinking

Reasoning is always enabled for this model and cannot be disabled.

— Cloudflare, glm-5.3-flash

chat_template_kwargs.clear_thinking: false preserves reasoning context between turns. Inspect usage.completion_tokens_details.reasoning_tokens in responses.

gpt-oss models (gpt-oss-120b) use a simpler schema: max_tokens (default 256), optional lora and raw (skip chat template), top_k, and batch items with Responses-style input plus reasoning.effort—not the full GLM/Kimi tool surface.

Tools, JSON output, and web search on Workers AI

Section titled “Tools, JSON output, and web search on Workers AI”

Controls which (if any) tool is called by the model. ‘none’ = no tools, ‘auto’ = model decides, ‘required’ = must call a tool.

— Cloudflare, qwen3.8-27b

parallel_tool_calls defaults to true. response_format supports text, json_object, and json_schema. Audio output requires modalities including 'audio' and an audio object.

Built-in web search uses web_search_options.search_context_size (low | medium | high, default medium) and user_location.type: approximate (city, country, region, timezone)—not Sonar’s latitude/longitude fields.

Assistant messages may include annotations with url_citation (url, title, start/end index), similar in purpose to Sonar citations but on the chat completion shape.

Perplexity Agent batch processing (Batch API) follows five steps: author JSONL, upload with POST /v1/files (purpose=batch), create batch with POST /v1/batches (endpoint required as /v1/responses), poll GET /v1/batches/{batch_id}, download output and error files.

Each JSONL line needs unique custom_id, method: "POST", url: "/v1/responses", and the same model in every body. Invalid lines on upload return 400 with the first bad line number and nothing stored. Poll every 30–60s; tier 0 batch/file endpoints are 1 req/s—faster polling yields 429.

A successful upload checks the file format. A request can still fail when it runs, for example if the model id does not exist. Those requests go to the error file.

— Perplexity, Batch API

usage sums the token usage of the requests in the output file only, so it is not your full bill.

— Perplexity, Batch API

Terminal batch statuses: completed, expired, cancelled, failed. A completed batch can still have per-line failures in the error file.

  1. max_steps: 1 with finance_search and a direct model (use ≥ 3).
  2. Omitting max_output_tokens for anthropic/* on the Agent API.
  3. Sending web_search_options to Orchestrator Chat Completions instead of Sonar.
  4. Expecting previous_response_id or store: true on Orchestrator Responses (stateless—400).
  5. Batch JSONL with different model per line, or polling batches faster than 1 req/s.
  6. tools: [] on Agent requests with effort (use tools_disabled: true).
  7. noul Decisions questions without instructions or criteria.
  8. MCP over legacy SSE transport (Streamable HTTP only).
  9. enable_thinking: false on models where the schema allows only true (e.g. GLM 5.3 Flash, Kimi K2.7 Code).
  10. Requesting audio on Workers AI without modalities and the audio object.
  1. Run one Agent request with a finance_search tool in tools and max_steps: 3; confirm finance_results or related items in output[] per Create Agent Response.
  2. POST a minimal Orchestrator Response with string input; retry with store: true and confirm HTTP 400, then stream with stream: true and confirm typed events ending in data: [DONE].
  3. Upload a two-line batch JSONL via Batch API; poll to a terminal status and match custom_id in output and error files.
  4. Call Decisions with one noul question and inspect probability and x-request-id response headers.
  5. Invoke a Cloudflare catalog model with stream: true and verify text/event-stream plus usage.completion_tokens_details.reasoning_tokens when reasoning params are set (qwen3.8-27b or glm-5.3).

You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page disagrees with the linked provider docs, email yimasynthetic@gmail.com with the page URL and the exact statement you believe is wrong so it can be corrected or clarified.