pageindex-node-sdk
v1.0.5
Published
Node-first TypeScript SDK for the PageIndex API
Maintainers
Readme
PageIndex Node SDK (pageindex-node-sdk)
Node-first TypeScript SDK for the PageIndex API.
PageIndex is a vectorless, reasoning-based RAG framework that turns long, complex documents into a tree-structured index and lets LLMs perform agentic reasoning over that structure for context‑aware, traceable retrieval — with no vector database and no chunking required.
This SDK wraps the core HTTP endpoints (PDF upload, document status/tree/OCR, listing, deletion, and Chat API with streaming) for easy use from Node.js.
Install
npm install pageindex-node-sdk
# or
yarn add pageindex-node-sdkRequirements
- Node.js >= 18 (uses built‑in
fetch,FormData,ReadableStream) - A PageIndex API key from the Developer Dashboard
Quickstart (TypeScript / ESM)
import { PageIndexClient } from "pageindex-node-sdk";
const client = new PageIndexClient({
apiKey: process.env.PAGEINDEX_API_KEY!,
});
async function main() {
// 1) Upload a PDF
const { doc_id } = await client.submitDocumentFromPath({
path: "./2023-annual-report.pdf",
});
console.log("doc_id:", doc_id);
// 2) Poll until tree processing is complete
let status = "processing";
while (status !== "completed") {
const doc = await client.getTree(doc_id);
status = doc.status;
console.log("status:", status, "retrieval_ready:", doc.retrieval_ready);
if (status !== "completed") {
await new Promise((r) => setTimeout(r, 1500));
}
}
// 3) Non‑streaming chat
const chat = await client.chatCompletions({
doc_id,
messages: [
{ role: "user", content: "What are the key findings in this document?" },
],
enable_citations: true,
});
console.log(chat.choices?.[0]?.message?.content);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});Streaming chat example
import { PageIndexClient } from "pageindex-node-sdk";
const client = new PageIndexClient({
apiKey: process.env.PAGEINDEX_API_KEY!,
});
async function streamChat(docId: string) {
for await (const evt of client.chatCompletionsStream({
doc_id: docId,
messages: [
{ role: "user", content: "Summarize this document in 5 bullet points." },
],
enable_citations: true,
})) {
if (evt.type === "data") {
const delta = evt.data.choices?.[0]?.delta?.content ?? "";
if (delta) process.stdout.write(delta);
} else if (evt.type === "done") {
break;
}
}
process.stdout.write("\n");
}API overview
All methods live on PageIndexClient:
Constructor
new PageIndexClient({ apiKey, baseUrl?, fetch? })apiKey(required): your PageIndex API key (sent viaapi_keyheader).baseUrl(optional): defaults tohttps://api.pageindex.ai.fetch(optional): customfetchimplementation (e.g. for tests).
PDF processing
submitDocument({ file, filename?, mode? })- Wraps
POST /doc/withmultipart/form-data.
- Wraps
submitDocumentFromPath({ path, filename?, mode? })- Node‑only helper that reads a local PDF and calls
submitDocument.
- Node‑only helper that reads a local PDF and calls
Document results
getDocument(docId, { type?, format?, summary? })- Generic wrapper over
GET /doc/{doc_id}/.
- Generic wrapper over
getTree(docId, { summary? })- Convenience wrapper for
type=tree.
- Convenience wrapper for
getOcr(docId, { format? })- Convenience wrapper for
type=ocr+format=page|node|raw.
- Convenience wrapper for
Metadata & management
getDocumentMetadata(docId)GET /doc/{doc_id}/metadata
listDocuments({ limit?, offset? })GET /docs
deleteDocument(docId)DELETE /doc/{doc_id}/
Chat API (beta)
chatCompletions(request)- Non‑streaming
POST /chat/completions.
- Non‑streaming
chatCompletionsStream(request)- Streaming via Server‑Sent Events (SSE); yields parsed events with:
type: "data" | "done" | "comment"data: parsed chunk (whentype === "data").
- Streaming via Server‑Sent Events (SSE); yields parsed events with:
The request/response shapes are aligned with the official PageIndex API reference.
Contribution Guidelines
Issues & feature requests
- Open a GitHub issue with:
- A clear description of the problem or feature.
- Steps to reproduce (if applicable).
- Environment details (Node version, OS).
- Open a GitHub issue with:
Pull requests
- Fork the repository.
- Create a feature branch (
feat/my-featureorfix/my-bug). - Ensure:
npm run typecheckpasses.npm run lintpasses.
- Write clear commit messages and, where useful, update this
README.mdor code comments for non-obvious behavior.
Code style
- Follow existing patterns in
src/pageindex-client.tsandsrc/types.ts. - Prefer small, focused PRs.
- Follow existing patterns in
License
This project is licensed under the MIT License. See the LICENSE file for details.
Repository
Source code and issue tracking live on GitHub:https://github.com/coolpinkzz/pageindex-node-sdk
