Fundamentals
The core building blocks of every Pdffillr SDK integration - making your first API call, understanding the client namespace, getting the most out of TypeScript types, and writing error handling that holds up in production.
1. Your First Request
Every interaction with the Pdffillr API starts with creating a chat session. A session is the unit of work that drives one complete, AI-guided form-filling interaction - from first question to filled PDF. The call is a single awaited method on the client with no required arguments. Here is the complete, minimal program to do it.
import 'dotenv/config';
import Pdffillr from '@pdffillr/sdk';
// 1. Initialise the client once at application startup.
// The SDK reads your API key from the environment automatically.
const client = new Pdffillr({
apiKey: process.env['PDFFILLR_API_KEY'],
});
// 2. Create a new chat session.
// This sends POST /v1/sdk/chat/sessions and resolves with the session object.
const session = await client.sdk.chat.sessions.create();
// 3. Inspect the result.
console.log(session);What each line does
Using await outside a top-level ES module
Top-level await works only in ES modules ("type": "module" in package.json, or .mts / .mjs files). In CommonJS files or older TypeScript setups, wrap your calls in an async function and call it immediately.
import 'dotenv/config';
import Pdffillr from '@pdffillr/sdk';
const client = new Pdffillr({
apiKey: process.env['PDFFILLR_API_KEY'],
});
// Wrap in an async function if you are not at the top level of an ES module.
async function main() {
const session = await client.sdk.chat.sessions.create();
console.log('Session created:', session);
}
main().catch(console.error);2. API Namespace
The SDK organises every API resource into a nested property hierarchy that mirrors the Pdffillr REST API's URL structure. You navigate to a resource by chaining property accesses on the client object, then call the method that represents the HTTP verb. This design means the SDK is self-documenting - the method name tells you the operation and your editor's autocomplete shows you every option without leaving your IDE.
client
└── sdk // All SDK-level resources
└── chat // Conversational form-filling
└── sessions
└── .create() // POST /v1/sdk/chat/sessions| Property chain | HTTP method | Path |
|---|---|---|
| client.sdk | - | /v1/sdk |
| client.sdk.chat | - | /v1/sdk/chat |
| client.sdk.chat.sessions | - | /v1/sdk/chat/sessions |
| client.sdk.chat.sessions.create() | POST | /v1/sdk/chat/sessions |
client.sdkThe top-level namespace for every Pdffillr API resource. All features and endpoints are nested under this property. Think of it as the root of the resource tree - everything you can do with the API starts here.
client.sdk.chatGroups all resources related to AI-driven, conversational form-filling. The chat layer is responsible for the back-and-forth interaction between the end user and the Pdffillr AI engine - guiding a user through a form field by field, validating responses in real time.
client.sdk.chat.sessionsThe sessions resource manages the full lifecycle of a chat session - from creation through to the final filled PDF and JSON output. Each call to sessions.create() opens a fresh, isolated session context on Pdffillr. Sessions are the primary unit of work in the platform.
3. TypeScript Support
The SDK is written in TypeScript and ships its compiled JavaScript output alongside bundled .d.ts declaration files. This means you get complete, accurate type information in any editor that supports the TypeScript Language Server - including VS Code, WebStorm, and Neovim with LSP - without installing any additional package or changing your tsconfig.json.
What your editor shows you
import 'dotenv/config';
import Pdffillr from '@pdffillr/sdk';
const client = new Pdffillr({
apiKey: process.env['PDFFILLR_API_KEY'],
});
// TypeScript infers the return type automatically.
// Hover over 'session' in your editor to see the full type.
const session = await client.sdk.chat.sessions.create();
// No manual type annotation needed - your editor already knows
// the shape of every property on the response object.Module system compatibility
| Module system | Import syntax | When to use |
|---|---|---|
| ESM (recommended) | import Pdffillr from … | TypeScript projects, or package.json "type": "module" |
| CommonJS | require('@pdffillr/sdk') | Legacy Node.js projects without ESM configured |
4. Error Handling
Every SDK method that makes a network call returns a Promise. When something goes wrong - an invalid API key, a rate-limit breach, a malformed request, or a transient server fault - the Promise rejects with aPdffillr.APIError subclass. Robust error handling is not optional in production: unhandled rejections crash Node.js processes, and silently swallowed errors hide outages from your monitoring stack.
import 'dotenv/config';
import Pdffillr from '@pdffillr/sdk';
const client = new Pdffillr({
apiKey: process.env['PDFFILLR_API_KEY'],
});
try {
const session = await client.sdk.chat.sessions.create();
console.log('Session ready:', session);
} catch (err) {
// Log the failure - never swallow errors silently.
console.error('SDK request failed:', err);
// Re-throw so the caller or process handler can decide
// whether to retry, alert, or gracefully shut down.
throw err;
}Common failure scenarios
401 UnauthorizedThe API key is missing, malformed, expired, or revoked.
Verify PDFFILLR_API_KEY is set correctly and that the key is active in the dashboard.
429 Too Many RequestsYour application is sending more requests than the rate limit allows.
Implement exponential back-off before retrying. Do not retry immediately - that makes the problem worse.
Network error / ECONNREFUSEDThe Node.js process cannot reach the Pdffillr API - firewall, DNS, or VPN issue.
Confirm that outbound HTTPS is permitted from your server. Check DNS resolution for the API hostname.
5xx Server ErrorA transient fault on Pdffillr - the platform is degraded or deploying.
Retry with exponential back-off. Check the Pdffillr status page. 5xx errors are usually short-lived.
For transient server errors (5xx) and rate-limit responses (429), retrying with increasing delays is the correct production pattern. Client errors (4xx) must not be retried - they will not self-resolve.
import Pdffillr from '@pdffillr/sdk';
const client = new Pdffillr({
apiKey: process.env['PDFFILLR_API_KEY'], // This is the default and can be omitted
});
const session = await client.sdk.chat.sessions
.create({ title: 'My session' })
.catch(async (err) => {
if (err instanceof Pdffillr.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});Next steps
PDFFILLR.AI
The intelligent layer for modern fund
administration. Automating high-stakes
documentation with precision and speed.