reverse-engineer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Reverse Engineering Perplexity AI APIs

逆向工程Perplexity AI APIs

Discover, document, and implement undocumented Perplexity AI endpoints for pplx-sdk.
发现、记录并为pplx-sdk实现未公开的Perplexity AI接口。

When to use

适用场景

Use this skill when:
  • Discovering new API endpoints from perplexity.ai browser traffic
  • Decoding request/response payloads from captured cURL commands
  • Mapping SSE event types from streaming endpoints
  • Extracting auth flows (cookies, tokens, session management)
  • Adding new endpoint support to the SDK
在以下场景使用本技能:
  • 从perplexity.ai浏览器流量中发现新的API接口
  • 解码捕获的cURL命令中的请求/响应负载
  • 映射流式接口的SSE事件类型
  • 提取认证流程(Cookie、令牌、会话管理)
  • 为SDK添加新接口支持

Instructions

操作步骤

Step 1: Capture Traffic

步骤1:捕获流量

DevTools (F12) → Network → XHR/Fetch
1. Perform action on perplexity.ai
2. Right-click request → Copy as cURL
3. Paste cURL for analysis
开发者工具(F12)→ 网络 → XHR/Fetch
1. 在perplexity.ai上执行操作
2. 右键点击请求 → 复制为cURL
3. 粘贴cURL进行分析

Step 2: Decode Payload

步骤2:解码负载

Extract from the captured request:
  • URL path (e.g.,
    /rest/sse/perplexity.ask
    )
  • Method (GET, POST, PUT, DELETE)
  • Auth (Bearer token from cookie
    pplx.session-id
    )
  • Request body (JSON payload with field names and types)
  • Response format (JSON, SSE stream, etc.)
从捕获的请求中提取:
  • URL路径(例如:
    /rest/sse/perplexity.ask
  • 请求方法(GET、POST、PUT、DELETE)
  • 认证信息(来自Cookie
    pplx.session-id
    的Bearer令牌)
  • 请求体(包含字段名和类型的JSON负载)
  • 响应格式(JSON、SSE流等)

Step 3: Document Schema

步骤3:记录Schema

For each field in the payload:
  • Name, type, required/optional, default value
  • What it controls (e.g.,
    mode: "concise"
    = shorter answers)
  • Discovered values (e.g.,
    model_preference
    = "pplx-70b-chat" | "pplx-70b-deep")
针对负载中的每个字段:
  • 名称、类型、必填/可选、默认值
  • 功能说明(例如:
    mode: "concise"
    = 更简短的回答)
  • 已发现的取值(例如:
    model_preference
    = "pplx-70b-chat" | "pplx-70b-deep")

Step 4: Map to SDK Architecture

步骤4:映射到SDK架构

DiscoveryTargetAction
New endpoint
transport/
Add endpoint constant and method
Request fields
domain/models.py
Create Pydantic request model
Response fields
domain/models.py
Create Pydantic response model
SSE events
transport/sse.py
Add event type to parser
Auth variation
shared/auth.py
Add extraction method
Error codes
core/exceptions.py
Map to exception type
研究成果目标文件操作
新接口
transport/
添加接口常量和方法
请求字段
domain/models.py
创建Pydantic请求模型
响应字段
domain/models.py
创建Pydantic响应模型
SSE事件
transport/sse.py
为解析器添加事件类型
认证变体
shared/auth.py
添加提取方法
错误码
core/exceptions.py
映射到异常类型

Step 5: Implement

步骤5:实现

Create the SDK implementation following the layered architecture:
  1. Model in
    domain/models.py
  2. Service in
    domain/<service>.py
  3. Tests in
    tests/test_<service>.py
遵循分层架构创建SDK实现:
  1. domain/models.py
    中定义模型
  2. domain/<service>.py
    中编写服务逻辑
  3. tests/test_<service>.py
    中编写测试用例

Known API Surface

已知API范围

Implemented

已实现

  • POST /rest/sse/perplexity.ask
    — Main query endpoint (SSE streaming)
  • POST /rest/sse/perplexity.ask
    — 主要查询接口(SSE流式传输)

Discovered (not yet implemented)

已发现(未实现)

  • Thread management (
    /rest/threads/
    )
  • Collections (
    /rest/collections/
    )
  • User profile (
    /rest/user/
    )
  • File upload (
    /rest/upload
    )
  • Sharing (
    /rest/share/
    )
  • 线程管理(
    /rest/threads/
  • 收藏集(
    /rest/collections/
  • 用户资料(
    /rest/user/
  • 文件上传(
    /rest/upload
  • 分享功能(
    /rest/share/

Anti-Detection Notes

反检测注意事项

  • Use realistic
    User-Agent
    headers matching Chrome/Safari
  • Include
    Referer: https://www.perplexity.ai/
    and
    Origin
    headers
  • Consider TLS fingerprinting via curl_cffi with
    impersonate="chrome120"
  • Rate limit requests to avoid detection
  • 使用符合Chrome/Safari的真实
    User-Agent
    请求头
  • 包含
    Referer: https://www.perplexity.ai/
    Origin
    请求头
  • 考虑通过curl_cffi使用
    impersonate="chrome120"
    进行TLS指纹模拟
  • 限制请求速率以避免被检测到