TenanciTenanci

Help centerDevelopers

Node/TypeScript SDK

The official API v2 client for Node and TypeScript, with no dependencies and shortcuts for projects, domains, analytics, marketing, email, the portal and A/B tests.

@tenanci/sdk is a small client for the v2 API for Node and TypeScript: you call tenanci.domains.create(...) instead of building the HTTP request by hand, and errors arrive as exceptions carrying the API's stable code. It has no dependencies and uses the fetch built into Node 18 or newer.

Install

npm install @tenanci/sdk

Set up

Create an API key and pass it to the client together with the API address:

SDK (Node)
import { Tenanci } from "@tenanci/sdk";

const tenanci = new Tenanci({
  apiKey: process.env.TENANCI_API_KEY!,
  baseUrl: "https://api.tenanci.com/v2",
});
Option What it is
apiKey the key (tnc_live_…), required
baseUrl the v2 API address, required: https://api.tenanci.com/v2
fetch optional: a different fetch (tests, edge runtimes)
locale optional: "pt-BR" or "en", the language of error messages (without it, the organization's)

Connect a customer's domain

The most common case: a customer of your app bought their own domain and your backend registers it right away, saying which customer it belongs to (tenant context).

const domain = await tenanci.domains.create({
  projectId: "prj_8f3k2m",
  hostname: "joesbarbershop.com",
  tenant: { id: "barbershop-123", data: { name: "Big Joe Barbershop" } },
});
console.log(domain.status); // "pending_dns"
console.log(domain.dns);    // { type: "A", name: "joesbarbershop.com", values: ["109.224.228.49"] }

domain.dns is the record the customer must create at their DNS provider (see DNS). Operation: POST /domains.

What you can do

Group Methods
projects list(), get(id), create({ name, originUrl }), verify(id)
domains list({ projectId, cursor, limit }), get(id), create(...), update(id, fields), remove(id), recheck(id), setTenant(id, tenant), setAccess(id, access)
analytics overview(domainId, { from, to }), breakdown(domainId, dimension, options), campaigns(domainId, { from, to })
marketing get(domainId), save(domainId, settings), createLink(domainId, { slug, url, name })
emails send({ domainId, to, subject, text, html, replyTo, fromLocal })
portal createSession(projectId, { tenantId, tenantData, returnUrl, email, ttlMinutes })
splitTests list(domainId), create(domainId, test), action(domainId, id, "start" | "pause" | "resume" | "end" | "archive", winner?)
ai status(), importBrand(domainId, url), translate(domainId, { lang, texts, context }), suggestSeo(domainId, { paths, about }): suggestions only, see AI features
tailorkit get(domainId), saveDraft(domainId, document), publish(domainId)
seo listPages(domainId), upsertPage(domainId, { pathPattern, title, description, … })
request request(method, path, body?, query?) for any other v2 API operation

projects.list() and splitTests.list() return the list directly; domains.list() returns a page ({ items, nextCursor }, see pagination).

Any other operation

For an operation without a shortcut, use request. The path is the one in the reference, without /api/v2:

// the domain's status timeline
const { items } = await tenanci.request<{ items: unknown[] }>("GET", "/domains/dom_4h7n1q/events");

// check DNS again (shortcut: tenanci.domains.recheck)
await tenanci.request("POST", "/domains/dom_4h7n1q/recheck");

Operations: GET /domains/:id/events and POST /domains/:id/recheck.

Errors

Every API error response becomes a TenanciError with status (HTTP), code (stable), message and details:

SDK (Node)
import { TenanciError } from "@tenanci/sdk";

try {
  await tenanci.domains.create({ projectId: "prj_8f3k2m", hostname: "joesbarbershop.com" });
} catch (e) {
  if (e instanceof TenanciError && e.code === "domain_exists") {
    // already registered in your organization: carry on with the existing domain
  } else if (e instanceof TenanciError && e.code === "domain_limit_reached") {
    // the plan can't fit more domains (see "Extra domains")
  } else {
    throw e;
  }
}

message comes in the locale option's language (or the organization's); code is the same in any language. The list of codes is under API errors. For the plan's domain limit, see extra domains.

AI agents

Tenanci's MCP server uses this same client under the hood, with the key's same rules and scopes. If you use Claude, Cursor or another agent, see MCP: no code needed.