@pageindex/sdk
v0.6.0
Published
PageIndex SDK - Document processing for AI applications via REST API and MCP
Maintainers
Readme
@pageindex/sdk
TypeScript SDK for PageIndex document processing.
Get your API Key at dash.pageindex.ai. For full API documentation, see docs.pageindex.ai.
Installation
pnpm add @pageindex/sdkRequires Node.js >= 18.0.0
Quick Start
import { PageIndexClient } from '@pageindex/sdk';
const client = new PageIndexClient({
apiKey: 'your-api-key',
});
// Upload a document
const { doc_id } = await client.api.submitDocument(fileBuffer, 'report.pdf');
// List recent documents
const recent = await client.tools.recentDocuments();
// Extract document structure
const structure = await client.tools.getDocumentStructure({ docName: 'report.pdf' });
// Extract page content
const pages = await client.tools.getPageContent({ docName: 'report.pdf', pages: '1-5' });With explicit resource management (TypeScript 5.2+):
await using client = new PageIndexClient({ apiKey: 'your-api-key' });
const recent = await client.tools.recentDocuments();
// connection closed automatically when scope exitsAPI
Client
const client = new PageIndexClient({
apiKey: 'your-api-key',
folderScope: 'folder-id', // optional, restricts all operations to this folder
});When folderScope is set, all operations are restricted to the specified folder and its descendants. Per-call folderId can narrow within the scope (e.g. target a subfolder) but cannot access folders outside the boundary. Change it at runtime via client.setFolderScope(id).
Tools
All methods via client.tools:
| Method | Description |
| ------------------------------------------------------------------------- | ------------------------ |
| recentDocuments({ folderId?, cursor?, limit? }) | List recent uploads |
| findRelevantDocuments({ query?, limit?, folderId?, cursor? }) | Search documents |
| getDocument({ docName, waitForCompletion?, folderId? }) | Get document details |
| getDocumentStructure({ docName, part?, waitForCompletion?, folderId? }) | Extract document outline |
| getPageContent({ docName, pages, waitForCompletion?, folderId? }) | Extract page content |
| getDocumentImage({ imagePath }) | Retrieve embedded image |
| removeDocument({ docNames, folderId? }) | Delete documents |
| createFolder({ name, description?, parentFolderId? }) | Create folder |
| listFolders({ parentFolderId? }) | List folders |
Page specification formats: "5", "3,7,10", "5-10", "1-3,7,9-12"
API
All methods via client.api:
// Submit a document
const result = await client.api.submitDocument(file, 'document.pdf');
// Get document metadata
const doc = await client.api.getDocument(docId);
// List all documents
const docs = await client.api.listDocuments({ limit: 20, offset: 0 });
// Delete a document
await client.api.deleteDocument(docId);
// Chat completions
const chat = await client.api.chatCompletions({
messages: [{ role: 'user', content: 'Summarize the document' }],
doc_id: docId,
});
Error Handling
import { PageIndexError } from '@pageindex/sdk';
try {
await client.tools.getDocument({ docName: 'xxx' });
} catch (e) {
if (e instanceof PageIndexError) {
// e.code: 'NOT_FOUND' | 'UNAUTHORIZED' | 'RATE_LIMITED' | 'USAGE_LIMIT_REACHED' | ...
// e.statusCode: HTTP status code
}
}Documentation
- API Quickstart — Get started with document processing
- API Endpoints — Full REST API reference
- Python SDK — Python client (tree, chat, OCR)
- MCP Integration — Use PageIndex with AI agents
Examples
See examples/chat-demo for Next.js + AI SDK integration.
License
MIT
