How API key authentication works
The service issues a string — a random sequence, usually 32 to 64 bytes in base64 or hex. On every
request the client passes it in an HTTP header:
GET /api/recommendations?user_id=123
Authorization: Bearer sk-live-abc123def456...
or
X-API-Key: sk-live-abc123def456...
The server verifies the key, determines whose it is and what rights it carries, and responds
accordingly.
Access levels in an e-commerce integration
A correct architecture issues several keys with different rights:
| Key type | Where it is used | Rights |
|---|---|---|
| Public (frontend) | JavaScript on the site | Read only: fetching recommendations, widgets |
| Private (backend) | Server, CI/CD | Writing events, managing configuration |
| Server write-only | An event collector | Writing events with no read access |
A public key may sit in client code — but only when it is strictly read-only and bound to allowed
origin domains.
Common mistakes
- A private key committed to a repository — automated scanners find it within minutes of publication
- One key for every service — compromising it opens everything
- Keys never rotated for years — after a leak there is no way to know when the exposure started
- Keys in URL parameters — they end up in server logs, proxies and browser history