⚙️ PageIndex JavaScript SDK
Document Processing
Upload, process, and manage documents
Chat API (beta)
Chat with your PageIndex-processed documents
Install
npm install @pageindex/sdkInitialize
To get started, visit the PageIndex Developer Dashboard and generate your API key .
import { PageIndexClient } from "@pageindex/sdk";
const client = new PageIndexClient({ apiKey: "YOUR_API_KEY" });Configuration Options
| Name | Type | Required | Description | Default |
|---|---|---|---|---|
| apiKey | string | yes | PageIndex API key | - |
| apiUrl | string | no | Custom API base URL | https://api.pageindex.ai |
| folderScope | string | no | Restrict all operations to a specific folder and its subfolders | - |
Quick Start
Upload a PDF, retrieve its tree structure, and ask a question:
import { PageIndexClient } from "@pageindex/sdk";
import { readFileSync } from "fs";
const client = new PageIndexClient({ apiKey: "YOUR_API_KEY" });
// 1. Upload a document
const file = readFileSync("./2023-annual-report.pdf");
const { doc_id } = await client.api.submitDocument(file, "2023-annual-report.pdf");
console.log("Document ID:", doc_id);
// 2. Get tree structure (includes processing status)
const tree = await client.api.getTree(doc_id);
if (tree.status === "completed") {
console.log("Tree:", tree.result);
}
// 3. 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);
// 4. 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 ?? "");
}See Document Processing for upload and management, and Chat API for the full chat reference.
💡
Want results instantly with streaming? The Chat API also supports streaming responses.
Error Handling
All SDK errors are instances of PageIndexError:
import { PageIndexClient, PageIndexError } from "@pageindex/sdk";
try {
const doc = await client.api.getDocument("invalid-id");
} catch (error) {
if (error instanceof PageIndexError) {
console.log(error.code); // "NOT_FOUND" | "UNAUTHORIZED" | "RATE_LIMITED" | ...
console.log(error.message); // Human-readable description
console.log(error.statusCode); // HTTP status code
console.log(error.details); // Additional context
}
}Error Codes
| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED | 401 | Invalid or missing API key |
NOT_FOUND | 404 | Document or resource not found |
RATE_LIMITED | 429 | Too many requests |
USAGE_LIMIT_REACHED | 403 | Account usage limit exceeded |
INVALID_INPUT | 400 | Invalid parameters |
SERVICE_UNAVAILABLE | 503 | Service temporarily unavailable |
INTERNAL_ERROR | 500 | Unexpected server error |
SDK Full Reference
- Document Processing: Upload, process, and manage documents.
- Chat API (beta): Chat with your PageIndex-processed documents.
💬 Community & Support
Last updated on