Skip to main content
Logo

Perplexity WebUI Scraper

Python scraper to extract AI responses from Perplexity's web interface.

PyPI Python License

Documentation: henrique-coder.github.io/perplexity-webui-scraper

About

This unofficial library uses Perplexity's internal WebUI endpoints with a browser session token. It supports conversations, file uploads, streaming, an MCP server, and an OpenAI-compatible REST API.

A Perplexity account and its browser session token are required. Free accounts support text prompts; paid tiers are required for Pro/Max models and file uploads.

Community

Installation

Install the package depending on your use case:

This project is distributed as a Python package on PyPI and as optional container images on GHCR. GitHub Releases contain the Python wheel and source distribution; native standalone executables are not published.

Core library

Install the core Python library without optional features.

uv add perplexity-webui-scraper

All optional features

Install the cli, api, and mcp extras together.

uv add "perplexity-webui-scraper[all]"

CLI tools

Install with terminal UX dependencies to use the interactive chat and token CLI commands.

uv add "perplexity-webui-scraper[cli]"

Servers

Install dependencies required for the MCP Server or the OpenAI-compatible REST API.

# MCP Server for AI agents
uv add "perplexity-webui-scraper[mcp]"

# OpenAI-compatible API server
uv add "perplexity-webui-scraper[api]"

Quick Start

1. Get your session token

# Interactive email authentication
uv run perplexity-webui-scraper token

Or retrieve __Secure-next-auth.session-token manually from your browser cookies on perplexity.ai.

2. Basic usage

from perplexity_webui_scraper import Perplexity

client = Perplexity(session_token="YOUR_TOKEN")
conversation = client.create_conversation()

print(client.get_account_profile().account_tier)

conversation.ask("What is quantum computing?")
print(conversation.answer)

# Follow-ups preserve context automatically
conversation.ask("Explain it simpler")
print(conversation.answer)

Before each prompt, the library checks /api/auth/session and raises ModelAccessError if an available model requires a higher tier than the authenticated account. When the session payload does not expose enough subscription data, it falls back to /rest/user/settings. Models use one of three statuses: available (confirmed working normally), unknown (not yet verified, including custom identifiers), or unavailable (confirmed not working). is_official separately records whether a model is listed in Perplexity's official WebUI. last_tested_at records the last test in ISO 8601 UTC and is null for untested models. Any non-available status requires allow_risky_model=True; after acknowledgement, the backend makes the final entitlement decision. Free accounts can use text prompts, but file attachments raise FileAccessError.

perplexity/best adapts to the account tier: free accounts use Perplexity's internal turbo preference, while Pro/Max accounts use pplx_pro_upgraded; both use copilot mode.

3. Streaming

for chunk in conversation.ask("Explain AI", stream=True):
    if chunk.last_chunk:
        print(chunk.last_chunk, end="", flush=True)

4. Choose a model

from perplexity_webui_scraper import ConversationConfig

conversation = client.create_conversation(ConversationConfig(model="perplexity/best"))
conversation.ask("Solve this step by step: ...")
print(conversation.answer)

5. List registered models

from perplexity_webui_scraper import MODELS

for model in MODELS.list_all():
    print(f"{model.id:40} {model.name}")

Available CLI

Command Extra Description
perplexity-webui-scraper token cli Interactive email auth wizard to generate a session token (supports TOTP 2FA)
perplexity-webui-scraper chat cli Ask Perplexity AI questions with real-time streaming output
perplexity-webui-scraper chat setup cli Configure saved token and default model for the chat command
perplexity-webui-scraper mcp mcp Start the MCP server
perplexity-webui-scraper api api Start the OpenAI-compatible REST API server

OpenAI-Compatible API

Run a local server that accepts the supported OpenAI chat-completions fields and forwards requests to Perplexity. Each request passes the Perplexity session token through Authorization: Bearer.

# Start the server (no token needed at startup)
perplexity-webui-scraper api

# Custom host and port
perplexity-webui-scraper api --host 0.0.0.0 --port 8080

# Development mode with auto-reload
perplexity-webui-scraper api --reload

Running via Container (Podman)

# Pull the published multi-arch API image
podman pull ghcr.io/henrique-coder/perplexity-webui-scraper:latest

# Run the server (exposing port 8000)
podman run --rm -p 8000:8000 ghcr.io/henrique-coder/perplexity-webui-scraper:latest

Optional MCP image for containerized stdio setups:

# Pull the published multi-arch MCP image
podman pull ghcr.io/henrique-coder/perplexity-webui-scraper:mcp

# Run MCP server (requires token)
podman run --rm -e PERPLEXITY_SESSION_TOKEN=your_token ghcr.io/henrique-coder/perplexity-webui-scraper:mcp

For local development, you can still build the provided container files:

# API image: installs the `api` extra, exposes port 8000, and starts the REST server.
podman build -t perplexity-api -f Containerfile .
podman run --rm -it -p 8000:8000 perplexity-api

# MCP image: installs the `mcp` extra and starts the stdio MCP server. It does not expose an HTTP port.
podman build -t perplexity-mcp -f Containerfile.mcp .
podman run --rm -it -e PERPLEXITY_SESSION_TOKEN=your_token perplexity-mcp

CLI options

Option Short Default Description
--host -H 127.0.0.1 Bind address
--port -p 8000 Port to listen on
--reload False Enable auto-reload (dev)
--log-level info Uvicorn log level

Authentication

Pass your Perplexity session token as the API key in every request:

# curl
export PERPLEXITY_SESSION_TOKEN="your_session_token"
curl http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer $PERPLEXITY_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "perplexity/best", "messages": [{"role": "user", "content": "Hello!"}]}'

# Streaming
curl -N http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer $PERPLEXITY_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "perplexity/best", "messages": [{"role": "user", "content": "Hello!"}], "stream": true}'
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="YOUR_SESSION_TOKEN",  # sent as Authorization: Bearer automatically
)

response = client.chat.completions.create(
    model="perplexity/best",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

API endpoints

Method Path Description
GET /v1/models List registered models
POST /v1/chat/completions Chat completion (streaming + non-streaming)
GET /docs Interactive Swagger UI
GET /redoc ReDoc documentation

Fields not supported by Perplexity (e.g. temperature, top_p) are accepted for client compatibility but silently ignored.

MCP Server

Expose every Perplexity model as a separate tool for AI agents (Claude Desktop, Antigravity, etc.):

{
  "mcpServers": {
    "perplexity-webui-scraper": {
      "command": "uvx",
      "args": [
        "--from",
        "perplexity-webui-scraper[mcp]@latest",
        "perplexity-webui-scraper",
        "mcp"
      ],
      "env": { "PERPLEXITY_SESSION_TOKEN": "your_token_here" }
    }
  }
}

See the MCP documentation for tools and configuration.

Disclaimer

This is an unofficial library. It uses internal APIs that may change without notice. Use at your own risk. By using this library, you agree to Perplexity AI's Terms of Service.

Download files

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

Source Distribution

perplexity_webui_scraper-1.1.7.tar.gz (62.0 kB view details)

Uploaded Source

Built Distribution

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

perplexity_webui_scraper-1.1.7-py3-none-any.whl (84.9 kB view details)

Uploaded Python 3

File details

Details for the file perplexity_webui_scraper-1.1.7.tar.gz.

File metadata

  • Download URL: perplexity_webui_scraper-1.1.7.tar.gz
  • Upload date:
  • Size: 62.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for perplexity_webui_scraper-1.1.7.tar.gz
Algorithm Hash digest
SHA256 9c83fdf39d62cc2d9a5520b81b8300ca0dfa9a1f336e4ae6e4d9232f14da1a0e
MD5 b5841878ae1023169d3acbd3dd1785af
BLAKE2b-256 4bb137694a9c2c4b3bdbf2394dbfeed12b869d38d94b2e43d84dc3be7211efbd

See more details on using hashes here.

File details

Details for the file perplexity_webui_scraper-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: perplexity_webui_scraper-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 84.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for perplexity_webui_scraper-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee6dc03242abad840ab1a131c145559b3be266c1df509ff62a6f88b0b573873
MD5 f5f0d43da97d3d86ec916844e5b28c16
BLAKE2b-256 128a8f3fee43f031a5e0703844ca5227c611db00841f3224cd8251bbe171e11a

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.8

2 files

This release

1.1.7 This release

2 files

1.1.6

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

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