Create, rotate and revoke API keys for CI and agents
Use metorial-admin api-keys to give each pipeline or agent its own key with an expiry and IP allowlist, rotate it with a grace period and revoke a leaked one.
Give every pipeline and every agent its own API key, so you can rotate or revoke one without touching the others. metorial-admin api-keys create makes a key with an optional expiry date and IP allowlist, rotate replaces its secret, and revoke turns it off at once. The secret is shown one time, when the key is created.
What you'll learn
- How to create a key for one instance or for the whole organization
- How to limit a key by expiry date and IP address
- How to rotate a key, and revoke it after a leak
Before you start
- The
metorial-adminCLI, signed in (install and sign in) - The ID of the instance the key is for, from
metorial-admin instance list
Choose a key type
--type takes one of three values:
| Type | What it is for |
|---|---|
instance_access_token_secret | Server-side access to one instance. Needs --instance-id. Use this for CI and agents. |
instance_access_token_publishable | A publishable key for one instance. Needs --instance-id. |
organization_management_token | Managing the organization itself. Not tied to an instance. |
Secret keys start with metorial_sk_ and publishable keys with metorial_pk_.
Create a key
Create the key
Name the key after the thing that uses it. Add --expires-at and --ip-filters to narrow it.
Store the secret
The response contains the key's ID and its secret. Copy the secret into your CI system's secret store now. Later get and list calls show a redacted form only.
Use it
Set the key in the environment of the job or agent:
The SDKs and the API read the same key. See the API for the request header.
List and inspect keys
Each key shows its status, type, name, IP filters and when it was last used. A key you no longer recognize, or one that has not been used for months, is a candidate for revoking.
metorial-admin api-keys reveal <api-key-id> returns the secret of an existing key again.
Change the limits on a key
update also takes --name and --description. It has no flag for the type or the instance. To change those, create a new key.
Rotate a key
Rotation gives the key a new secret. Pass --current-expires-at to keep the old secret valid until that time, so you can roll out the new one without downtime.
Store the new secret from the response, update the job or agent, and let the old one expire.
Revoke a key after a leak
If a secret was committed, logged or shared, revoke the key first and investigate second.
Then check what the key did. The organization audit log and the session logs are both available from the CLI. See See what happened from the terminal.
A leaked MCP URL is a different credential. If the URL contains ?key=, delete that token:
Give each agent its own limited credential
The CLI lets you limit an API key in three ways: to one instance, to a set of IP addresses, and to an expiry date. It has no flag for limiting a key to certain resources or actions.
For an agent that only needs to call tools over MCP, a Magic MCP token is the narrower credential. It reaches only one server, one endpoint or a named group of servers. See Magic MCP from the terminal.
In the dashboard
Keys for an instance are under Developer, API Keys, where Create API Key opens the same options.
Check it worked
Run a read-only command with the new key and no saved profile, for example in a clean shell:
After revoke, the same command fails with an authentication error.