npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

pageindex-js

v0.0.8

Published

A Javascript/Typescript client for PageIndex

Downloads

673

Readme

PageIndex TypeScript SDK

A fully typed TypeScript client for the PageIndex API. This SDK allows you to interact with PageIndex for document submission, OCR, tree generation, retrieval, and chat completions in a type-safe manner.


Table of Contents


Installation

npm install pageindex-js
# or
yarn add pageindex-js

Include the SDK in your project:

import { PageIndexClient } from 'pageindex-js';

Initialization

import { PageIndexClient } from './pageindex-js';

const client = new PageIndexClient('YOUR_API_KEY');

Document Submission

Upload a PDF document for processing:

const result = await client.submitDocument('./example.pdf');
console.log(result.doc_id);

OCR

Get OCR processing results:

const ocrResult = await client.getOcr('doc_id_here', 'page'); // 'page' or 'node'
console.log(ocrResult);

Tree Generation

Retrieve the document tree structure:

const tree = await client.getTree('doc_id_here', true); // true to include node summaries
console.log(tree);

Check if the document is ready for retrieval:

const ready = await client.isRetrievalReady('doc_id_here');
console.log(ready); // true or false

Retrieval

Submit a query against a document:

const retrieval = await client.submitQuery('doc_id_here', 'What is the main topic?', true);
console.log(retrieval.retrieval_id);

Get retrieval results:

const retrievalResult = await client.getRetrieval('retrieval_id_here');
console.log(retrievalResult);

Chat Completions

Generate a chat completion, optionally scoped to one or more documents:

const messages = [
  { role: 'user', content: 'Summarize the document.' }
];

const completion = await client.chatCompletions({messages: [], stream: false, doc_id: 'doc_id_here'});
console.log(completion);

Streaming responses:

for await (const chunk of client.chatCompletions({messages: [], stream: true, doc_id: 'doc_id_here'})) {
  console.log(chunk);
}

Document Management

Get metadata for a document:

const doc = await client.getDocument('doc_id_here');
console.log(doc);

Delete a document:

await client.deleteDocument('doc_id_here');

List all documents with pagination:

const docs = await client.listDocuments(50, 0);
console.log(docs.documents);

Error Handling

All API errors throw a PageIndexAPIError:

try {
  await client.getDocument('invalid_id');
} catch (err) {
  if (err instanceof PageIndexAPIError) {
    console.error('API error:', err.message);
  }
}