COSS

Overview

Install the coss package, configure the client and handle results.

coss is the official TypeScript SDK. It has zero dependencies, is fully typed and runs on Node.js 22+, Bun, Deno and Cloudflare Workers.

npm install coss

The SDK is not published to npm yet. Until it is, use it from the COSS repository.

The client

One client covers every product. Create it once and reuse it. Each endpoint's page in the API reference shows its SDK call in the TypeScript tab; these pages cover how the client itself behaves.

import {  } from "coss";

const coss = new ({ : .. });
const coss: Coss

Hover any identifier in these examples to see its type.

Options

const  = new ({
  : "coss_test_...",
  : "https://api.coss.com",
  : 30_000,
  : 2,
  : false,
});
OptionDefaultDescription
apiKeyCOSS_API_KEYA coss_live_… or coss_test_… key
baseUrlCOSS_BASE_URL, then https://api.coss.comThe API origin
timeout30000Per-attempt timeout in milliseconds
maxRetries2Retries for network errors, timeouts, 409, 429 and 5xx
fetchglobal fetchA custom fetch implementation
dangerouslyAllowBrowserfalseAllow running where document exists (exposes your key)

The constructor throws only for programmer errors: a missing API key, or running in a browser without dangerouslyAllowBrowser.

Results, not exceptions

Every method returns { data, error }. API and network failures come back as error; they are never thrown. Checking error narrows data:

const  = await ..("email_01k7c8m4q2f3e9v6t5r1n0p8yz");

if (.) {
  .(..);
} else {
  .(.data.);
data: Email
}

Per-request options

Methods take an optional last argument. Every method accepts an AbortSignal; send also takes an idempotency key.

const  = new ();

await ..(, { : "welcome-user-123", : . });
await ..("email_01k7c8m4q2f3e9v6t5r1n0p8yz", { : . });

Runtimes

The package is ESM-only and uses nothing but fetch, AbortSignal and crypto.randomUUID. Environment fallbacks read process.env where it exists; on Workers or Deno without env access, pass apiKey (and baseUrl) explicitly.

On this page