Skip to content

new TryYourSize()

Constructor@tryyoursize/node

Creates a client for one secret or restricted key. Create it once and reuse it.

constructor(apiKey: string, options: TryYourSizeOptions = {})
apiKeystringRequired

A secret key (sk_test_… / sk_live_…) or a restricted key (rk_…). Keep it in an environment variable.

optionsTryYourSizeOptionsOptional= {}
Properties
apiVersionstring | undefinedOptional

TYS-Version sent with every request (default: the version this SDK was built against).

maxRetriesnumber | undefinedOptional

Retries of network errors, timeouts, 429, 5xx and 409 idempotency_key_in_use (default 2).

timeoutMsnumber | undefinedOptional

Per-attempt timeout in ms (default 30,000).

baseUrlstring | undefinedOptional

API origin (default https://api.tryyoursize.com).

fetchtypeof fetch | undefinedOptional

A fetch implementation (default: the global fetch of Node 18+).

TypeError for a missing key, a publishable key, or no fetch.

import TryYourSize from "@tryyoursize/node";
const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, {
maxRetries: 2, // network errors, timeouts, 429, 5xx
timeoutMs: 30_000,
});

Was this page helpful?