# TypeScript SDK

> Run your team's scripts from TypeScript in one call, and call every API operation with types from the API itself.

The TypeScript SDK is a small typed client for Node.js, browsers and Cloudflare Workers. Its `run` method runs a script and returns the result in one call, however long the script takes. Every other API operation is a method too. Each path, parameter and response takes its type from the same definitions the API uses to validate requests, so the SDK always matches the [API reference](/docs/reference/).

## Install

```bash
npm install @reminix/sdk
```

## Your key

Create an API key in the app under **Settings → Developers**, and keep its access at **Run scripts**.

* `createClient()` reads your key from the `REMINIX_API_KEY` environment variable. If you haven’t set it, it reads `REMINIX_TOKEN`, the variable the CLI uses. With neither variable set, it throws an error.
* Where there’s no `process.env`, such as in a browser or a Cloudflare Worker, pass the key yourself: `createClient({ apiKey: env.REMINIX_API_KEY })`.
* With an **API key**, every call acts in the key’s workspace.
* With a **personal access token**, pass it as `token` and name the workspace: `createClient({ token, workspace: "acme" })`.

## Run a script

```ts
import { createClient } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

const run = await reminix.run("monthly-report", { month: "2026-09" });
console.log(run.output);
```

`run` returns once the script has finished:

* **A long run** keeps going after the API call returns. `run` checks on it until it ends.
* **A run that needs a person’s approval** waits for them. Pass `onApproval` to show them where to approve it: `reminix.run(slug, inputs, { onApproval: (url) => notify(url) })`.
* **A run that fails or ends as cancelled** throws a `RunError`. A run ends as cancelled when a person stops it, an approver denies it, or its approval expires. The error’s `run` has the run’s `status`, and the run’s `error` says why.
* **To get the run back straight away**, pass `{ wait: false }`. Later, `reminix.waitForRun(run)` follows it until it ends. It also takes the run’s id.
* **`pollInterval`** sets how often `run` checks on a run that hasn’t ended, in milliseconds. It’s 2000 by default.
* **`timeout`** limits each request `run` makes, in milliseconds, as on every other method. If a request times out, `run` tries it again.
* **`headers`** go with every request `run` makes.
* **To stop waiting**, pass a `signal`. It stops every request `run` makes, starting the run included. `AbortSignal.timeout(ms)` limits the whole wait. The run carries on when the wait stops.
* **To make calling again safe**, such as from a job that reruns, pass `{ idempotencyKey }`. A second call with the same key and inputs returns the first run instead of starting another.

### Files given and saved

Give a file input as a `Blob`, a `File`, or `{ name, mediaType, data }`. The SDK uploads the file first and passes its id. In this example, the monthly report takes an optional CSV file of manual adjustments and saves the report as a CSV file:

```ts
import { readFile } from "node:fs/promises";
import { createClient } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

const run = await reminix.run("monthly-report", {
  month: "2026-09",
  adjustments: {
    name: "adjustments.csv",
    mediaType: "text/csv",
    data: await readFile("adjustments.csv"),
  },
});
for (const file of run.files ?? []) {
  if (file.origin === "saved") console.log(file.name, file.downloadUrl);
}
```

The files a run saves come back in `run.files`, each with a download link. [Files](/docs/files/) has the details.

## Make a call

```ts
import { createClient } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

const runs = await reminix.runs.list({ script: "monthly-report", limit: 10 });
console.log(runs.items);
```

Every API operation is a method, named after its [CLI](/docs/cli/) command. For example, `reminix runs list` becomes `reminix.runs.list()`.

* Ids in the path are arguments, and everything else goes in one object:

  ```ts
  reminix.scripts.update("monthly-report", { name: "Monthly report" });
  ```

* A method returns the response’s data.

* Creating a schedule or trigger needs a personal access token, not a workspace API key. [Schedules and triggers](/docs/schedules-and-triggers/) explains why.

* Because the types come from the API itself, your editor completes every method, field and response.

## Lists

A list method returns its first page when you `await` it. The page has the response’s `items` and `nextCursor`:

```ts
import { createClient } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

const page = await reminix.runs.list({ script: "monthly-report", limit: 50 });
console.log(page.items);

if (page.hasNextPage()) {
  const next = await page.getNextPage();
  console.log(next.items);
}
```

To go through every item, use `for await`. The SDK fetches each next page when it needs it:

```ts
import { createClient } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

for await (const run of reminix.runs.list({ script: "monthly-report" })) {
  console.log(run.id, run.status);
}
```

Each next page is the same call with `cursor` set, so your other fields and options hold for every page. Read more about [pagination](/docs/pagination/).

## Errors

When the API refuses a call, the method throws an `APIError`. It has the [error](/docs/errors/)’s `code`, `message`, `status` and `requestId`. It also has:

* `details`: what is wrong with each field, as `{ path, message }`, when the API refused the input.
* `docs`: a link to the error on the Errors page.
* `headers`: the response’s headers, such as `Retry-After` and the rate-limit headers.

Each status has its own class, so you can catch one kind of failure:

| Status | Class                      |
| ------ | -------------------------- |
| 400    | `BadRequestError`          |
| 401    | `AuthenticationError`      |
| 402    | `PlanLimitError`           |
| 403    | `PermissionDeniedError`    |
| 404    | `NotFoundError`            |
| 409    | `ConflictError`            |
| 422    | `UnprocessableEntityError` |
| 429    | `RateLimitError`           |
| 500+   | `InternalServerError`      |

Any other status is an `APIError` itself.

When the SDK can’t reach the API, the method throws an `APIConnectionError`, with the network’s error as its `cause`. When every attempt timed out, it throws an `APITimeoutError`, which is an `APIConnectionError` too.

A run that fails throws a `RunError`. Every error a call throws, a `RunError` included, is a `ReminixError`, unless your own `signal` stopped it:

```ts
import {
  createClient,
  NotFoundError,
  ReminixError,
  RunError,
} from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

try {
  await reminix.run("monthly-report", { month: "2026-09" });
} catch (error) {
  if (error instanceof NotFoundError) {
    console.log("No such script");
  } else if (error instanceof RunError) {
    console.log(error.run.error);
  } else if (error instanceof ReminixError) {
    console.log(error.message);
  } else {
    throw error;
  }
}
```

## Retries and time limits

* Every write sends an [idempotency key](/docs/idempotency/). When the SDK retries a failed attempt, such as after a network error or a `503`, the write still happens only once.

* The SDK retries a failed attempt twice. To change that, pass `maxRetries` to `createClient`. `0` turns retries off.

* When the API says how long to wait with `Retry-After`, the SDK waits that long, up to 60 seconds. If it must wait longer, it throws the error, such as a `RateLimitError`, instead.

* To make your own retries safe too, pass your key as the last argument:

  ```ts
  reminix.runs.create("monthly-report", { inputs }, { idempotencyKey: id });
  ```

* Each attempt waits up to 60 seconds for a response. The SDK retries a timed-out attempt with the same key. To change the limit, pass `timeout` in milliseconds to `createClient`, or to one call:

  ```ts
  reminix.scripts.get("monthly-report", { timeout: 5000 });
  ```

* To limit a whole call, retries included, pass a `signal`. With `AbortSignal.timeout()`, the call stops at once when time is up, even while it waits to retry. It then throws the signal’s `TimeoutError`, not an SDK error:

  ```ts
  reminix.scripts.get("monthly-report", { signal: AbortSignal.timeout(2000) });
  ```

## Client options

| Option           | What it does                                                                             |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `apiKey`         | Your API key. By default, `REMINIX_API_KEY`, then `REMINIX_TOKEN`.                       |
| `token`          | A personal access token, instead of a key.                                               |
| `workspace`      | The workspace a personal access token acts in.                                           |
| `environment`    | The environment to act in, sent as `X-Environment`. By default, the workspace’s default. |
| `baseURL`        | The API’s address, without `/v1`. By default, `REMINIX_BASE_URL`, else our API.          |
| `defaultHeaders` | Headers to send with every request. A call’s own `headers` win.                          |
| `maxRetries`     | How many times to retry a failed attempt. By default, 2.                                 |
| `timeout`        | How long each attempt may take, in milliseconds. By default, 60 000.                     |
| `fetch`          | Your own `fetch`, such as a Cloudflare service binding.                                  |

Outside a browser, every request names the SDK and its version in its `User-Agent` header, such as `reminix-node/1.0.0`.

Each API method takes these options for one call, as its last argument: `idempotencyKey`, `headers`, `timeout` and `signal`. `run` and `uploadFile` take all four. `waitForRun` takes `headers`, `timeout` and `signal`, beside `pollInterval`.

## Methods

Here is every method. Each one links to its fields and a full example under **Endpoints**:

### Scripts

* [`scripts.archive()`](/docs/reference/scripts/#archive-a-script)

  Archive a script

* [`scripts.create()`](/docs/reference/scripts/#create-a-script)

  Create a script

* [`scripts.get()`](/docs/reference/scripts/#get-a-script)

  Get a script

* [`scripts.list()`](/docs/reference/scripts/#list-scripts)

  List scripts

* [`scripts.restore()`](/docs/reference/scripts/#restore-an-archived-script)

  Restore an archived script

* [`scripts.update()`](/docs/reference/scripts/#change-a-script)

  Change a script

### Runs

* [`runs.cancel()`](/docs/reference/runs/#cancel-a-run)

  Cancel a run

* [`runs.create()`](/docs/reference/runs/#run-a-script)

  Run a script

* [`runs.get()`](/docs/reference/runs/#get-a-run)

  Get a run

* [`runs.list()`](/docs/reference/runs/#list-runs)

  List runs

* [`runs.log()`](/docs/reference/runs/#get-a-runs-log)

  Get a run's log

### Versions

* [`scriptVersions.get()`](/docs/reference/versions/#get-a-version)

  Get a version

* [`scriptVersions.list()`](/docs/reference/versions/#list-a-scripts-versions)

  List a script's versions

* [`scriptVersions.publish()`](/docs/reference/versions/#publish-a-version)

  Publish a version

* [`scriptVersions.testRun()`](/docs/reference/versions/#test-run-a-version)

  Test-run a version

* [`scriptVersions.upload()`](/docs/reference/versions/#upload-a-version)

  Upload a version

### Schedules

* [`schedules.create()`](/docs/reference/schedules/#schedule-a-script)

  Schedule a script

* [`schedules.delete()`](/docs/reference/schedules/#delete-a-schedule)

  Delete a schedule

* [`schedules.get()`](/docs/reference/schedules/#get-a-schedule)

  Get a schedule

* [`schedules.list()`](/docs/reference/schedules/#list-a-scripts-schedules)

  List a script's schedules

* [`schedules.update()`](/docs/reference/schedules/#change-a-schedule)

  Change a schedule

### Triggers

* [`triggers.create()`](/docs/reference/triggers/#run-a-script-when-something-happens)

  Run a script when something happens

* [`triggers.delete()`](/docs/reference/triggers/#delete-a-trigger)

  Delete a trigger

* [`triggers.get()`](/docs/reference/triggers/#get-a-trigger)

  Get a trigger

* [`triggers.list()`](/docs/reference/triggers/#list-a-scripts-triggers)

  List a script's triggers

* [`triggers.rotateSecret()`](/docs/reference/triggers/#rotate-a-webhook-triggers-secret)

  Rotate a webhook trigger's secret

* [`triggers.update()`](/docs/reference/triggers/#change-a-trigger)

  Change a trigger

### Files

* [`files.content()`](/docs/reference/files/#get-a-files-content)

  Get a file's content

* [`files.get()`](/docs/reference/files/#get-a-file)

  Get a file

* [`files.list()`](/docs/reference/files/#list-files)

  List files

* [`files.upload()`](/docs/reference/files/#upload-a-file)

  Upload a file

### Environments

* [`environments.create()`](/docs/reference/environments/#add-an-environment)

  Add an environment

* [`environments.delete()`](/docs/reference/environments/#delete-an-environment)

  Delete an environment

* [`environments.get()`](/docs/reference/environments/#get-an-environment)

  Get an environment

* [`environments.list()`](/docs/reference/environments/#list-environments)

  List environments

* [`environments.update()`](/docs/reference/environments/#change-an-environment)

  Change an environment

### Secrets

* [`secrets.delete()`](/docs/reference/secrets/#delete-a-secret)

  Delete a secret

* [`secrets.get()`](/docs/reference/secrets/#get-a-secret)

  Get a secret

* [`secrets.list()`](/docs/reference/secrets/#list-secrets)

  List secrets

* [`secrets.update()`](/docs/reference/secrets/#update-a-secret)

  Update a secret

* [`secretValues.delete()`](/docs/reference/secrets/#remove-a-secrets-value-from-an-environment)

  Remove a secret's value from an environment

* [`secretValues.set()`](/docs/reference/secrets/#save-a-secrets-value)

  Save a secret's value

### Script settings

* [`scriptSettings.get()`](/docs/reference/script-settings/#get-the-workspaces-script-settings)

  Get the workspace's script settings

* [`scriptSettings.update()`](/docs/reference/script-settings/#change-the-workspaces-script-settings)

  Change the workspace's script settings

### Trigger calls

* [`triggerCalls.list()`](/docs/reference/trigger-calls/#list-a-webhook-triggers-calls)

  List a webhook trigger's calls

### Workspace

* [`workspace.get()`](/docs/reference/workspace/#get-the-current-workspace)

  Get the current workspace

* [`workspace.invitations.list()`](/docs/reference/workspace/#list-pending-invitations)

  List pending invitations

* [`workspace.members.list()`](/docs/reference/workspace/#list-workspace-members)

  List workspace members

* [`workspace.planUsage.get()`](/docs/reference/workspace/#get-your-plans-usage-this-period)

  Get your plan's usage this period

* [`workspace.teams.list()`](/docs/reference/workspace/#list-teams)

  List teams

### Webhooks

* [`workspace.eventTypes.list()`](/docs/reference/webhooks/#list-event-types)

  List event types

* [`workspace.webhookDeliveries.list()`](/docs/reference/webhooks/#list-an-endpoints-deliveries)

  List an endpoint's deliveries

* [`workspace.webhookDeliveries.redeliver()`](/docs/reference/webhooks/#redeliver-an-event)

  Redeliver an event

* [`workspace.webhookEndpoints.create()`](/docs/reference/webhooks/#add-a-webhook-endpoint)

  Add a webhook endpoint

* [`workspace.webhookEndpoints.delete()`](/docs/reference/webhooks/#remove-a-webhook-endpoint)

  Remove a webhook endpoint

* [`workspace.webhookEndpoints.enable()`](/docs/reference/webhooks/#re-enable-a-webhook-endpoint)

  Re-enable a webhook endpoint

* [`workspace.webhookEndpoints.get()`](/docs/reference/webhooks/#get-a-webhook-endpoint)

  Get a webhook endpoint

* [`workspace.webhookEndpoints.list()`](/docs/reference/webhooks/#list-webhook-endpoints)

  List webhook endpoints

* [`workspace.webhookEndpoints.test()`](/docs/reference/webhooks/#send-a-test-event)

  Send a test event

* [`workspace.webhookEndpoints.update()`](/docs/reference/webhooks/#update-a-webhook-endpoint)

  Update a webhook endpoint

### Approvals

* [`workspace.approvalActions.list()`](/docs/reference/approvals/#list-the-actions-you-can-ask-approval-for)

  List the actions you can ask approval for

* [`workspace.approvalRequests.create()`](/docs/reference/approvals/#ask-a-person-to-approve-an-action)

  Ask a person to approve an action

* [`workspace.approvalRequests.get()`](/docs/reference/approvals/#check-an-approval-request)

  Check an approval request

* [`workspace.approvalRequests.redeem()`](/docs/reference/approvals/#redeem-an-approved-request)

  Redeem an approved request

### Audit events

* [`workspace.auditEvents.list()`](/docs/reference/audit-events/#list-workspace-audit-events)

  List workspace audit events

### Personal access tokens

* [`user.me()`](/docs/reference/personal-access-tokens/#get-the-current-user)

  Get the current user

* [`user.revokeToken()`](/docs/reference/personal-access-tokens/#revoke-the-token-making-this-request)

  Revoke the token making this request

## Calling a path directly

`reminix.GET`, `reminix.POST` and the other HTTP methods call any path, with the same types. They return `{ data, error, response }` instead of throwing, and `unwrap` turns that into the data or an `APIError`:

```ts
import { createClient, unwrap } from "@reminix/sdk";

const reminix = createClient(); // uses the REMINIX_API_KEY environment variable

const scripts = unwrap(await reminix.GET("/scripts"));
console.log(scripts.items);
```
