@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.
Install the package
Install the client and itsgraphql 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."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 inBOXPRESSD_DEVELOPER_API_KEY, then create one client for your backend process.
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 itsdata and pagination fields.
searchCigars, getCigar, resolveCigar, getProduct, lookupBarcode, and getMe.
Query GraphQL
GraphQL helpers return the GraphQLdata object directly.
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
Userequest() for API routes without a dedicated helper. The client adds x-boxpressd-key; you supply the paid operation’s idempotency key.
Check billing
The client includes helpers for the non-billable billing reads:endUserId from your backend when you want billing usage attributed to one of your application users:
Handle errors
The same named error classes are available from both module formats.requestWithResponse() or graphqlWithResponse() when you also need response headers, the request ID, rate-limit metadata, or GraphQL cost.