How to use the Clickmax TypeScript SDK
The @clickmax/public-sdk package calls the Clickmax API from JavaScript or TypeScript code. Each endpoint has a typed method, and each call returns a result that holds either the value or the error.
Before you start, you need:
- a workspace API key, created by an owner or admin under Settings > Connections > API (details in Clickmax API authentication);
- a runtime with
fetchandAbortSignal.any, such as Node.js 22 or later, Deno, Bun, or Cloudflare Workers; - a project that uses ES modules, because the package has no CommonJS build.
The key acts on behalf of the whole workspace. Use the SDK only on a server and load the key from an environment variable or a secret manager. Never include the key in code that runs in a browser or a mobile app.
Make your first call
Install the package
Create the client
The second constructor argument takes options that apply to every call made through the instance:
The constructor is the only part of the SDK that throws. It throws a TypeError when the key is empty or malformed or when an option is invalid.
Call an endpoint
Methods follow the endpoint path: /tags/list becomes clickmax.tags.list() and /tags/manual-list becomes clickmax.tags.manualList(). Endpoints without a resource are methods of the client itself, such as /whoami, which becomes clickmax.whoami().
The first argument is the endpoint input, with the same fields as the interactive reference:
Endpoints without input, such as clickmax.tags.list(), do not take that argument.
Handle the result
Methods never throw and never reject. Read the result as an object:
Or destructure it as an [ok, error, value] tuple:
In both forms, TypeScript knows that value is set when ok is true and that error is set when ok is false.
Handle each error type
The error of a failed result is a ClickmaxError, which extends Error:
The type, code, requestId, and issues fields come from the API error body, and their possible values are listed in Clickmax API errors. The error also has status (the HTTP status, or 0 when no response arrived), message (text for logs that can change between versions), retryAfter (the seconds from the Retry-After header, when the API sends it), and raw (the response body as received). When an error response is not JSON, the SDK derives the type from the HTTP status.
When a request gets no usable response, the SDK uses its own types:
When the SDK rejects an argument before sending the request, such as a negative timeout or a body that cannot be converted to JSON, the result fails with type invalid_request, code invalid_argument, and status 0.
When you ask support for help, include the error.requestId.
Retry after the request limit
All keys of a workspace share the limit of 100 requests every 10 seconds. When it is exceeded, the result fails with type rate_limit, and retryAfter says how many seconds to wait:
Retry automatically on rate_limit errors. On api, network, and timeout errors, retry with backoff only when repeating the call is safe. An invalid_request, authentication, or permission error comes back the same until the request or the account changes.
Change the options of a single call
The last argument of every method accepts signal, timeout, headers, and fetch. Each option replaces the instance value for that call only:
Per-call headers are applied over the instance headers. The Authorization header always uses the instance key and cannot be changed per call.
Use several workspaces
Each instance keeps its own key and options, and instances share no state. Create one instance per workspace:
Validate data with zod
The @clickmax/public-sdk/zod subpath exports zod schemas for the input and the successful response of each endpoint. Using them is optional: the client does not import these schemas and does not validate input before sending the request. To use them, install zod 4 (4.1.13 or a later 4.x) in your project:
A schema name joins the resource and the method in PascalCase, followed by a suffix:
The interactive reference shows the HTTP method of each endpoint. Methods of the client itself use only the method name, such as WhoamiResponse for clickmax.whoami().
The schemas are written with zod/mini, and your bundler includes only the schemas you import in your build.
Update the package
Each package version matches the v0 API at the time it was published. Because v0 can still change, pin the version you tested and test your integration before upgrading.