Skip to main content

LLM access to pplx-api 3 by Perplexity Labs

Project description

llm-perplexity

PyPI Changelog License

LLM access to pplx-api 3 by Perplexity Labs

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

All Perplexity models have access to real-time web information. Here are the currently available models (as of 2026-02) from https://docs.perplexity.ai/models/model-cards:

  • sonar-pro - Flagship model (200k context) - with web search
  • sonar - Base model (128k context) - with web search
  • sonar-deep-research - Deep research model (128k context) - with web search
  • sonar-reasoning-pro - Advanced reasoning model (128k context) - with web search

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 various parameters to customize model behavior:

# Control randomness (0.0 to 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'

# Token filtering (between 0 and 2048)
llm -m sonar-pro --option top_k 40 'Generate focused content'

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

# Return related questions
llm -m sonar-pro --option return_related_questions true 'How does quantum computing work?'

# Use Pro Search or auto classification (requires streaming)
llm -m sonar-pro --option search_type pro 'Analyze the latest developments in quantum computing'
llm -m sonar-pro --option search_type auto 'Compare the energy efficiency of popular EVs'

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

# Search mode: web (default), academic, or sec (SEC filings)
llm -m sonar-pro --option search_mode academic 'Recent papers on transformer architectures'
llm -m sonar-pro --option search_mode sec 'Apple quarterly earnings'

# Disable web search entirely
llm -m sonar-pro --option disable_search true 'What is the capital of France?'

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

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

# Filter search results by language
llm -m sonar-pro --option search_language_filter en 'Latest tech news'

# Penalize repetition (presence_penalty: -2.0 to 2.0)
llm -m sonar-pro --option presence_penalty 1.5 'Tell me about different dog breeds'

# Penalize frequent tokens (frequency_penalty: > 0, 1.0 = no penalty)
llm -m sonar-pro --option frequency_penalty 1.5 'Write a varied paragraph about nature'

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

# Include images in results
llm -m sonar-pro --option return_images true 'Show me the Eiffel Tower'

# Set output language preference
llm -m sonar-pro --option language_preference es 'Tell me about AI'

# Stop sequences
llm -m sonar-pro --option stop 'END' 'Generate a list'

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'

Note: Only certain Perplexity models support image inputs. Currently the following formats are supported: PNG, JPEG, and GIF.

OpenRouter Access

You can also access these models through OpenRouter. First install the OpenRouter plugin:

llm install llm-openrouter

Then set your OpenRouter API key:

llm keys set openrouter

Use the --option use_openrouter true flag to route requests through OpenRouter:

llm -m sonar-pro --option use_openrouter true 'Fun facts about pelicans'

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-perplexity
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

llm install -e '.[test]'

Running Tests

The test suite is comprehensive and tests all example commands from the documentation with actual API calls.

Before running tests, you need to set up your environment variables:

  1. Copy the .env.example file to .env:

    cp .env.example .env
    
  2. Edit the .env file and add your Perplexity API key:

    LLM_PERPLEXITY_KEY=your_perplexity_api_key_here
    
  3. (Optional) If you want to test OpenRouter integration, also add your OpenRouter API key:

    LLM_OPENROUTER_KEY=your_openrouter_api_key_here
    
  4. Install the package and test dependencies using one of these methods:

    Using the setup script:

    ./setup.sh
    

    Using make:

    make setup
    

    Manually:

    pip install -e .
    pip install pytest python-dotenv pillow
    

Run the tests with pytest:

# Run all tests
pytest test_llm_perplexity.py

# Using make
make test

# Run a specific test
pytest test_llm_perplexity.py::test_standard_models

Note: Running the full test suite will make real API calls to Perplexity, which may incur costs depending on your account plan.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_perplexity-2026.2.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_perplexity-2026.2.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file llm_perplexity-2026.2.1.tar.gz.

File metadata

  • Download URL: llm_perplexity-2026.2.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_perplexity-2026.2.1.tar.gz
Algorithm Hash digest
SHA256 f110f4602ea1d7157092016dc8dfba875c4a76442cbb66ed13690285b30843f4
MD5 503b98f5be30189a957bcc7a77dfe89d
BLAKE2b-256 e77b28ce36343168f53caf95283e4975e88ae91d4fbfca2331a0b6df7ac71546

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_perplexity-2026.2.1.tar.gz:

Publisher: publish.yml on hex/llm-perplexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_perplexity-2026.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_perplexity-2026.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4c003bc019e955e941afc1fb98c413691b5be00dc7d9743bff857aee8d01a5c
MD5 0d669cdf67c11e3d942165a091be2317
BLAKE2b-256 8aa04c6070f11ae4382c5dc739a00b87ea4e84c4b84862ceb7973a30c79e2a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_perplexity-2026.2.1-py3-none-any.whl:

Publisher: publish.yml on hex/llm-perplexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page