MetorialDocs

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

Choose a key type

--type takes one of three values:

TypeWhat it is for
instance_access_token_secretServer-side access to one instance. Needs --instance-id. Use this for CI and agents.
instance_access_token_publishableA publishable key for one instance. Needs --instance-id.
organization_management_tokenManaging 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.

metorial-admin api-keys create \
  --type instance_access_token_secret \
  --instance-id <instance-id> \
  --name "ci-deploy" \
  --description "Deploy pipeline, main branch" \
  --expires-at 2027-06-30T00:00:00Z \
  --ip-filters 203.0.113.10,203.0.113.11

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:

export METORIAL_API_KEY=<secret>
export METORIAL_INSTANCE_ID=<instance-id>
metorial-admin sessions list --limit 1

The SDKs and the API read the same key. See the API for the request header.

List and inspect keys

metorial-admin api-keys list --type instance_access_token_secret --instance-id <instance-id>
metorial-admin api-keys list --type organization_management_token
metorial-admin api-keys get <api-key-id>

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

metorial-admin api-keys update <api-key-id> \
  --expires-at 2027-01-31T00:00:00Z \
  --ip-filters 203.0.113.10

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.

metorial-admin api-keys rotate <api-key-id> --current-expires-at 2026-12-01T12:00:00Z

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.

metorial-admin api-keys revoke <api-key-id>

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:

# A token you created as an admin
metorial-admin magic-mcp tokens delete <magic-mcp-token-id>

# A token the metorial CLI created when you ran install
metorial tokens revoke <token-id>

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:

METORIAL_API_KEY=<secret> metorial-admin instance list

After revoke, the same command fails with an authentication error.

Next steps