new TryYourSize()
Creates a client for one secret or restricted key. Create it once and reuse it.
constructor(apiKey: string, options: TryYourSizeOptions = {})Parameters
Section titled “Parameters”apiKeystringRequiredA secret key (sk_test_… / sk_live_…) or a restricted key (rk_…). Keep it in an environment variable.
optionsTryYourSizeOptionsOptional= {}Properties
apiVersionstring | undefinedOptionalTYS-Version sent with every request (default: the version this SDK was built against).
maxRetriesnumber | undefinedOptionalRetries of network errors, timeouts, 429, 5xx and 409 idempotency_key_in_use (default 2).
timeoutMsnumber | undefinedOptionalPer-attempt timeout in ms (default 30,000).
baseUrlstring | undefinedOptionalAPI origin (default https://api.tryyoursize.com).
fetchtypeof fetch | undefinedOptionalA fetch implementation (default: the global fetch of Node 18+).
Errors
Section titled “Errors”TypeError for a missing key, a publishable key, or no fetch.
Example
Section titled “Example”import TryYourSize from "@tryyoursize/node";
const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, { maxRetries: 2, // network errors, timeouts, 429, 5xx timeoutMs: 30_000,});import osimport tryyoursize
tys = tryyoursize.TryYourSize(os.environ["TRYYOURSIZE_SECRET_KEY"], max_retries=2, timeout=30.0)Was this page helpful?
Thank you. We read every answer.