Integration · SDK
TypeScript
The TypeScript client ships on npm as @metapolicy/sdk. Pure ESM. Works in Node 18+, the browser, React Native, edge runtimes (Cloudflare Workers, Vercel Edge). Tree-shakes to ~5 KB gzipped for the decide-only path.
The contract
What flows in
- Decide requests: experiment, userId, context object
- Reward events: userId, experiment, rewardSpec key, value
- Optional: batch decide for slate ranking
What flows out
- Assignment + propensity returned synchronously to the call site
- Promise resolves before render in the SSR case
Setup
- 01npm install @metapolicy/sdk
- 02Initialise once at app bootstrap with your environment-scoped API key
- 03Call client.decide({ experiment, userId, context }) at the decision site
- 04Wire reward emission to your existing analytics or order-confirmed event
- 05For React: optional hook useDecision(experiment, context) handles suspense + revalidation
Where it runs
Built for the mobile-growth team's TS-everywhere stack. Same client in your Next.js server components, your React Native app, your Cloudflare Worker that gates the paywall, and your Vercel Edge middleware.
Wire format and types are generated from the same OpenAPI spec the Python client uses — one schema, every language.
React Native specifics
Decide responses are cached in-memory keyed on (experiment, userId, contextHash) for the duration of the foreground session, so you can call decide multiple times across renders without a network round-trip.
AppState background transitions invalidate the cache to keep propensities honest if the context could have drifted while the app was paused.
Other sdk integrations
Wire TypeScript in a 30-minute call.
We pair with your engineer, ship the integration live, and run the first decision on your stack.