Skip to content

Rani367/pAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pAPI

A free, fast API for Perplexity AI. No API key needed — uses your logged-in Perplexity session.

Includes an MCP server so Claude Code (or any MCP client) can use Perplexity as a search tool.

How it works

Your app → pAPI → curl-impersonate (Chrome TLS) → Perplexity web UI → Answer

pAPI reverse-engineers Perplexity's internal /rest/sse/perplexity_ask endpoint. It uses curl-impersonate to bypass Cloudflare's TLS fingerprinting and your browser session cookies for authentication.

Quick start

1. Install

git clone https://github.com/Rani367/pAPI.git
cd pAPI
bun install

2. Get curl-impersonate

# macOS arm64
mkdir bin && curl -sL "https://github.com/lexiforest/curl-impersonate/releases/download/v1.5.1/curl-impersonate-v1.5.1.arm64-macos.tar.gz" | tar xz -C bin

# Linux x86_64
mkdir bin && curl -sL "https://github.com/lexiforest/curl-impersonate/releases/download/v1.5.1/curl-impersonate-v1.5.1.x86_64-linux-gnu.tar.gz" | tar xz -C bin

3. Get your Perplexity cookies

  1. Go to perplexity.ai and log in
  2. Open DevTools → Network tab
  3. Type a question and submit it
  4. Find the perplexity_ask request → right-click → Copy as cURL
  5. Extract the cookie string from the -b or --cookie flag

4. Configure

cp .env.example .env
# Paste your cookie string as PERPLEXITY_COOKIES

5. Run

bun run dev    # with hot reload
bun run start  # production

API

POST /ask

curl -X POST http://localhost:3000/ask \
  -H 'Content-Type: application/json' \
  -d '{"prompt": "What is quantum computing?"}'

Request body:

Field Type Default Description
prompt string required Your question
sources string[] ["web"] Search sources
citations boolean false Include source URLs

Response:

{
  "answer": "Quantum computing is...",
  "citations": ["https://..."]
}

POST /ask/stream

Same request body. Returns Server-Sent Events.

GET /health

Returns {"status": "ok"}.

Docker

docker build -t papi .
docker run -d -p 3000:3000 --env-file .env --name papi papi

MCP Server

An MCP server that exposes a perplexity_search tool. Works with any MCP client: Claude Code, Claude Desktop, Cursor, Windsurf, VS Code Copilot, etc.

Install via npx (no clone needed)

# Claude Code
claude mcp add -e PAPI_URL=https://your-papi-instance.com --scope user papi-search -- npx papi-mcp-server

# Claude Desktop / Cursor / other — add to your MCP config:
{
  "mcpServers": {
    "papi-search": {
      "command": "npx",
      "args": ["papi-mcp-server"],
      "env": {
        "PAPI_URL": "https://your-papi-instance.com"
      }
    }
  }
}

Environment variables

Variable Description
PAPI_URL Direct pAPI URL (e.g. https://my-papi.example.com)
PAPI_GIST_URL URL to a file containing the pAPI hostname (for dynamic tunnels)

Set one or the other.

Usage

Just ask your AI to search:

"Use perplexity_search to find the latest version of Bun"

Cookie refresh

The Cloudflare cookies (cf_clearance, __cf_bm) expire periodically. When requests start returning errors, grab fresh cookies from your browser and update .env.

License

MIT

About

Free Perplexity AI API + MCP server to replace agents' search tool with perplexity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors