Skip to content
dimmiDocs

SDKs

TypeScript SDK

Install @dimmi/api to call the dimmi REST API from TypeScript with generated types, cursor pagination, and automatic retries.

@dimmi/api wraps openapi-fetch with types generated from dimmi’s OpenAPI contract. It works on Node.js 20+ or any runtime with fetch.

Terminal window
npm install @dimmi/api
dimmi.ts
import { createDimmiApi, unwrap } from "@dimmi/api";
const api = createDimmiApi({
host: "https://trydimmi.com",
token: process.env.DIMMI_API_TOKEN!,
});
const created = await unwrap(
api.POST("/contacts", { body: { email: "ada@example.com", name: "Ada Lovelace" } }),
);
console.log(created.data.id);

Set DIMMI_API_TOKEN to your API token. If you self-host, point host to your own dimmi URL.

api.GET, api.POST, api.PATCH, api.PUT, and api.DELETE accept every path in the API reference. Each returns { data, error, response }, and unwrap() returns data or throws.

import { paginate } from "@dimmi/api";
for await (const conversation of paginate(api, "/conversations", {
params: { query: { "filter[status]": "open" } },
})) {
console.log(conversation.id);
}

paginate() yields one item at a time and fetches new pages as you iterate. Use pages() with the same arguments if you want each raw page response instead.

import { DimmiApiError, unwrap } from "@dimmi/api";
try {
await unwrap(api.POST("/contacts", { body: { email: "not-an-email" } }));
} catch (error) {
if (error instanceof DimmiApiError) {
console.log(error.status, error.code, error.errors);
}
}

unwrap(), paginate(), and pages() throw DimmiApiError, exposing status, code, and errors from API errors.

Option Default What it does
host None Your dimmi base URL. The client appends /api/v1.
baseUrl None Full API URL, used instead of host.
maxRetries 3 Retry count after a 429 rate limit response.
maxRetryDelay 30000 Max retry delay in milliseconds (respects Retry-After).
autoIdempotency false Adds an Idempotency-Key to every POST that lacks one.
headers None Extra headers sent on every request.
fetch globalThis.fetch Custom fetch implementation.

This package does not include webhook verification. For Node.js webhook checks, see Verify webhook signatures.