API keys
Create API keys for servers, functions, scripts and CI, attach policies to them, and rotate them safely.
An API key is a static credential for machines. Use it from servers, functions, scripts, CI pipelines and the CLI.
HTTP
Authorization: APIKEY cosc0XtrpGVIzKPP4Q1tvR9X5mJZRdta
Create a key
Terminal
curl -X POST https://api.example.com/api/passport/apikey \
-H "Authorization: IDENTITY <token>" -H "Content-Type: application/json" \
-d '{"name": "Website", "description": "Server-side rendering of the public site", "active": true}'JSON
{
"name": "Website",
"description": "Server-side rendering of the public site",
"active": true,
"key": "cosc0XtrpGVIzKPP4Q1tvR9X5mJZRdta",
"policies": [],
"_id": "6b0b1afaa5611972c29c263c"
}A new key has no policies. Attach the ones it needs:
Terminal
curl -X PUT https://api.example.com/api/passport/apikey/<apikeyId>/policy/BucketReadOnlyAccess \
-H "Authorization: IDENTITY <token>"Manage keys
| Endpoint | Action |
|---|---|
GET /passport/apikey | passport:apikey:index |
GET /passport/apikey/:id | passport:apikey:show |
POST /passport/apikey | passport:apikey:create |
PUT /passport/apikey/:id | passport:apikey:update |
DELETE /passport/apikey/:id | passport:apikey:delete |
PUT /passport/apikey/:id/policy/:policyId | passport:apikey:policy:add |
DELETE /passport/apikey/:id/policy/:policyId | passport:apikey:policy:remove |
Set active to false to suspend a key without deleting it.
API keys and rules
API keys are checked against their policies only. Bucket rules don't apply to them, so a key that can read a bucket sees every document in it, drafts included.
Good practices
- One key per consumer. Create separate keys for the website, each function, CI, every integration and every AI agent using the MCP server, so you can revoke one without breaking the others.
- Least privilege. Prefer custom policies limited to the buckets and actions a consumer uses over the
*FullAccesspolicies. - Store keys as secrets in functions, and as protected variables in CI.
- Rotate regularly. Create a new key with the same policies, deploy it, then deactivate and delete the old one.
Keys for the CLI and CI
The CLI authenticates with an API key. Give the key used by spica apply the full-access policies of the modules you manage as code: BucketFullAccess, FunctionFullAccess, PolicyFullAccess, EnvVarFullAccess and SecretFullAccess.