# KRIN SDKs

> **Not live on production yet.** This guide follows the published API contract. Its steps work once these parts answer in production: TypeScript server SDK, PHP server SDK, Android SDK.

> KRIN has server SDKs for TypeScript and PHP, generated from the same OpenAPI file as the API, with helpers that sign wall links and verify reward postbacks. The Android SDK opens the wall in a hardened WebView and adds device integrity checks. Secrets stay on your server: client SDKs hold only a placement id.

Use an SDK to skip the plumbing: signing, retries, idempotency and typed errors. Everything an SDK does is also documented as plain HTTP, so you never depend on one.

> **Answer.** KRIN has server SDKs for TypeScript and PHP, generated from the same OpenAPI file as the API, with helpers that sign wall links and verify reward postbacks. The Android SDK opens the wall in a hardened WebView and adds device integrity checks. Secrets stay on your server: client SDKs hold only a placement id.

## Which one do I need?

| you are | use |
|---|---|
| A publisher with a website or web app | no SDK needed: a signed link and a postback handler ([quickstart](https://docs.krin.io/en/publishers/quickstart/web)). The server SDK saves you writing the signing code |
| A publisher with an Android app | the Android SDK in the app, plus a server SDK (or your own code) to sign sessions and verify postbacks |
| A publisher drawing its own offer UI | the headless Offer API from your server (quickstart) |
| An advertiser sending conversions | a server SDK's `signInboundPostback`, or the [S2S spec](https://docs.krin.io/en/advertisers/s2s) |
| Anyone automating KRIN | a server SDK. MCP for AI agents: Soon |

## Rules every SDK follows

- **No secrets in clients.** The JavaScript and Android SDKs hold only a placement id. Wall sessions start from a signed link or a session token your server creates. Placement secrets, API keys and postback secrets live only on servers.
- **Exact money.** Micro-USD amounts are integers and rewards are decimal strings; no SDK turns them into floating-point numbers. The TypeScript SDK refuses an unsafe integer and offers `bigint` accessors.
- **Versions.** Each request sends `Krin-Version`. A new API date is a new minor SDK version; a change that breaks callers is a new major version. The SDK's own version is in its `User-Agent`.
- **Tested against the spec.** Every SDK ships KRIN's published test vectors as unit tests, and a release fails if one doesn't match.

## Server SDKs: TypeScript and PHP

Both are generated from the public OpenAPI file, so every public operation is there, plus these helpers:

| helper | does |
|---|---|
| `signLaunchUrl(secret, params)` | builds a signed wall link, with the nonce and sorted sub-ids |
| `verifyRewardPostback(secrets[], request)` | checks a POST header or a GET `sig`, in constant time, with the 300-second limit and two secrets during a rotation; returns the typed postback |
| `verifyWebhook(secret, headers, rawBody)` | checks a webhook delivery |
| `signInboundPostback(secret, params)` | signs an advertiser's S2S conversion |
| `createSession(placementId, userId, opts)` | creates a wall session for Android and headless use |

How the clients behave:

- **Retries** on network errors, 429 and 5xx, with backoff and jitter, honouring `Retry-After`. A POST is retried only when it carries an `Idempotency-Key`.
- **Idempotency keys** are added to every money operation, and to any POST where you pass `idempotent: true`.
- **Typed errors** carry the problem `code` and the `request_id`.
- **`dryRun: true`** maps to `?dry_run=true` on every write that has it.
- **Pagination** with async iterators over `next_cursor`.

Until a package is published, the same signing and checking code is on each guide page in Node, PHP and Python, tested against the same vectors.

## Web wall events (JavaScript)

When the wall is in an iframe, it posts these messages to your page (origin checked both ways): `krin:ready`, `krin:resize {height}`, `krin:reward_pending {conversion_id}`, `krin:close`, `krin:open_external {url}`. See the [web quickstart](https://docs.krin.io/en/publishers/quickstart/web#6-open-or-embed-the-wall). `krin:reward_pending` only updates your UI; you credit on the signed postback.

## Coming next

iOS (with App Attest), Unity, React Native and Flutter wrappers, Python and Go server SDKs, and playtime and rewarded-video modules. They use the same API and the same signatures, so code you write today keeps working.

## FAQ

**Do I need an SDK to use KRIN?**
No. A signed link and a postback handler are enough for a web wall. The SDKs save code and add device integrity on Android.

**Can I put my API key in the Android app?**
No. Client SDKs take only a placement id and a session token from your server. Any key in an app can be extracted.

**Which Android versions are supported?**
The minimum Android version is set from Google's Play Integrity library requirements and published with the first release.

**Does the SDK track users in the background?**
No. It does no background work and includes no third-party analytics.
