API keys
Every request carries a key. Each key belongs to one knowledge group and can only read that group’s documents.
Key types
| Publishable | Secret | |
|---|---|---|
| Prefix | pk_live_ | sk_live_ |
| Use it for | The website widget, in the browser. | The REST API, from your server. |
| Safe to expose | Yes. It is meant to be public. | No. Keep it in an environment variable. |
| Origin check | Yes, against the allowed origins. | No. |
The widget refuses to start with a secret key, and the widget configuration endpoint rejects it, so a leaked script tag cannot expose one by accident.
Create and revoke
In Studio, open a group, go to Keys and generate a key. The full key is shown once. Docket stores only a hash of it, so a lost key cannot be recovered: generate a new one and delete the old one.
Deleting a key in Studio revokes it. Docket caches successful key checks for up to 30 seconds, so a revoked key can keep working for that long.
Allowed origins
A publishable key is only accepted from sites on its allowed list. The browser sends the site’s origin with each request and Docket compares it with the list. Each entry can be:
- A host, such as
example.comorlocalhost:3000. - A wildcard for subdomains, such as
*.example.com. *to allow any site.
An empty list also allows any site, which is convenient while developing.
Keys made in Studio allow any origin
A key created in Studio is saved with* as its allowed origins. That list is checked before the group’s own setting, so for now the group’s allowed origins do not narrow it.