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 cossThe 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 ({ : .. });Hover any identifier in these examples to see its type.
Options
const = new ({
: "coss_test_...",
: "https://api.coss.com",
: 30_000,
: 2,
: false,
});| Option | Default | Description |
|---|---|---|
apiKey | COSS_API_KEY | A coss_live_… or coss_test_… key |
baseUrl | COSS_BASE_URL, then https://api.coss.com | The API origin |
timeout | 30000 | Per-attempt timeout in milliseconds |
maxRetries | 2 | Retries for network errors, timeouts, 409, 429 and 5xx |
fetch | global fetch | A custom fetch implementation |
dangerouslyAllowBrowser | false | Allow 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.);}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.