Keys
Secret, publishable, agent, and branch-only keys — where each one goes, and how to mint, reset, rotate, and delete them.
Every request to https://data.shipmantis.com carries a project key. The key says which project
the request is for and what it may do. Mantis has four key kinds:
Secret (mk_secret_) | Publishable (mk_pub_) | Agent (mk_agent_) | Branch-only (mk_branch_) | |
|---|---|---|---|---|
| Lives in | Your server, workers | Your app in the browser | Coding agents (MCP / CLI) | Sandboxed agents & CI preview jobs |
| Environment variable | MANTIS_SECRET_KEY | MANTIS_PUBLISHABLE_KEY | MANTIS_SECRET_KEY | MANTIS_SECRET_KEY |
| Queries and files | Every row and file; skips access rules. Write guardrails apply on main. | Only what access rules allow. Nothing by default. | Every row and file; attributed as agent. Write guardrails apply on main. | Read on main; full read/write on non-main branches. Writes to main are refused (403). |
| Schema, branches, snapshots, rewind | Yes (destructive steps on main held for approval) | No | Yes (destructive steps & rewinds on main held for approval) | Branches, snapshots, and migrations on non-main branches only; cannot modify main. |
A project starts with one secret + publishable pair, made with the project. Each machine that runs
init against that project later gets its own pair. You can also mint
standalone agent or branch_only keys from the project's Keys panel in the
dashboard.
Which key a request needs
| Request | Secret | Agent | Branch-only | Publishable |
|---|---|---|---|---|
POST /v1/query (select) & live queries | Yes | Yes | Yes | Yes, through rules |
POST /v1/query (insert, update, delete) | Yes (guarded on main) | Yes (guarded on main) | Non-main branches only | Yes, through rules |
/v1/auth/* (built-in auth) | Yes | Yes | Yes | Yes |
/v1/storage/* (files) | Yes | Yes | Non-main reads | Yes, through file rules |
/v1/schema/*: read, plan, apply, undo | Yes | Yes | Non-main apply/undo; read/plan anywhere | No |
/v1/branches/*, /v1/branches/*/snapshots, reset | Yes | Yes | Non-main branches (cannot promote to main) | No |
/v1/changes/{id}, /v1/activity | Yes | Yes | Yes | No |
/v1/webhooks/deliveries, /v1/crons/*/run | Yes | Yes | Non-main branches | No |
/v1/rewind/* | Yes | Yes | Non-main branches only | No |
A publishable key sent where a secret or agent key is needed is refused with 403. A branch_only
key attempting to write data, apply migrations, promote, or rewind main is also refused with 403.
Sending a key
The SDK sends the key for you. Pass the one that fits where the code runs:
import { createClient } from "@shipmantis/sdk";
import schema from "../mantis/schema";
export const mantis = createClient({
url: process.env.MANTIS_URL!,
key: process.env.MANTIS_SECRET_KEY!,
schema,
});MANTIS_URL=https://data.shipmantis.com
MANTIS_SECRET_KEY=mk_secret_...The Laravel package reads them from .env; plain PHP reads them from the environment with
Mantis::fromEnvironment(). PHP only ever needs the secret key, because it runs on your server.
The publishable key belongs to a browser script that uses the JavaScript SDK, and goes to the
page through your own config, never from .env as a whole.
Without the SDK, send the key as a bearer token. Mantis-Branch picks a
branch; leave it out for main.
curl https://data.shipmantis.com/v1/schema \
-H "Authorization: Bearer $MANTIS_SECRET_KEY" \
-H "Mantis-Branch: try-tags"| Header | What it holds |
|---|---|
Authorization | Bearer <key>. Required on every /v1 request. |
Mantis-Branch | A branch name. Optional; main without it. |
Mantis-User-Token | The signed-in user's JWT, for access rules or built-in auth. |
Mantis-Actor | Optional actor label (up to 80 chars) recorded in the Agent Activity Feed, e.g. claude-code. |
A live query sends the key once, when its connection opens, and the branch as a connection parameter. The SDK does both.
Where each key goes
| Place | Key | How |
|---|---|---|
| Your laptop | Both, its own pair | init writes them to .env.local. |
| A Next.js app on Vercel, Netlify or your own server | Secret on the server, publishable for the browser | Set MANTIS_SECRET_KEY and NEXT_PUBLIC_MANTIS_PUBLISHABLE_KEY in the host's environment variables. |
| CI | Secret, its own pair | A repository secret, read as MANTIS_SECRET_KEY by the steps that push or branch. |
| A mobile or desktop app | Publishable only | Bundled with the app; anything that needs the secret key goes through your server. |
| A worker or cron job | Secret, its own pair | Its environment, so it can be reset alone. |
| Your agent | Secret | .env.local, read by the MCP server. |
A pair per machine
Every key has a name, and the two keys of a pair share it. The first pair has no name; the dashboard lists it as Made with the project.
Running init on a project that already has keys makes a new pair named after the machine,
like work-laptop, mantis init, and writes it to that folder's .env.local. The keys on every
other machine keep working.
To make a pair yourself, open the project in the dashboard, type a name under New key pair (up to 64 characters), and press Add. A pair for your production server, one for CI and one per teammate's laptop means any one of them can be reset or deleted without touching the others.
Shown once
Mantis keeps a SHA-256 hash of each key, never the key itself. The full key is shown exactly
once: in the init output and .env.local, or in the dashboard right after you add or reset
it. After that the dashboard shows only its first 16 characters, like mk_secret_BS5QFt…, to
tell keys apart.
A lost key can't be recovered. Reset it, or add a new pair.
Reset or delete
Both are on the project's page in the dashboard, next to each key, and both ask before they do anything.
| Reset | Delete | |
|---|---|---|
| The key | Stops working at once | Stops working at once |
| A replacement | A new key of the same kind and name, shown once | None |
| Use it when | The key leaked, but the place that used it still needs one | The machine or service is gone, or you rotated it out |
| The other key of the pair | Untouched | Untouched |
Neither can be undone. To get a deleted key's place back, add a new pair.
Deleting every key leaves the project unreachable from code until you add a new pair. The dashboard and your data are not affected.
Rotating without downtime
A reset stops the old key before you have put the new one in place. To swap a key on a running service without a single refused request, overlap them:
Add a new pair
Under New key pair, name it after the service and today's date, like production 2026-10.
Copy both keys.
Deploy with the new keys
Set MANTIS_SECRET_KEY and MANTIS_PUBLISHABLE_KEY on the service and deploy. Both pairs work
in the meantime.
Delete the old pair
Once every instance runs the new keys, delete the old pair's two keys. Anything still on them is refused from its next request.
If a key leaks
A leaked secret key can read and change every row, change the schema and rewind. Treat it as an incident.
Reset it
Reset the key in the dashboard. It stops working on its next request.
Put the new key where the old one was
Update .env.local, your host's environment variables and CI. Requests with the old key are
refused until they have the new one.
Check what happened
Mantis records every write. Preview a rewind to the time the key leaked to see what has changed since, and apply it if the key was used against you.
A leaked publishable key is expected: every visitor to your site has it. What protects your data is the access rules. Reset it only if you want to cut off a copy of your app that uses it.
When a reset or delete takes effect
Every HTTP request looks its key up again, so the next request with a reset or deleted key is refused.
A live query checks its key when its connection opens. A connection that is already open keeps receiving updates until it closes, for example when the page is reloaded; it can't reconnect with the old key.
Keys and branches
Every key belongs to its project's main. There are no branch keys: any key can reach any
branch by naming it, through Mantis-Branch, --branch, MANTIS_BRANCH or
createClient({ branch }). A request for a branch that doesn't exist is refused with 404.
Keys and your agent
The MCP server and the CLI read MANTIS_SECRET_KEY from .env.local, then .env.
You can put a secret, agent (mk_agent_), or branch_only (mk_branch_) key in
MANTIS_SECRET_KEY:
- Use an
agentkey so every agent action is labeled in the Agent Activity Feed while schema drops, mass writes, and rewinds onmainwait for human approval. - Use a
branch_onlykey when you want an agent or CI runner to experiment freely on branches without ever being able to mutatemain.
init adds .env.local to .gitignore, and the instructions it writes for every agent tell it
never to print or commit any key. If one ever leaks, reset the key.
Errors
The SDK throws a MantisError with the status and the message:
import { MantisError } from "@shipmantis/sdk";
try {
await mantis.from("todos").select();
} catch (error) {
if (error instanceof MantisError && error.status === 401) {
// The key is missing, mistyped, reset or deleted.
}
throw error;
}The client throws a MantisException with the status and the message:
use Shipmantis\Mantis\MantisException;
try {
Mantis::table('todos')->select();
} catch (MantisException $error) {
if ($error->status() === 401) {
// The key is missing, mistyped, reset or deleted.
}
throw $error;
}| Status | Message | What to do |
|---|---|---|
401 | Send a valid project key as Authorization: Bearer <key>. | The key is missing, mistyped, reset or deleted. Copy the current one, or add a new pair. |
403 | This needs the project's secret key, not the publishable one. | Run that call on your server, with the secret key. |
404 | There is no branch "…". | Check the branch name with npx shipmantis branch list. |
400 | Send one Mantis-Branch header. | The request sent the header twice. |