Agent skill · software engineering · jeremylongshore
klaviyo-sdk-patterns
Apply production-ready Klaviyo SDK patterns for the klaviyo-api package.
Why this skill is useful
Adds production-ready patterns for the klaviyo-api SDK that streamline integration and error handling, which the AI wouldn't reliably generate on its own.
What it needs
Requires klaviyo-api installed locally. About 3k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.
What this skill does
Klaviyo SDK Patterns Overview Production-ready patterns for the klaviyo-api Node.js SDK: singleton sessions, type-safe wrappers, retry logic, cursor pagination, and multi-tenant support. Read the target project's Klaviyo files, then Write or Edit the src/klaviyo/ modules below into place so every call goes through one consistent, retry-aware layer instead of ad-hoc new ApiKeySession(...) calls scattered across the codebase. The six patterns are summarized here with the essential skeleton; the full, copy-paste implementation for all of them lives in references/implementation.md, and combined worked examples with expected output are in references/examples.md. Prerequisites klaviyo-api package installed in the target project. The klaviyo-install-auth setup completed, so KLAVIYOPRIVATEKEY is available in the environment. A TypeScript project with strict mode enabled — every pattern is typed. Instructions Step 1: Singleton session (the foundation) Create one lazily-initialized ApiKeySession and reuse it everywhere. Read the key from the environment, fail fast if it is missing, and expose a reset hook for tests. Steps 2-6: the rest of the layer Each builds on the session singleton. Write the corresponding file from references/implementation.md: Step 2 — Type-safe API wrapper (api.ts): lazy getters for all 11 API clients (Profiles, Events, Lists, …) so unused clients are never constructed. Step 3 — Error wrapper (errors.ts): parseKlaviyoError normalizes the raw error and safeCall returns { data, error } instead of throwing. Step 4 — Retry (retry.ts): withRetry retries only on 429/5xx, honoring Klaviyo's Retry-After header, else exponential backoff with jitter. Step 5 — Pagination (pagination.ts): paginate turns any cursor-based list endpoint into an AsyncGenerator, extracting page[cursor] for you. Step 6 — Multi-tenant factory (multi-tenant.ts): getApisForTenant caches one client set per tenant id, isolating each customer's API key. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/klaviyo-sdk-patterns