Skip to main content
The @caretly/caretly package has no runtime dependencies and is built on the standard fetch. It ships ESM, CommonJS and TypeScript types.

Install

The package name has the @caretly scope. Import from @caretly/caretly, not caretly.

Quickstart

Create a test key in the console and set it in your environment:
Render a label to PDF and save it:

ESM, CommonJS and runtimes

The package works with import and require:
instanceof checks on errors work even when an application loads both builds. It runs on Node.js 18 or newer. The core also runs in Deno, Bun and edge runtimes that have fetch. Only saveTo needs node:fs. Elsewhere, read result.bytes instead.
Keep your API key on the server. Don’t use the client in browser code, where anyone can read the key.

Render a page as PNG

A PNG holds one page. Choose it with page, starting at 1:
caretly.renderPdf(zpl) is the matching shorthand for a PDF.

Render several files

renderFiles sends the files as multipart/form-data. Each file starts from a fresh printer state, and pages follow the order of the files:

Render options

render(zpl, options) and renderFiles(files, options) take: Options you leave out aren’t sent, so the server defaults apply. An invalid format, page, dpmm or idempotencyKey throws a RangeError before any request.

Read the result

Handle errors

Every error from the API or the network extends CaretlyError: APIError has status, message (the server’s text), retryAfter (seconds or null) and headers.
Aborting with your own signal rejects with the signal’s reason, an AbortError by default, not a CaretlyError.

Retries and idempotency

The client retries 429, 503 and connection errors up to maxRetries times, 2 by default. It waits Retry-After seconds when the server sends it. Otherwise it backs off 0.5 s, 1 s, 2 s, up to 8 s. Timeouts and other statuses aren’t retried. When retries are on and you pass no idempotencyKey, the client generates a UUID per call and sends it on every attempt, so a retried request is never billed twice. Set your own key, such as an order number, to make retries across calls or processes safe too:

Configuration

Custom fetch

Pass your own fetch to add logging, route requests through a proxy, or mock them in tests:

Health check