# Validakey > Payment-backed access tokens (vKeys). Use the official PHP SDK for the sealed token path; do not hand-roll envelopes. ## Human docs - https://validakey.com/docs/getting-started/ - https://validakey.com/docs/access/ - https://validakey.com/docs/php-client/ - https://validakey.com/docs/ai/ ## Machine contracts - https://validakey.com/openapi.json — OpenAPI 3.1 (envelope ops are SDK-only on the wire) - https://validakey.com/llms-full.txt — full agent guide - https://validakey.com/ai/skill/ — Cursor/Claude Agent Skill ## Interactive reference - https://validakey.com/explorer/ ## Rules for coding agents 1. Integrate via `composer require validakey/validakey-php` and `Validakey\ValidakeyClient`. 2. Licence/token path never uses the account private key (`VALIDAKEY_API_PKEY`). 3. Handshake → Instance ID → mint/validate/renew; persist the instance id (e.g. `FileInstanceStore`). 4. Do not invent envelope crypto or POST cleartext JSON to `/v1/i/`, `/v1/m/`, `/v1/v/`, `/v1/r/`, `/v1/t/`, or `/v1/p/`. 5. Account APIs (`/v1/u/`, `/v1/billing/*`, `/v1/apps/`, …) use `Authorization: Bearer ` from a server you control only. --- # Agent rules (Validakey) ## Do - Install and call `validakey/validakey-php` (`ValidakeyClient`, `ValidakeyConfig`). - Set env: `VALIDAKEY_BASE_URL` (e.g. `https://validakey.com/v1`), `VALIDAKEY_API_UUID`, `VALIDAKEY_USER_APP_ID`, optional `VALIDAKEY_SUBJECT`. - Persist Instance ID for long-lived processes (`Validakey\Instance\FileInstanceStore`). - Use `createToken()`, `verifyToken()`, `renewToken()`, `deleteToken()`, `rotateInstance()`, `forSubject()`. - Keep account private key on your billing/admin server only. - For software you ship to end users: enable **mint policy** on the User App (fixed price + duration/uses limits). Query `POST /v1/policy/` so clients discover required mint parameters from the server. ## Do not - Hand-roll Feistel/envelope sealing or guess the wire field (`q`). - Ship `VALIDAKEY_API_PKEY` / account private key inside end-user or mobile apps. - Call sealed routes with cleartext JSON bodies. - Re-handshake on every request when a stored Instance ID is still valid (prefer client reuse / `rotateInstance()`). - Trust client-supplied `basis_cents` / duration / uses for distributed licensing without mint policy enabled. ## When stuck 1. Read https://validakey.com/llms-full.txt 2. Read https://validakey.com/ai/skill/ 3. Check https://validakey.com/openapi.json for route inventory (SDK-only markers on envelope ops) 4. Human docs: https://validakey.com/docs/getting-started/ --- # Getting started (agents) ## Install ```bash composer require validakey/validakey-php ``` Load Composer’s autoloader in application bootstrap. ## Credentials | Env / value | Role | |-------------|------| | `VALIDAKEY_BASE_URL` | API root, e.g. `https://validakey.com/v1` | | `VALIDAKEY_API_UUID` | Account UUID (UUIDv4) | | `VALIDAKEY_USER_APP_ID` | User App ID — keys handshake; ships with production code but keep it private | | `VALIDAKEY_SUBJECT` | Optional end-customer subject for multi-tenant apps | | `VALIDAKEY_API_PKEY` | Account Bearer key — **account path only**; never in distributed licence clients | ## Configure and mint ```php use Validakey\ValidakeyClient; use Validakey\ValidakeyConfig; use Validakey\CreateTokenRequest; use Validakey\Instance\FileInstanceStore; $config = new ValidakeyConfig( baseUrl: getenv('VALIDAKEY_BASE_URL'), apiUUID: getenv('VALIDAKEY_API_UUID'), userAppId: getenv('VALIDAKEY_USER_APP_ID'), apiPKey: getenv('VALIDAKEY_API_PKEY') ?: null, subject: getenv('VALIDAKEY_SUBJECT') ?: null, ); $client = new ValidakeyClient( $config, null, new FileInstanceStore('/var/lib/myapp/validakey-instance.json'), ); $token = $client->createToken(new CreateTokenRequest(duration: 3600)); echo $token->token; ``` `createToken()` handshakes automatically when no Instance ID is stored. ## Next - Validate: `$client->verifyToken(...)` - Multi-tenant: `$client->forSubject('customer-42')` - Full guide: https://validakey.com/llms-full.txt --- # Access and authentication (agents) Validakey has two paths. ## Token path (licences) - Routes: `/v1/i/` handshake, `/v1/r/` rotate, `/v1/t/` transfer, `/v1/m/` mint, `/v1/policy/` mint policy, `/v1/v/` validate/renew/revoke, `/v1/p/` instance payment. - Auth: sealed envelope under User App ID or Instance ID. - **Always use `validakey-php`.** Wire body is `{ "q": "" }` — cleartext never goes on the wire. - No account private key on this path. - **Mint policy:** opt-in per User App. When enabled, omitted mint fields use server defaults; values outside limits → `mint_policy_violation`. Billing mode may be **Single** or **Recurring** (`auto_renew`; duration is the renewal interval in seconds). Perpetual defaults and recurring are mutually exclusive. For distributed licensing, enable policy and set a fixed price (`basis_cents_min == basis_cents_max`); never trust client-supplied prices. Discover policy via instance-sealed `POST /v1/policy/`. Configure via dashboard or account `PATCH /v1/apps/` (`mint_policy`). Identity chain: 1. Account UUID → User App ID (dashboard or account API). 2. App ID + account UUID + subject + fingerprint → Instance ID (`POST /v1/i/`). 3. Instance ID → mint / policy / validate / renew / revoke / rotate / customer card. Subject names the end customer; the PHP client can generate one if omitted. ## Account path (your server) - Routes: `/v1/u/`, `/v1/billing/*`, `/v1/apps/`, `/v1/instance/`, `/v1/usage/`, `/v1/payout/*`. - Auth: `Authorization: Bearer ` plus `api_user_id`. - OpenAPI documents these fully. Never embed `api_pkey` in software shipped to end users. ## Validation scope Validating a vKey matches the calling instance’s account, application, and subject. Mismatch → `not_found`. --- # PHP client (agents) Package: `validakey/validakey-php` (1.7.x line). Configure via `ValidakeyConfig` or env: `VALIDAKEY_BASE_URL`, `VALIDAKEY_API_UUID`, `VALIDAKEY_USER_APP_ID`, `VALIDAKEY_SUBJECT`, optional `VALIDAKEY_API_PKEY`. ## Core licence methods | Method | HTTP | Notes | |--------|------|--------| | `createToken()` | `POST /v1/m/` | Reuses stored instance; handshakes when needed. Respect app mint policy: omit price/shape so defaults apply | | `getMintPolicy()` | `POST /v1/policy/` | Instance-sealed; returns `MintPolicyResponse` (`enabled`, `defaults`, `limits`) | | `verifyToken()` | `POST /v1/v/` | Read-only unless consume is true | | `renewToken()` | `POST /v1/v/` | Extends time/uses without changing token value when applicable; renew adds also respect mint policy limits | | `deleteToken()` | `DELETE /v1/v/` | Revokes; record retained | | `rotateInstance()` | `POST /v1/r/` | Retires current Instance ID; preferred over repeating handshake | ## Multi-tenant ```php $alpha = $client->forSubject('customer-42'); $token = $alpha->createToken(new \Validakey\CreateTokenRequest(duration: 86400)); ``` ## Persistence Default Instance ID is in-memory. For concurrent or long-lived processes use `Validakey\Instance\FileInstanceStore` (path outside web root). ## Host Base URL for this deployment: `https://validakey.com/v1` Explorer: https://validakey.com/explorer/ OpenAPI: https://validakey.com/openapi.json