Skip to content

Unofficial TypeScript SDK for Perplexity AI - SSE Streaming, REST API, OAuth Connectors (Protocol 2.18)

Notifications You must be signed in to change notification settings

pv-udpv/pplx-unofficial-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Perplexity AI Research & Development Workspace

Enterprise-level workspace for Perplexity.ai API research, reverse engineering, and production-ready implementation

License: MIT TypeScript Python Protocol

🏒 Enterprise Workspace Overview

This repository contains a comprehensive enterprise-level monorepo combining:

  • πŸ”΅ TypeScript SDK - Client library for Perplexity AI (original functionality preserved)
  • 🐍 Python Backend Services - Microservices architecture with FastAPI
  • πŸ“Š Schema-Driven Development - OpenAPI specifications as source of truth
  • πŸ—οΈ Production Infrastructure - Docker, Kubernetes, CI/CD pipelines
  • πŸ”¬ Research Tools - Traffic analysis, reverse engineering, code generation

Quick Links


πŸš€ Quick Start (Enterprise Workspace)

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • Git

One-Command Setup

make setup

This will:

  • Create Python virtual environment
  • Install Python dependencies (FastAPI, Ruff, mypy)
  • Install Node.js dependencies
  • Set up pre-commit hooks
  • Create runtime directories
  • Generate .env template

Start Development Environment

make dev

Services will start on:

Common Commands

make lint      # Run all linters (ruff, mypy, eslint)
make format    # Format all code
make test      # Run all tests
make codegen   # Generate code from schemas
make clean     # Clean build artifacts

πŸ“ Workspace Structure

/
β”œβ”€β”€ services/              # Microservices
β”‚   β”œβ”€β”€ gateway/          # API Gateway (Python/FastAPI)
β”‚   β”œβ”€β”€ auth-service/     # Authentication (Python/FastAPI)
β”‚   β”œβ”€β”€ knowledge-api/    # Core API (Python/FastAPI)
β”‚   β”œβ”€β”€ frontend/         # Next.js App (TypeScript)
β”‚   β”œβ”€β”€ analysis/         # Code Analysis (Python)
β”‚   └── asset-fetcher/    # Asset Mirror (Python)
β”œβ”€β”€ packages/              # Shared Packages
β”‚   β”œβ”€β”€ shared-python/    # Python utilities
β”‚   └── shared-ts/        # TypeScript utilities
β”œβ”€β”€ schemas/               # API Schemas & Traffic
β”‚   β”œβ”€β”€ api/v2.17/        # OpenAPI specifications
β”‚   β”œβ”€β”€ collected/        # Captured traffic
β”‚   └── tools/            # Schema tools
β”œβ”€β”€ src/                   # Original TypeScript SDK
β”œβ”€β”€ data/                  # Persistent data
β”œβ”€β”€ scripts/               # Utility scripts
β”œβ”€β”€ infra/                 # Infrastructure (Docker, K8s)
└── docs/                  # Documentation

πŸ› οΈ Technology Stack

Backend (Python 3.12+)

  • FastAPI - High-performance async web framework
  • Uvicorn - ASGI server
  • Pydantic - Data validation and settings management
  • Ruff - Fast Python linter and formatter
  • mypy - Static type checking
  • pytest - Testing framework

Frontend (TypeScript)

  • Next.js 14+ - React framework with App Router
  • React - UI library
  • Vitest - Unit testing
  • Playwright - E2E testing
  • ESLint - Linting
  • Prettier - Code formatting

Infrastructure

  • Docker - Containerization
  • Docker Compose - Multi-container orchestration
  • GitHub Actions - CI/CD pipelines
  • Kubernetes - Production orchestration (planned)

πŸ“˜ TypeScript SDK

The original TypeScript SDK functionality is fully preserved and enhanced.

Installation

npm install @pplx-unofficial/sdk

Features

πŸ“˜ TypeScript SDK Features

  • βœ… SSE Streaming - Real-time AI search responses with Server-Sent Events
  • βœ… REST API - Complete CRUD for threads, entries, and collections
  • βœ… OAuth Connectors - 9 integrations (Google Drive, Notion, OneDrive, etc.)
  • βœ… Service Worker Analysis - Fetch and parse application chunk manifest
  • βœ… Code Graph Analysis - Dependency graphs, call chains, and bootstrap analysis
  • βœ… Type-Safe - Full TypeScript types for all operations
  • βœ… JSON Patch - RFC-6902 compliant differential updates
  • βœ… Rate Limiting - Built-in rate limit management
  • βœ… Pagination - AsyncGenerator-based pagination
  • βœ… Tree-Shakeable - Modular exports for optimal bundle size

πŸ“¦ Installation

npm install @pplx-unofficial/sdk
# or
yarn add @pplx-unofficial/sdk
# or
pnpm add @pplx-unofficial/sdk

πŸš€ Quick Start

Unified SDK (Recommended)

import { createPplxSDK } from "@pplx-unofficial/sdk";

const sdk = createPplxSDK();

// Quick search
const { entries, thread } = await sdk.quickSearch("What is quantum computing?");
console.log(entries[entries.length - 1].blocks);

// Streaming search
for await (const entry of sdk.stream.search("Explain transformers")) {
  console.log("Status:", entry.status);
  if (entry.final) {
    console.log("Final answer:", entry.blocks);
  }
}

// REST API
const threads = await sdk.rest.listThreads({ limit: 20 });
console.log("Recent threads:", threads.items);

// Connectors
const connectors = await sdk.getConnectorsStatus();
console.log("Connected:", connectors.filter(c => c.connected));

// Service Worker Analysis
const manifest = await sdk.serviceWorker.getManifest();
console.log("Total chunks:", manifest.totalChunks);

Modular Imports

// Import only what you need
import { createPplxClient } from "@pplx-unofficial/sdk/stream";
import { createRestClient } from "@pplx-unofficial/sdk/rest";
import { createConnectorsClient } from "@pplx-unofficial/sdk/connectors";
import { createServiceWorkerClient } from "@pplx-unofficial/sdk/service-worker";

const stream = createPplxClient();
const rest = createRestClient();
const connectors = createConnectorsClient();
const serviceWorker = createServiceWorkerClient();

Note: These modular import paths represent the planned API design and may not be available in the current release.

πŸ“š Documentation

πŸ”Œ Supported Connectors

Connector Type Plans Features
Google Drive File Storage Pro+ Picker, Real-time sync
Microsoft OneDrive File Storage Enterprise Picker, Sync
SharePoint File Storage Enterprise Org-wide
Dropbox File Storage Enterprise Sync
Box File Storage Enterprise Sync
Notion Productivity Pro+ Database search
Confluence Productivity Enterprise Space search
Slack Communication Enterprise Channel history
Local Upload Local All Drag & drop

🎨 Usage Examples

SSE Streaming

import { createPplxClient } from "@pplx-unofficial/sdk";

const client = createPplxClient();

// Search with options
for await (const entry of client.search("latest AI research", {
  focus: "academic",
  model: "sonar-pro",
  recency: "month"
})) {
  console.log(entry.status); // STARTED, STREAMING, COMPLETED
  if (entry.final) {
    console.log("Answer:", entry.blocks);
    console.log("Sources:", entry.sources_list);
  }
}

REST API

import { createRestClient } from "@pplx-unofficial/sdk";

const rest = createRestClient();

// List threads
const threads = await rest.listThreads({ limit: 20, sort: "updated_at" });

// Get thread details
const thread = await rest.getThread(contextUuid);

// Like an entry
await rest.likeEntry(backendUuid);

// Fork entry
const fork = await rest.forkEntry({
  backend_uuid: backendUuid,
  title: "My Fork"
});

// Collections (Spaces)
const collections = await rest.listCollections();
await rest.addThreadToCollection(collectionUuid, threadUuid);

OAuth Connectors

import { createConnectorsClient, OAuthPopupManager } from "@pplx-unofficial/sdk";

const connectors = createConnectorsClient();

// Start OAuth flow
const auth = await connectors.authorize("google_drive");
const popup = new OAuthPopupManager();
await popup.authorize(auth.auth_url);

// List files
const files = await connectors.listFiles("google_drive", { limit: 100 });

// Sync files to Space
await connectors.syncFiles("google_drive", fileIds, spaceUuid);

Service Worker Analysis

import { createServiceWorkerClient } from "@pplx-unofficial/sdk";

const client = createServiceWorkerClient();

// Fetch manifest
const manifest = await client.getManifest();
console.log(`Total chunks: ${manifest.totalChunks}`);

// Filter chunks
const jsChunks = await client.getChunks({ extension: "js" });
const restrictedFeatures = await client.getChunks({ restrictedOnly: true });

// Get statistics
const stats = await client.getStatistics();
console.log(`JavaScript files: ${stats.byExtension.js}`);
console.log(`Restricted features: ${stats.byCategory.restricted}`);

πŸ—οΈ Architecture

@pplx-unofficial/sdk
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ stream (pplx-client.ts)          - SSE streaming engine
β”‚   β”œβ”€β”€ rest (pplx-rest-client.ts)       - REST API for CRUD
β”‚   β”œβ”€β”€ connectors (pplx-connectors-client.ts) - OAuth & file sync
β”‚   └── index.ts                         - Unified SDK
β”œβ”€β”€ spa-assets/                           - Tracked SPA assets & versions
β”‚   β”œβ”€β”€ snapshots/                       - HAR-extracted snapshots by date
β”‚   β”œβ”€β”€ workbox/                         - Service worker chunks
β”‚   β”œβ”€β”€ vite-chunks/                     - Vite build artifacts
β”‚   β”œβ”€β”€ diffs/                           - Version-to-version differences
β”‚   └── metadata/                        - Asset index & integrity checksums
β”œβ”€β”€ docs/                                 - Documentation
β”œβ”€β”€ examples/                             - Usage examples
└── har_agent.py                          - HAR analysis toolkit

Protocol: 2.18
Endpoints: 38 total (2 SSE + 24 REST + 11 Connectors + 1 Service Worker)
LOC: 2,050+ (excluding examples)

πŸ€– SDK Consumer Bot

A reference implementation demonstrating all SDK capabilities:

cd sdk-consumer-bot

# Search with streaming
pplx-bot search "quantum computing" --focus academic

# Create conversation thread
pplx-bot chat "ML Research" "explain transformers" --save "AI Papers"

# Search with connectors
pplx-bot connectors-search "team docs" -c google_drive notion

# Automated research
pplx-bot research "GraphQL vs REST" --depth 3

Features:

  • βœ… Real-time streaming search with progress indicators
  • βœ… Conversation management (threads, collections, likes)
  • βœ… OAuth connector integration (Google Drive, Notion, etc.)
  • βœ… CLI interface with 8+ commands
  • βœ… Programmatic API for Node.js apps
  • βœ… TypeScript examples and documentation

See sdk-consumer-bot/README.md for full documentation.

πŸ”’ Security

  • CSRF Protection - State parameter in OAuth flow
  • Token Encryption - AES-256-GCM for stored tokens
  • Rate Limiting - Automatic rate limit compliance
  • User Isolation - Personal connectors per account

⚠️ Disclaimer

This is an unofficial SDK created through reverse engineering of Perplexity AI's web application. It is not affiliated with, endorsed by, or supported by Perplexity AI.

Use at your own risk:

  • May break with Perplexity updates
  • Not covered by official support
  • Terms of Service compliance is user's responsibility

πŸ“„ License

MIT License - see LICENSE file

🀝 Contributing

Contributions welcome! Please open an issue or PR.

πŸ”— Links


🎯 Microservices Architecture

Gateway Service (Port 8000)

API Gateway providing:

  • Rate limiting and CORS handling
  • Request routing to backend services
  • Authentication token injection
  • Health checks and monitoring

Auth Service (Port 8001)

Authentication hub featuring:

  • NextAuth flow implementation
  • Session pool management
  • Token rotation and refresh
  • Multi-account support

Knowledge API (Port 8002)

Core API service with:

  • SSE streaming endpoints
  • REST API for CRUD operations
  • Database integration
  • Cache layer for performance

Analysis Service (Port 8003)

Code analysis tools:

  • Tree-sitter AST parsing
  • Dependency graph generation
  • ML pipeline integration
  • Traffic pattern analysis

Asset Fetcher (Port 8004)

Service worker analysis:

  • Service worker parsing
  • Asset mirroring and updates
  • Version tracking
  • Incremental synchronization

Frontend (Port 3000)

Next.js application:

  • React with App Router
  • SSE streaming support
  • Real-time updates
  • Production-ready UI

πŸ“Š Status

Module Status Technology
Gateway Service βœ… Complete Python/FastAPI
Auth Service βœ… Complete Python/FastAPI
Knowledge API βœ… Complete Python/FastAPI
TypeScript SDK πŸ”„ Maintained TypeScript
Infrastructure βœ… Complete Docker/K8s
Documentation βœ… Complete Markdown
CI/CD Pipelines βœ… Complete GitHub Actions
Frontend πŸ”œ Planned Next.js 14+
Analysis Service πŸ”œ Planned Python/tree-sitter
Asset Fetcher πŸ”œ Planned Python

πŸ”— Links

πŸ“„ License

MIT License - see LICENSE file

🀝 Contributing

Contributions welcome! Please:

  1. Read docs/workspace.md
  2. Follow the coding standards (Ruff for Python, ESLint for TypeScript)
  3. Write tests for new features
  4. Submit pull requests to develop branch

⚠️ Disclaimer

This is an unofficial workspace created through reverse engineering of Perplexity AI's web application. Not affiliated with, endorsed by, or supported by Perplexity AI.

Use at your own risk:

  • May break with Perplexity updates
  • Not covered by official support
  • Terms of Service compliance is user's responsibility

Made with ❀️ for research and development

About

Unofficial TypeScript SDK for Perplexity AI - SSE Streaming, REST API, OAuth Connectors (Protocol 2.18)

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •