Skip to content

A simple command-line tool for querying the Perplexity API from your terminal

Notifications You must be signed in to change notification settings

Dodothereal/perplexity-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Perplexity CLI

A beautiful, feature-rich command-line interface for the Perplexity AI API with interactive arrow navigation โ€” Cross-platform (Linux, macOS, Windows)

Python License CLI Platforms

Demo

โœจ Features

  • Beautiful Terminal UI - ASCII art "PERPLEXITY CLI" banner, colored output, status bars, and formatted messages
  • Arrow Navigation Menus - Interactive settings and model selection with โ†‘โ†“ keys
  • Interactive Chat Mode - Full REPL with slash commands and conversation history
  • Markdown Formatting - Supports bold, italic, code blocks, headers, and lists
  • Rich Text Output - Syntax highlighting, colored code blocks, and styled links
  • Real-time Streaming - Watch answers generate with proper word wrapping
  • Conversation Persistence - Save/load chats and export to Markdown
  • Custom System Prompts - Create custom AI personas
  • Citations Support - View source citations for research answers
  • Secure API Keys - .env file support for secure API key management

๐Ÿš€ Quick Start

Linux / macOS

# Install dependencies
pip install openai python-dotenv

# Copy the script
cp perplexity ~/.local/bin/perplexity
chmod +x ~/.local/bin/perplexity

# Add to PATH (if not already)
export PATH="$HOME/.local/bin:$PATH"

# Start chatting!
perplexity --chat

Windows (PowerShell)

# Install dependencies
pip install openai python-dotenv

# Copy the script to a folder in your PATH
# Common locations:
#   C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python3xx\Scripts\
#   C:\Users\%USERNAME%\AppData\Local\Microsoft\WindowsApps\
Copy-Item perplexity $env:USERPROFILE\perplexity.py

# Create an alias (add to your PowerShell profile)
# Run `notepad $PROFILE` and add:
#   function perplexity { python $env:USERPROFILE\perplexity.py @args }

# Start chatting!
perplexity --chat

Windows (Command Prompt)

REM Install dependencies
pip install openai python-dotenv

REM Copy to a folder in PATH, e.g.:
COPY perplexity C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python3xx\Scripts\perplexity.py

REM Create batch wrapper (one-time):
echo @python "%USERPROFILE%\perplexity.py" %* > C:\Windows\perplexity.bat

REM Start chatting!
perplexity --chat

โš™๏ธ Setup

API Key

Get your API key from perplexity.ai/settings/api

Option 1: Environment Variable

export PERPLEXITY_API_KEY="your-api-key-here"

Option 2: .env File (Recommended)

Linux / macOS:

mkdir -p ~/.perplexity
cat > ~/.perplexity/.env << 'EOF'
PERPLEXITY_API_KEY=your-api-key-here
EOF

Windows (PowerShell):

New-Item -Path "$env:USERPROFILE\.perplexity" -ItemType Directory -Force
Set-Content -Path "$env:USERPROFILE\.perplexity\.env" -Value "PERPLEXITY_API_KEY=your-api-key-here"

Windows (Command Prompt):

mkdir "%USERPROFILE%\.perplexity"
echo PERPLEXITY_API_KEY=your-api-key-here > "%USERPROFILE%\.perplexity\.env"

๐Ÿ“– Usage

Interactive Chat

perplexity --chat      # or -c
perplexity --chat --stream
perplexity --chat --model sonar-medium-online
perplexity --chat --system "You are a sarcastic comedian"

Single Query

perplexity "What is the capital of France?"
perplexity "Explain quantum physics" --stream
perplexity "Latest AI news" --search
perplexity "Debug this code" --system "You are a Python expert"

๐ŸŽฎ Interactive Commands

Command Description
/menu โญ Open interactive settings menu (arrow keys)
/model Switch AI model with arrow selection
/help Show interactive help box
/clear Clear conversation history
/save Save current conversation
/export Export conversation to Markdown
/history List all saved conversations
/load Load a saved conversation
/status Show current session info
/quit Exit chat mode
/exit Exit chat mode
/q Exit chat mode

Keyboard Shortcuts:

  • Ctrl+C - Interrupt current response
  • Ctrl+D - Exit chat mode
  • โ†‘โ†“ - Navigate menus
  • ENTER - Select menu item
  • ESC - Cancel/close menu

๐Ÿ”ง Options

Option Short Description Default
query - Your question or search query -
--chat -c Enter interactive chat mode -
--model - Model to use sonar-pro
--search - Use research-focused mode -
--stream - Stream responses in real-time -
--system -s Custom system prompt -
--api-key - Override API key -
--no-color - Disable colored output -

๐Ÿค– Available Models

Model Best For Speed
sonar-pro General queries with web citations โญโญ
sonar-medium-online Faster responses โญโญโญ
sonar-small-online Quick answers โญโญโญโญ

๐Ÿ’ก Examples

Quick Question

$ perplexity "What is the capital of Australia?"

โ”Œโ”€ Perplexity โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ Canberra, located in the Australian Capital Territory.
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Research with Citations

$ perplexity "Latest developments in AI agents" --search

โ”Œโ”€ Perplexity โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ AI agents are evolving rapidly with new capabilities...

๐Ÿ“š Sources
  [1] https://perplexity.ai/blog/ai-agents
  [2] https://openai.com/research/agents
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Custom Persona

$ perplexity -s "You are a sarcastic pirate captain" "Tell me a joke"

โ”Œโ”€ Perplexity โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ Arrr, why did the pirate go to medical school?
โ”‚ Because he wanted to study "arrr-thritis", ye scallywag!
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

๐Ÿ’พ Conversation History

Conversations are saved automatically to ~/.cache/perplexity/ as JSON files.

Managing Conversations

# List saved conversations
You: /history

๐Ÿ“‚ Saved Conversations
  โ€ข chat_20240203_153045.json (5 msgs) - 2024-02-03T15:30:45
  โ€ข chat_20240203_140000.json (12 msgs) - 2024-02-03T14:00:00

# Load a conversation
You: /load

[1] chat_20240203_153045.json (5 msgs)
[2] chat_20240203_140000.json (12 msgs)

Load which one? (number or 'cancel'): 1
โœ“ Loaded 5 messages.

# Export to Markdown
You: /export
Output filename (e.g. chat.md): my_research.md
โœ“ Exported to: my_research.md

๐ŸŽจ Terminal Interface

Welcome Screen (v2.0)

   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
  โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•
  โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
  โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘
  โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘
   โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•
                  CLI v2.0

โ”โ”โ”  Model: SONAR PRO                    2024-02-03 03:30 PM  โ”โ”โ”

  MENU OPTIONS:
  Type '/menu' to open settings
  Type '/help' for all commands

Quick Commands:
  /menu        Open settings menu (arrow navigation)
  /model       Switch AI model
  /clear       Clear conversation
  /save        Save conversation
  /export      Export to Markdown
  /history     List saved chats
  /load        Load saved chat
  /quit        Exit

Interactive Settings Menu

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                        PERPLEXITY CLI โ€ข SETTINGS                  โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ–บ ๐Ÿค– Change Model
  ๐Ÿ”ง API Settings
  ๐Ÿ’พ Conversation History
  ๐Ÿ“ค Export Conversation
  โ„น๏ธ  About
  โ† Back to Chat

  โ†‘โ†“ Navigate โ€ข ENTER Select โ€ข ESC Cancel

Model Selection

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                       PERPLEXITY CLI โ€ข SELECT MODEL                โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ— Sonar Pro (Best)       โ”€โ”€ Recommended for complex queries
  โ—‹ Sonar Medium           โ”€โ”€ Faster responses
  โ† Cancel

  โ†‘โ†“ Navigate โ€ข ENTER Select โ€ข ESC Cancel

Styled Messages

โ”Œโ”€ You โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ What is quantum computing?
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

โ”Œโ”€ Perplexity โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ Quantum computing is a revolutionary field that uses
โ”‚ quantum mechanics to process information in ways
โ”‚ classical computers cannot...
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

๐Ÿ“š Sources
  [1] https://example.com/quantum-intro
  [2] https://example.com/qubits-explained

๐Ÿ“ File Locations

File/Folder Linux/macOS Windows Purpose
.env ~/.perplexity/.env %USERPROFILE%\.perplexity\.env API key configuration
Conversations ~/.cache/perplexity/ %USERPROFILE%\.cache\perplexity\ Saved chat history
Script ~/.local/bin/perplexity %USERPROFILE%\perplexity.py CLI executable

๐Ÿ’ฌ Tips & Tricks

  • Custom Personas: Use --system to create different AI personalities

    • "You are a sarcastic comedian"
    • "You are a senior code reviewer"
    • "You explain things like I'm 5"
  • Faster Responses: Use sonar-small-online for quick answers

  • Interrupting: Press Ctrl+C to interrupt long responses

  • Research: Use --search for complex topics requiring citations

  • Documentation: Export chats to Markdown for documentation

๐Ÿ› Troubleshooting

API Key Not Found

Error: API key not found. Set PERPLEXITY_API_KEY or create ~/.perplexity/.env

Solution: Create an .env file or set the environment variable.

Module Not Found

ModuleNotFoundError: No module named 'openai'

Solution: Install dependencies with pip install openai python-dotenv

Colors Not Showing

Linux/macOS: Colors are automatically disabled when piping to a file or using --no-color.

Windows: If colors aren't showing:

  • Use Windows Terminal or PowerShell 7+ (supports ANSI colors)
  • For older Command Prompt, colors may not work - use perplexity --no-color
  • Use PowerShell 5.1+: Install Windows Terminal for best experience

๐Ÿ“„ License

MIT License - see LICENSE for details.

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • Open an issue for bugs or feature requests
  • Submit a pull request with improvements
  • Share your creative prompt ideas

๐Ÿ™ Credits


Made with โ™ฅ by Dodothereal

About

A simple command-line tool for querying the Perplexity API from your terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages