OverviewQuickstartREST APIMCP serverPlaywrightTypeScript SDK
Humanless/Docs/TypeScript SDK

TypeScript SDK

The Humanless SDK is one zero-dependency TypeScript file that wraps the REST API. It adds typed responses, typed errors and smart waits. waitForCode and waitForLink skip messages that have no code or link, and they re-poll until an overall deadline. It works anywhere fetch exists: Node 18+, Deno, Bun and browsers.

Install

The SDK is a single source file, published at usehumanless.com/sdk/humanless.ts. It isn't on npm yet. Download it into your project:

bash
curl -o humanless.ts https://usehumanless.com/sdk/humanless.ts

Then import it:

ts
import { Humanless, withIdentity } from "./humanless";

const hl = new Humanless({ apiKey: process.env.HUMANLESS_API_KEY! });

Constructor options

OptionTypeDefault
apiKeystringrequired (hl_live_...)
baseUrlstringprocess.env.HUMANLESS_BASE_URL, otherwise https://api.usehumanless.com
fetchtypeof fetchglobal fetch (override it for tests or proxies)

Methods

MethodREST callReturns
createIdentity({ channels?, domain?, ttl_seconds? })POST /v1/identitiesIdentity
getIdentity(identityId)GET /v1/identities/:idIdentity
waitForMessage({ identityId, channel?, timeout?, since?, signal? })GET /v1/identities/:id/waitMessage (any type)
waitForCode(opts)sameMessage & { code: string }. Skips messages without a code
waitForLink(opts)sameMessage & { url: string }. Skips messages without a link
getTotp(identityId)GET /v1/identities/:id/totp{ code, seconds_remaining }
deleteIdentity(identityId)DELETE /v1/identities/:id{ identity_id, status: "deleted" }

Wait options

OptionTypeDefaultNotes
identityIdstringrequired
channel"any", "email" or "sms""any"
timeoutseconds60Overall deadline across all long-poll rounds. Each round is at most 60 s
sinceUnix ms or DatenoneTake Date.now() just before you trigger the send. This makes the wait race-free and lets you read the same message again
signalAbortSignalnoneCancels the wait

withIdentity

withIdentity(hl, opts, fn) creates an identity, runs fn, and always deletes the identity afterwards, even if fn throws. That keeps your dedicated phone numbers free and avoids 409 all_numbers_busy.

ts
await withIdentity(hl, { channels: ["email"] }, async ({ identity_id, email }) => {
  await page.getByLabel("Email").fill(email!);
  await page.getByRole("button", { name: "Send code" }).click();
  const { code } = await hl.waitForCode({ identityId: identity_id });
  await page.getByLabel("Code").fill(code);
});

Errors

ts
import { HumanlessError } from "./humanless";

try {
  await hl.createIdentity({ channels: ["sms"] });
} catch (err) {
  if (err instanceof HumanlessError && err.isSmsQuotaExceeded) {
    console.log("Top up or upgrade:", err.details?.billing_url);
  } else throw err;
}

Types

ts
type IdentityChannel = "email" | "sms" | "totp";

interface Identity {
  identity_id: string;
  channels: IdentityChannel[];
  email: string | null;
  phone: string | null;        // E.164
  totp_secret: string | null;  // base32
  status: "active" | "deleted" | "expired";
  expires_at: string;
  created_at: string;
  ended_at: string | null;
}

interface Message {
  type: "otp" | "magic_link" | "raw";
  code: string | null;
  url: string | null;
  channel: "email" | "sms";
  sender: string;
  subject: string | null;
  received_at: string;
  raw_snippet: string;
}

The SDK exports the old Verifybox* names as deprecated aliases, so code written against the earlier SDK keeps working.