R/api_perplexity.R
perplexity_chat.RdSends a chat message history to the Perplexity Chat API, supporting all documented API parameters as of July 2025.
perplexity_chat(
.llm,
.model = "sonar",
.max_tokens = 1024,
.temperature = NULL,
.top_p = NULL,
.frequency_penalty = NULL,
.presence_penalty = NULL,
.stop = NULL,
.search_domain_filter = NULL,
.return_images = FALSE,
.search_recency_filter = NULL,
.search_mode = "web",
.reasoning_effort = NULL,
.return_related_questions = FALSE,
.search_after_date_filter = NULL,
.search_before_date_filter = NULL,
.last_updated_after_filter = NULL,
.last_updated_before_filter = NULL,
.top_k = NULL,
.web_search_options = NULL,
.api_url = "https://api.perplexity.ai/",
.timeout = 60,
.stream = FALSE,
.verbose = FALSE,
.max_tries = 3,
.dry_run = FALSE
)An LLMMessage object containing the conversation history.
Model name to use (default: "sonar").
Max completion tokens (default: 1024).
Controls response randomness (0 < x < 2).
Nucleus sampling threshold (0 < x < 1).
Number > 0. Penalizes frequent tokens.
Numeric between -2 and 2. Penalizes present tokens.
Stop sequence(s), string or character vector/list.
Domains to allowlist/denylist for search (max 10, "-domain" for denylist).
Logical; if TRUE, returns images from search.
Restrict search to recent ("hour","day","week","month").
"web" (default) or "academic" (prioritize scholarly sources).
Reasoning level: "low", "medium" (default), "high" (for deep research models).
Logical; if TRUE, returns related questions.
Only content published after date (mm/dd/yyyy).
Only content published before date (mm/dd/yyyy).
Only content updated after date (mm/dd/yyyy).
Only content updated before date (mm/dd/yyyy).
Top-k token sampling (integer, 0 disables).
Named list with search config (e.g. list(search_context_size = "high")).
API endpoint (default: "https://api.perplexity.ai/").
Timeout in seconds (default: 60).
If TRUE, streams response.
If TRUE, prints additional info.
Max request retries (default: 3).
If TRUE, returns constructed request instead of sending.
An updated LLMMessage object with the assistant's reply and metadata, including citations and search_results.