API keys
Public and secret keys, rotate and revoke
API keys let your site, your app and your servers talk to Viakite. A public key goes in your website or app and only sends events. A secret key stays on your servers and reads and changes data through the API, limited to the scopes you give it. Keys belong to the organization and are managed in Settings → API keys.
Public and secret keys
| Public key | Secret key | |
|---|---|---|
| Starts with | pk_live_us_… | sk_live_us_… |
| For | Sending events from websites and apps | The API: reports, settings, members; server-side events |
| Where it lives | In the page or app; it is fine for anyone to see it | Servers and scripts only. Never in a browser or app |
| Projects | Exactly one | Any you pick, or every project |
| Scopes | None | At least one permission |
| Shown | Any time | Once, when created or rotated |
A key reads as type, mode and region, then 32 random letters and digits: sk_live_us_…. The region (us, the United States, today) is where the organization's data lives. test in place of live makes a test key.
Events sent with a test key are stored apart from live data and left out of every report. They show only on the Install page, in the event debugger (marked test) and the Test data card; reports have no test view.
Public pages and embeds use a third kind, share tokens (st_…), made in Analytics → Sharing. See Public pages.
Create a key
Open Settings → API keys
Choose New key. You need
keys.create.Name it and pick its type
A name your team will recognise, such as "Backend reports" (up to 100 characters). Pick Secret or Public, and Live or Test.
Choose what it can reach
A public key needs its Project. A secret key needs its scopes and, optionally, its projects (see below).
Copy the key
A secret key is shown once. Copy it into your secret store, then choose I've copied it. Viakite keeps only a hash and can't show it again; if you lose it, rotate the key.
A project without a public key also offers Create public key on its Analytics → Install screen.
POST/v1/orgs/{org}/keys1curl -X POST https://api.vk.viabio.me/v1/orgs/org_…/keys \2-H "Authorization: Bearer sk_live_us_…" \3-H "Content-Type: application/json" \4-d '{"name": "Backend reports", "type": "secret", "mode": "live", "scopes": ["analytics.view"], "project_ids": ["prj_…"]}'
1{2"id": "key_…",3"name": "Backend reports",4"type": "secret",5"mode": "live",6"region": "us",7"prefix": "sk_live_us_ab12",8"key": "sk_live_us_…",9"scopes": ["analytics.view"],10"project_ids": ["prj_…"],11"last_used_at": null,12"expires_at": null13}
Scopes and projects
A secret key's scopes are permissions from the same list as members' roles (Permissions), so analytics.view reads reports and analytics.manage changes goals and funnels. Read only in the scope picker ticks every .view permission. Give a key only what its job needs.
- You can only give scopes you have yourself. Asking for more answers
forbidden(403). - A key's projects limit where it works. No projects means every project in the organization, including new ones. At most 100.
- A public key has no scopes; it sends events to its one project.
Use a secret key as a bearer token:
1curl https://api.vk.viabio.me/v1/orgs/org_…/keys \2-H "Authorization: Bearer sk_live_us_…"
More in Authentication.
Rename or change a key
From a key's row menu, Rename changes its name. Through the API you can also change a secret key's scopes and projects; fields you leave out stay as they are.
PATCH/v1/orgs/{org}/keys/{key}Rotate a key
Rotating makes a new key with the same name, type, scopes and projects, and keeps the old one working for 24 hours. Deploy the new key within that window, and nothing breaks.
Choose Rotate from the key's row menu
The new key is shown once. Copy it.
Deploy the new key
Replace the old value wherever it is used.
Let the old key run out
The old key's row shows when it expires, and it stops on its own after 24 hours. To end it sooner, revoke it.
Revoke a key
Revoke stops a key at once. Do it when a secret key may have leaked, then make a new one. Revoking needs keys.revoke. Revoked and expired keys leave the list.
What the list shows
Each key shows its name (with a test chip for test keys), the start of its value (sk_live_us_ab12…), its type, its scopes, when it was last used (or "never"), and when it was created. The API also gives who created it and its projects. Seeing keys needs keys.view. Creating, rotating and revoking keys are recorded in the audit log.
Rate limit
Each secret key may make 10 requests a second. Every answer to a secret key says where it stands:
| Header | What it says |
|---|---|
RateLimit-Limit | The requests this key may make each second |
RateLimit-Remaining | How many are left in this second |
RateLimit-Reset | Seconds until the count starts again |
Over the limit, the API answers 429 rate_limited with Retry-After in seconds; wait that long and send the request again. Each key counts on its own, so two services with two keys don't slow each other down. Requests from the dashboard, public keys and share links aren't counted, and neither are events sent to POST /v1/events.
On a paid plan, the Rate limit card in Settings → API keys raises it to 25, 50 or 100 requests a second for every secret key of the organization, at no cost. It takes effect within 30 seconds. Changing it needs keys.create and is recorded in the audit log. On Free it stays at 10, and an organization that moves back to Free goes back to 10.
1curl -X PUT https://api.vk.viabio.me/v1/orgs/org_…/api-rate-limit \2-H "Authorization: Bearer sk_live_us_…" \3-H "Content-Type: application/json" \4-d '{"requests_per_second": 100}'
Above 10 on Free answers 402 plan_required; outside 10 to 100 answers 422 validation_error.