Skip to main content

llm-perplexity

PyPI Changelog License

LLM plugin for Perplexity's Agent API

Installation

Install this plugin in the same environment as LLM.

llm install llm-perplexity

Usage

First, set an API key for Perplexity AI:

llm keys set perplexity
# Paste key here

Run llm models to list the models, and llm models --options to include a list of their options.

Available Models

Perplexity's Sonar chat completions API will be supported until September 27, 2026. This plugin sends prompts through Perplexity's Agent API instead. The four Sonar model ids are still here, and each one selects an Agent API preset:

  • sonar selects the fast preset
  • sonar-pro selects the low preset
  • sonar-reasoning-pro selects the medium preset
  • sonar-deep-research selects the high preset

Perplexity chooses the model behind each preset and can change it. Check the model field in the logged response JSON (llm logs --json) to see which model actually answered.

Run prompts like this:

# Flagship model
llm -m sonar-pro 'Latest AI research'

# Base model
llm -m sonar 'Fun facts about walruses'

# Research and reasoning models
llm -m sonar-deep-research 'Complex research question'
llm -m sonar-reasoning-pro 'Problem solving task'

Advanced Options

The plugin supports these parameters to customize model behavior. Some underlying models ignore temperature and top_p. Setting both is an error.

# Control randomness (0.0 up to but not including 2.0, higher = more random)
llm -m sonar-pro --option temperature 0.7 'Generate creative ideas'

# Nucleus sampling threshold (alternative to temperature)
llm -m sonar-pro --option top_p 0.9 'Generate varied responses'

# Limit response length
llm -m sonar-pro --option max_tokens 500 'Summarize this article'

# Suppress citations section and discourage inline [n] markers
llm -m sonar-pro --option include_citations false 'Latest AI research'

# Filter search results by domain
llm -m sonar-pro --option search_domain_filter 'arxiv.org,nature.com' 'Recent AI papers'

# Exclude a domain from search results
llm -m sonar-pro --option search_domain_filter '-example.org' 'Recent AI papers'

# Filter search results by recency (hour, day, week, month, year)
llm -m sonar-pro --option search_recency_filter year 'Major events'

# Control reasoning effort (minimal, low, medium, high)
llm -m sonar-reasoning-pro --option reasoning_effort high 'Solve this complex math problem'

# Control how much search context the model retrieves (low, medium, high)
llm -m sonar-pro --option search_context_size low 'Latest AI research'

Using Images with Perplexity

The plugin supports sending images to Perplexity models for analysis (multi-modal input):

# Analyze an image with Perplexity
llm -m sonar-pro --option image_path /path/to/your/image.jpg 'What can you tell me about this image?'

# Ask specific questions about an image
llm -m sonar-pro --option image_path /path/to/screenshot.png 'What text appears in this screenshot?'

# Multi-modal conversation with an image
llm -m sonar-pro --option image_path /path/to/diagram.png 'Explain the process shown in this diagram'

image_path sends the image as an input_image part alongside the prompt text. llm's own -a attachment flag is not supported yet. In a conversation, the plugin sends only the current turn's image and does not re-send images from earlier turns.

Note: Only certain Perplexity models support image inputs. The plugin forwards any image/* file; PNG, JPEG, and GIF are what Perplexity's models accept, not a plugin restriction.

Changes in 2026.9.0

This release moved the plugin from Perplexity's Sonar chat completions API to the Agent API. The Agent API does not support 13 chat completions options. Passing any of them is now an error:

  • top_k
  • stream
  • presence_penalty
  • frequency_penalty
  • search_type
  • search_mode
  • disable_search
  • search_language_filter
  • return_images
  • return_related_questions
  • language_preference
  • stop
  • use_openrouter

Anyone using use_openrouter to route through OpenRouter should install the llm-openrouter plugin instead.

Conversations logged before this upgrade still work with llm -c. A default saved with llm models options set, or an alias or template, that carries one of the options above now fails; check with llm models options show <model> and clear it.

--key now works. Earlier the plugin silently ignored it.

The logged response JSON (llm logs --json) now has the Agent API shape. Sources sit under an output item of type search_results, each with title, url, date, last_updated, and snippet. The old top-level citations, search_results, and choices keys are gone.

A response Perplexity reports as failed now raises an error instead of returning empty text. The plugin sends max_tokens to the API as max_output_tokens; in testing, a response cut short by it still reported status completed.

This release also raises the minimum versions to llm>=0.26, openai>=1.109.1, and Python >=3.10.

Development

Clone the repository and run the tests:

git clone https://github.com/hex/llm-perplexity.git
cd llm-perplexity
uv run pytest

The suite runs offline against recorded cassettes and needs no API key.

To re-record a cassette against the live API, delete it under tests/cassettes/ and run:

LLM_PERPLEXITY_KEY=your_perplexity_api_key uv run pytest --record-mode=once

This plugin was made after the llm-claude-3 plugin by Simon Willison.

Metadata

Release files for llm-perplexity 2026.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-perplexity 2026.9.0
File Size Uploaded
llm_perplexity-2026.9.0.tar.gz 33.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-perplexity 2026.9.0
File Interpreter ABI Platform
llm_perplexity-2026.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.8 kB

Release files / llm_perplexity-2026.9.0.tar.gz

Download URL llm_perplexity-2026.9.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc9ab7d9188182dc1ee81ed35aeccf45be5f8af83a66d35171061b33388e5a1e
BLAKE2b-256 checksum
How to use checksums
b95866916012b3b8a4d61f623754004c718b5864f5be4a4798cef0aa28ffb459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / llm_perplexity-2026.9.0-py3-none-any.whl

Download URL llm_perplexity-2026.9.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6f7c391a152652f1c56d7ffc8943a8183c075e82e18bbb85b1f48f92098b6b9
BLAKE2b-256 checksum
How to use checksums
ef9147e583c469a5f6d6b1ee3416ff036fd67b407d9064b72b6e27bc84f43c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page