reverse-engineer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReverse 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 的Bearer令牌)
pplx.session-id - 请求体(包含字段名和类型的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., = shorter answers)
mode: "concise" - Discovered values (e.g., = "pplx-70b-chat" | "pplx-70b-deep")
model_preference
针对负载中的每个字段:
- 名称、类型、必填/可选、默认值
- 功能说明(例如:= 更简短的回答)
mode: "concise" - 已发现的取值(例如:= "pplx-70b-chat" | "pplx-70b-deep")
model_preference
Step 4: Map to SDK Architecture
步骤4:映射到SDK架构
| Discovery | Target | Action |
|---|---|---|
| New endpoint | | Add endpoint constant and method |
| Request fields | | Create Pydantic request model |
| Response fields | | Create Pydantic response model |
| SSE events | | Add event type to parser |
| Auth variation | | Add extraction method |
| Error codes | | Map to exception type |
| 研究成果 | 目标文件 | 操作 |
|---|---|---|
| 新接口 | | 添加接口常量和方法 |
| 请求字段 | | 创建Pydantic请求模型 |
| 响应字段 | | 创建Pydantic响应模型 |
| SSE事件 | | 为解析器添加事件类型 |
| 认证变体 | | 添加提取方法 |
| 错误码 | | 映射到异常类型 |
Step 5: Implement
步骤5:实现
Create the SDK implementation following the layered architecture:
- Model in
domain/models.py - Service in
domain/<service>.py - Tests in
tests/test_<service>.py
遵循分层架构创建SDK实现:
- 在中定义模型
domain/models.py - 在中编写服务逻辑
domain/<service>.py - 在中编写测试用例
tests/test_<service>.py
Known API Surface
已知API范围
Implemented
已实现
- — Main query endpoint (SSE streaming)
POST /rest/sse/perplexity.ask
- — 主要查询接口(SSE流式传输)
POST /rest/sse/perplexity.ask
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 headers matching Chrome/Safari
User-Agent - Include and
Referer: https://www.perplexity.ai/headersOrigin - 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使用进行TLS指纹模拟
impersonate="chrome120" - 限制请求速率以避免被检测到