https://github.com/vectifyai/pageindex-js-sdk
TypeScript SDK for PageIndex document processing.
https://github.com/vectifyai/pageindex-js-sdk
Last synced: 2 months ago
JSON representation
TypeScript SDK for PageIndex document processing.
- Host: GitHub
- URL: https://github.com/vectifyai/pageindex-js-sdk
- Owner: VectifyAI
- Created: 2026-01-13T07:35:09.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-05-28T00:58:52.000Z (2 months ago)
- Last Synced: 2026-05-28T02:23:42.988Z (2 months ago)
- Language: TypeScript
- Homepage: https://pageindex-js-sdk.vercel.app/
- Size: 583 KB
- Stars: 6
- Watchers: 0
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @pageindex/sdk
TypeScript SDK for [PageIndex](https://pageindex.ai) — upload documents, retrieve tree structures, and chat with your PDFs.
Get your API Key at [dash.pageindex.ai](https://dash.pageindex.ai/api-keys). Full docs at [docs.pageindex.ai/js-sdk](https://docs.pageindex.ai/js-sdk).
## Installation
```bash
npm install @pageindex/sdk
```
## Quick Start
```typescript
import { PageIndexClient } from '@pageindex/sdk';
import { readFileSync } from 'fs';
const client = new PageIndexClient({ apiKey: 'YOUR_API_KEY' });
// Upload a document
const file = readFileSync('./report.pdf');
const { doc_id } = await client.api.submitDocument(file, 'report.pdf');
// Get tree structure
const tree = await client.api.getTree(doc_id);
// Chat with the document
const response = await client.api.chatCompletions({
messages: [{ role: 'user', content: 'What are the key findings?' }],
doc_id,
});
console.log(response.choices[0].message.content);
// Stream a response
const stream = await client.api.chatCompletions({
messages: [{ role: 'user', content: 'Summarize this document' }],
doc_id,
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```
## Configuration
```typescript
const client = new PageIndexClient({
apiKey: 'YOUR_API_KEY', // Required
apiUrl: 'https://...', // Default: https://api.pageindex.ai
folderScope: 'folder-id', // Restrict all operations to a folder
});
```
## REST API (`client.api`)
| Method | Description |
| ------------------------------------------ | ----------------------------------------------- |
| `submitDocument(file, fileName, options?)` | Upload a document |
| `getTree(docId, options?)` | Get tree structure and processing status |
| `getDocument(docId)` | Get document metadata |
| `listDocuments(options?)` | List documents (paginated) |
| `deleteDocument(docId)` | Delete a document |
| `createFolder(options)` | Create a folder |
| `listFolders(options?)` | List folders |
| `chatCompletions(params)` | Chat with documents (streaming & non-streaming) |
## Chat API
Supports non-streaming, streaming, multi-document, metadata streaming, and citations. See [Chat API docs](https://docs.pageindex.ai/js-sdk/chat) for full reference.
```typescript
// Multi-document chat
await client.api.chatCompletions({
messages: [{ role: 'user', content: 'Compare these' }],
doc_id: ['doc-1', 'doc-2'],
});
// Streaming with tool call metadata
const stream = await client.api.chatCompletions({
messages,
doc_id,
stream: true,
stream_metadata: true,
});
for await (const chunk of stream) {
if (chunk.block_metadata?.type === 'mcp_tool_use_start') {
console.log(`[Using: ${chunk.block_metadata.tool_name}]`);
}
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```
## MCP Tools (`client.tools`)
Typed wrappers for PageIndex MCP — for building custom AI agent integrations. See [MCP Tools docs](https://docs.pageindex.ai/js-sdk/mcp-tools).
| Method | Description |
| -------------------------------- | ----------------------------------------------------------------- |
| `browseDocuments(params?)` | Unified discovery (time/relevance sort, folder drill-down) |
| `getFolderStructure(params?)` | Folder hierarchy as a tree |
| `searchDocuments(params)` | Keyword search with LLM re-rank (escalation path) |
| `getDocument(params)` | Get document details by name |
| `getDocumentStructure(params)` | Extract document outline |
| `getPageContent(params)` | Read page content |
| `getDocumentImage(params)` | Retrieve embedded image |
| `removeDocument(params)` | Delete documents (batch) |
**Deprecated** (still callable for backward compatibility, hidden from the live MCP `tools/list`):
| Method | Replacement |
| -------------------------------- | ---------------------------------------------------- |
| `recentDocuments(params?)` | `browseDocuments()` (default `sort: "time"`) |
| `findRelevantDocuments(params?)` | `browseDocuments({ sort: "relevance", query })` or `searchDocuments()` |
| `listFolders(params?)` | `getFolderStructure()` |
## Error Handling
```typescript
import { PageIndexError } from '@pageindex/sdk';
try {
await client.api.getDocument('invalid-id');
} catch (error) {
if (error instanceof PageIndexError) {
console.log(error.code); // "NOT_FOUND" | "UNAUTHORIZED" | "PLAN_REQUIRED" | ...
console.log(error.message);
}
}
```
## Examples
- [examples/chat-with-tools](./examples/chat-with-tools) — Next.js + AI SDK with MCP tools
- [examples/chat-completions](./examples/chat-completions) — Direct Chat Completions API usage
## Links
- [JS SDK Docs](https://docs.pageindex.ai/js-sdk) · [Python SDK](https://docs.pageindex.ai/sdk) · [MCP](https://docs.pageindex.ai/cookbook/mcp) · [REST API](https://docs.pageindex.ai/endpoints)
- [Discord](https://discord.gg/VuXuf29EUj) · [GitHub](https://github.com/VectifyAI/pageindex-js-sdk)
## License
MIT