The Keyset constructor accepts a single KeysetConfig object.
TypeScriptimport { Keyset } from "keysetapp"; const client = new Keyset(config: KeysetConfig);
KeysetConfig| Property | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | — | Your Keyset API key. Prefix pkey_ = public (read-only), skey_ = secret (read + write). |
cacheTTL | number | Yes | — | Top-level TTL in milliseconds. Used as a required field on the config shape. |
baseUrl | string | No | https://api.keyset.in/v1 | Override the API base URL (useful for self-hosted deployments or local development). |
timeout | number | No | 5000 | Request timeout in milliseconds. The request is aborted if it exceeds this value. |
retries | number | No | 0 | Number of retry attempts on failure. Uses exponential backoff: 2^attempt × 100 ms. |
cache | CacheConfig | No | — | Enable and configure the in-memory response cache. |
CacheConfig| Property | Type | Required | Default | Description |
|---|---|---|---|---|
enabled | boolean | No | false | Enable the in-memory cache. |
ttl | number | No | 60000 | Time-to-live in milliseconds for cached entries. |
TypeScriptconst client = new Keyset({ apiKey: "pkey_abc123", cacheTTL: 0, });
TypeScriptconst client = new Keyset({ apiKey: "pkey_abc123", cacheTTL: 60000, cache: { enabled: true, ttl: 60000, // cache responses for 60 seconds }, retries: 3, timeout: 8000, });
TypeScriptconst client = new Keyset({ apiKey: "pkey_abc123", cacheTTL: 0, baseUrl: "https://keyset.mycompany.com/api/v1", });
TypeScriptconst admin = new Keyset({ apiKey: "skey_xyz789", cacheTTL: 0, retries: 2, });
The SDK validates the key format at construction time. Invalid keys throw immediately:
TypeScriptnew Keyset({ apiKey: "", cacheTTL: 0 }); // Error: API key is required new Keyset({ apiKey: "invalid_key", cacheTTL: 0 }); // Error: Invalid API key format
Valid prefixes are pkey_ (public) and skey_ (secret).
When cache.enabled is true, the SDK creates an in-memory MemoryCache instance with:
cache.ttl milliseconds (default 60 000 ms)create, update, delete) automatically delete the cached content response