Start here
Keys and security
Which key where
Publishable sp_pk_… | Secret sp_sk_… | |
|---|---|---|
| Where | Browser code | Your server only |
| Protection | Works only from the app's allowed websites (the browser's Origin) | Refused (403 SECRET_KEY_IN_BROWSER) if it ever arrives from a browser |
| Limits | Per key and per visitor IP | Per key, and per shopper if you send X-Buyer-IP |
Recommended architecture (the starter does this): every API call goes through your server with the secret key; the browser talks only to your server. Use the publishable key only if you call the API straight from the browser.
Forward shopper details from your server
With the secret key, all your traffic comes from your server's IP. Send each shopper's details so limits apply per shopper and the merchant's analytics show real locations and devices:
X-Buyer-IP: 203.0.113.9
X-Buyer-User-Agent: Mozilla/5.0 …
const client = base.withBuyer({ ip: shopperIp, userAgent: request.headers.get('user-agent') });
Only send an IP you got from your own trusted proxy or platform, never one the browser chose.
Shopper tokens
Shopper access tokens (15 minutes) and refresh tokens (30 days, rotating) identify a person. Keep them in httpOnly, Secure, SameSite cookies set by your server, never in localStorage. See Shopper login.
Checklist
- The secret key exists only in server environment variables (never
NEXT_PUBLIC_…, never committed). - Every website that calls the API from a browser is on the app's allowed websites, using
https://. - Shopper tokens live in httpOnly cookies; logout calls
POST /v1/auth/logout. - Your server forwards
X-Buyer-IPandX-Buyer-User-Agent. - Merchant-written HTML (
content_htmlin pages and blog posts) is sanitised before rendering, for example with DOMPurify. - Order success is read from
GET /v1/orders/{id}, never assumed from a payment widget's callback. -
POST /v1/checkoutsuses oneIdempotency-Keyper checkout attempt. - Prices shown at checkout come from a quote, not from numbers kept in the browser.
If a key leaks
Tell us (or the merchant) immediately: the key is revoked within a minute and a new one issued. Revoking an app also ends every shopper session created through it.