TypeScript SDK ยท client.sdk.docs

Documents

The docs namespace manages PDF files in the Pdffillr SDK. Upload a PDF once to receive a numeric doc_id - that identifier drives every subsequent operation: checking status, fetching a URL, triggering the AI fill pipeline, or attaching the file to a chat session.

client.sdk.docsuploadgetURLgetMetadatalistdeleteuploadFilledInfoattachDocument
What this page covers
Uploading PDF files (up to 10 MB)
Retrieving a raw S3 key or a presigned download URL
Fetching single-document metadata and fill status
Listing all documents scoped to your API key
Permanently deleting a document and its storage object
Uploading filled-info data to trigger the AI fill pipeline
Attaching an uploaded PDF to a chat session

1. Overview

A document is a PDF you upload to your developer storage. On upload the SDK assigns a numeric doc_id that uniquely identifies the file under your API key. Every subsequent operation - checking fill status, generating a download URL, kicking off the AI pipeline, attaching the file to a chat session - refers to the document by that ID. Documents are scoped to your API key: other keys and accounts never see your files.

Seven things you can do with documents
01
docs.upload(body)Upload a PDF

Stores the file and returns a doc_id. Every other operation starts here - you must upload before you can fill, preview, or attach.

02
docs.getURL(docID, query?)Get a download URL

Returns either the raw S3 key path or a temporary presigned URL valid for 1 hour - ready for browser download or in-app preview.

03
docs.getMetadata(docID)Check document metadata

Retrieves the filename, size, upload time, and fill status for a single document. Use this to poll for fill job completion.

04
docs.list()List all your documents

Returns every PDF stored under your API key, ordered newest first. Useful for building document management UIs.

05
docs.delete(docID)Delete a document

Permanently removes the file and its S3 storage object. Cannot be undone - download the filled PDF before deleting.

06
docs.uploadFilledInfo(params)Trigger AI form filling

Uploads filled-in data and kicks off the AI fill pipeline against a blank PDF. Asynchronous - poll getMetadata() for the result.

07
sessions.attachDocument(sessionID, body)Attach to a chat session

Links an uploaded PDF to an active chat session so the AI can reference its content when answering questions.

Document lifecycle
docs-lifecycle.ts
import Pdffillr from '@pdffillr/sdk';
import fs from 'fs';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// 1. upload() - store the PDF and receive a doc_id.
const doc = await client.sdk.docs.upload({
  file: fs.createReadStream('form.pdf'),
});
console.log('Uploaded:', doc.doc_id);

// 2. list() - see every document stored under this API key.
const allDocs = await client.sdk.docs.list();
console.log(`${allDocs.length} documents on file`);

// 3. getMetadata() - check fill status before triggering a fill.
const meta = await client.sdk.docs.getMetadata(doc.doc_id);
console.log('Fill status:', meta.fill_status);

// 4. getURL() - get a presigned URL for browser preview (valid 1 hour).
const { url } = await client.sdk.docs.getURL(doc.doc_id, { presigned: true });
console.log('Preview URL:', url);

// 5. delete() - remove the document and its S3 object permanently.
await client.sdk.docs.delete(doc.doc_id);
console.log('Deleted.');

Document Storage

2. Upload a Document

Uploads a PDF file to your developer storage and returns a numeric doc_id. That identifier is the entry point for every subsequent operation - filling, polling results, fetching a URL, and chat context. Files must be PDF format and no larger than 10 MB.

client.sdk.docs.upload(body, options?)POST /v1/sdk/docs/upload
ReturnsPromise<DocRecord>
Required argsbody.file: Uploadable
Body parameters - DocUploadParams
ParameterTypeRequiredDescription
fileUploadableYesThe PDF file to upload. Pass fs.createReadStream(path) in Node.js or a File/Blob in browser environments. Must be PDF format, maximum 10 MB.
Example
docs-upload.ts
import Pdffillr from '@pdffillr/sdk';
import fs from 'fs';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Upload a PDF - the returned doc_id is used in all subsequent operations.
const doc = await client.sdk.docs.upload({
  file: fs.createReadStream('path/to/document.pdf'),
});
console.log('Uploaded doc_id:', doc.doc_id);
Save the doc_id
The doc_id returned by upload() is the only handle you have to the stored file. Save it in your database - the SDK provides no search-by-filename API.

3. Get Document URL

Returns a URL for accessing the raw, unfilled PDF. By default (presigned=false) the response contains the stored S3 key path. Pass presigned: true to receive a temporary presigned S3 URL valid for one hour - suitable for direct browser download or in-app preview without exposing your credentials.

client.sdk.docs.getURL(docID, query?, options?)GET /v1/sdk/docs/{docId}/url
ReturnsPromise<{ url: string }>
Required argsdocID: number
Query parameters - DocGetURLParams
ParameterTypeDefaultDescription
presignedbooleanfalseWhen false, returns the stored S3 key path. When true, returns a temporary presigned URL valid for 1 hour.
Example
docs-get-url.ts
import Pdffillr from '@pdffillr/sdk';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Default (presigned=false): returns the stored S3 key path.
const keyResult = await client.sdk.docs.getURL(42);
console.log('S3 key:', keyResult.url);

// presigned=true: returns a temporary URL valid for 1 hour.
// Use this when you need to serve the file directly in a browser.
const presignedResult = await client.sdk.docs.getURL(42, { presigned: true });
console.log('Presigned URL:', presignedResult.url);
Presigned URLs expire
A presigned URL is valid for exactly one hour from the moment it is generated. Do not cache it beyond that window - generate a fresh one each time the user needs to access the file.

4. Get Document Metadata

Retrieves the stored metadata for a single document identified by its doc_id. The response includes the filename, MIME type, file size, upload timestamp, and the current fill_status. Check this status before initiating a fill job or before serving the filled PDF to a user.

client.sdk.docs.getMetadata(docID, options?)GET /v1/sdk/docs/{docId}
ReturnsPromise<DocRecord>
Required argsdocID: number
Response fields - DocRecord
FieldTypeDescription
doc_idnumberThe unique numeric identifier for this document.
filenamestringThe original filename as uploaded.
mime_typestringThe detected MIME type (application/pdf).
size_bytesnumberFile size in bytes.
uploaded_atstring (ISO 8601)When the document was uploaded.
fill_status"pending" | "ready" | "failed"Current state of the AI fill pipeline for this document.
Example
docs-get-metadata.ts
import Pdffillr from '@pdffillr/sdk';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Retrieve metadata for a single document by its doc_id.
const meta = await client.sdk.docs.getMetadata(42);

console.log('Filename:    ', meta.filename);
console.log('MIME type:   ', meta.mime_type);
console.log('Size:        ', meta.size_bytes, 'bytes');
console.log('Fill status: ', meta.fill_status);  // 'pending' | 'ready' | 'failed'
console.log('Uploaded at: ', meta.uploaded_at);
Use this for polling
getMetadata() is the recommended way to poll for fill job completion. Call it every 3-5 seconds after uploadFilledInfo() and wait for fill_status to become ready or failed.

5. List All Documents

Returns every document uploaded under your API key, ordered by upload date descending (newest first). The response is strictly scoped to your key - documents belonging to other API keys or accounts are never returned. Each record includes the doc_id, filename, MIME type, size, upload timestamp, and fill status.

client.sdk.docs.list(options?)GET /v1/sdk/docs
ReturnsPromise<DocRecord[]>
Required argsNone
Example
docs-list.ts
import Pdffillr from '@pdffillr/sdk';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Returns all documents uploaded under this API key - newest first.
const docs = await client.sdk.docs.list();

docs.forEach((d) => {
  console.log(`[${d.fill_status}] ${d.doc_id} - ${d.filename}`);
  console.log(`  Size: ${d.size_bytes} bytes, Uploaded: ${d.uploaded_at}`);
});

6. Delete a Document

Permanently deletes the document identified by docID and removes its associated S3 storage object. This action cannot be undone. Any in-progress fill jobs referencing the document will fail after deletion. Only the document specified is affected - all other documents under your API key remain untouched.

client.sdk.docs.delete(docID, options?)DELETE /v1/sdk/docs/{docId}
ReturnsPromise<void>
Required argsdocID: number
Example
docs-delete.ts
import Pdffillr from '@pdffillr/sdk';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Permanently delete a document and its associated S3 object.
// This cannot be undone.
await client.sdk.docs.delete(42);
console.log('Document 42 deleted.');
Deletion is permanent
There is no way to recover a deleted document. Ensure you have downloaded or archived the filled PDF before calling delete().

Fill Pipeline

7. Trigger AI Form Filling

Uploads a filled-info data file and queues the AI form-filling pipeline against an existing blank PDF. The pipeline is asynchronous - this call returns immediately after the job is queued. Poll getMetadata() every 3-5 seconds until fill_status becomes ready, then download the filled PDF via getURL() with presigned: true.

client.sdk.docs.uploadFilledInfo(params, options?)POST /v1/sdk/docs/upload-filled-info
ReturnsPromise<void>
Required argspdf_doc_id, file
Parameters - DocUploadFilledInfoParams
ParameterTypeRequiredDescription
pdf_doc_idnumberYesThe doc_id of the blank PDF template uploaded via docs.upload().
fileUploadableYesThe filled-info file (JSON or structured data) containing the values to inject into the form fields.
Fill workflow
1Upload the blank PDF template via docs.upload() to get a pdf_doc_id.
2Prepare a filled-info file (JSON or structured data) with the values to inject.
3Call uploadFilledInfo() with the filled-info file and pdf_doc_id.
4Poll docs.getMetadata(pdf_doc_id) every 3-5 seconds until fill_status is ready.
5Download the filled PDF using docs.getURL(pdf_doc_id, { presigned: true }).
End-to-end example
docs-upload-filled-info.ts
import Pdffillr from '@pdffillr/sdk';
import fs from 'fs';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// Step 1 - upload the blank PDF template.
const template = await client.sdk.docs.upload({
  file: fs.createReadStream('blank-form.pdf'),
});

// Step 2 - upload filled-info data to trigger the AI fill pipeline.
await client.sdk.docs.uploadFilledInfo({
  pdf_doc_id: template.doc_id,
  file: fs.createReadStream('filled-data.json'),
});
console.log('Fill job queued - polling for result...');

// Step 3 - poll pollFillResult() every 3-5 seconds until status is 'ready'.
let result;
do {
  await new Promise((r) => setTimeout(r, 3000));
  result = await client.sdk.docs.pollFillResult(template.doc_id);
} while (result.status === 'processing');

if (result.status === 'ready') {
  // Step 4 - download the filled PDF using the provided URL (expires 1 hr).
  console.log('Filled PDF ready:', result.url);
} else {
  console.error('Fill job failed:', result.error);
}
The pipeline is asynchronous
uploadFilledInfo() queues the job and returns immediately. Do not assume the PDF is ready after this call - always poll getMetadata() until fill_status is no longer pending.

Session Integration

8. Attach to a Session

Attaches a previously uploaded PDF to a chat session. Once attached, the AI can reference the document's content when answering questions in all subsequent messages within that session. The document must already exist - upload it first using docs.upload(). You can attach multiple documents to a single session by calling this method multiple times with different doc_id values.

client.sdk.chat.sessions.attachDocument(sessionID, body, options?)POST /v1/sdk/chat/sessions/{sessionId}/attach-document
ReturnsPromise<void>
Required argssessionID, body.doc_id
Body parameters - SessionAttachDocumentParams
ParameterTypeRequiredDescription
doc_idnumberYesThe doc_id of the PDF to attach - must have been uploaded via docs.upload() first.
Example
docs-attach-to-session.ts
import Pdffillr from '@pdffillr/sdk';
import fs from 'fs';

const client = new Pdffillr({
  apiKey: process.env['PDFFILLR_API_KEY'],
});

// 1. Upload the PDF to get a doc_id.
const doc = await client.sdk.docs.upload({
  file: fs.createReadStream('contract.pdf'),
});

// 2. Create a chat session.
const session = await client.sdk.chat.sessions.create({ title: 'Contract Review' });

// 3. Attach the document to the session.
//    Once attached, the AI can reference its content in all subsequent messages.
await client.sdk.chat.sessions.attachDocument(session.session_id, {
  doc_id: doc.doc_id,
});
console.log('Document attached - the AI can now reference it in this session.');

// You can attach multiple documents by calling attachDocument again with a new doc_id.
Upload before attaching
attachDocument() expects the PDF to already exist in storage. Always call docs.upload() first and use the returned doc_id in the body.

What to read next

Was this page helpful?
PDFFILLR.AI logo

PDFFILLR.AI

The intelligent layer for modern fund
administration. Automating high-stakes
documentation with precision and speed.

Powered byEngineersMind