Skip to main content
@boxpressd/api-client is the official server-side TypeScript and JavaScript client for the Boxpressd Developer API. It provides typed REST and GraphQL helpers, OAuth forwarding, billing attribution, response metadata, timeouts, and typed errors. Version 0.1.4 and later supports both ECMAScript modules (ESM) and CommonJS (CJS). The package requires Node.js 18 or newer.
Keep the developer key and this client on a trusted server. Do not include them in browser, Expo, React Native, or other distributable application code.

Install the package

Install the client and its graphql peer dependency:

Choose a module system

The package uses conditional exports. Node and compatible bundlers select the correct build from the package-root import. The package publishes shared TypeScript declarations, the ESM runtime for the import condition, and the CommonJS runtime for the require condition. Import from @boxpressd/api-client; internal dist paths are not public exports.

TypeScript configuration

TypeScript applications can use normal named imports in either output mode. Set the compiler module mode to match the Node.js application.
For ESM output, set "type": "module" in your application’s package.json or use .mts. For CommonJS output, set "type": "commonjs", omit type, or use .cts. TypeScript compiles the named import to require() for CommonJS output while preserving the package’s types.

Create a client

Store your key in BOXPRESSD_DEVELOPER_API_KEY, then create one client for your backend process.
The client uses https://api.boxpressd.com and a 15-second timeout by default. When you set apiBaseUrl, the GraphQL URL defaults to ${apiBaseUrl}/graphql.

Search with REST

REST helpers return the API response body, including its data and pagination fields.
Common REST helpers include searchCigars, getCigar, resolveCigar, getProduct, lookupBarcode, and getMe.

Query GraphQL

GraphQL helpers return the GraphQL data object directly.
Use graphql() when you need a query that does not have a dedicated helper. It accepts a GraphQL string or a DocumentNode from the graphql package.

Call AI endpoints

Use request() for API routes without a dedicated helper. The client adds x-boxpressd-key; you supply the paid operation’s idempotency key.
See AI and cigar matching for endpoint inputs, credit behavior, and safe retry rules.

Check billing

The client includes helpers for the non-billable billing reads:
Pass a stable opaque endUserId from your backend when you want billing usage attributed to one of your application users:
The API hashes this value before storage. It does not authenticate or authorize a Boxpressd user.

Handle errors

The same named error classes are available from both module formats.
Use requestWithResponse() or graphqlWithResponse() when you also need response headers, the request ID, rate-limit metadata, or GraphQL cost.

Troubleshoot module loading