All guides
Updated
Reading
10 min
By
Anlyon Team

How to rotate an API key used by an AI agent without breaking pending actions

Rotate or revoke the provider key behind an AI agent's actions: what happens to approved requests waiting to run, to unresolved outcomes that still need a read-back, and to the agent's own Anlyon key.

  • credential rotation
  • secrets
  • revocation
  • approvals
  • operations

To rotate a provider key behind an AI agent's actions, write the new value to the same vault secret with secrets.put. The next dispatch uses it, and the agent never sees either value. The risk is not the swap itself. It is the work already in flight: approved requests resolve the credential when they run, not when they were approved, and unresolved outcomes still need the provider to answer a read-back.

TL;DR

  • Rotate with secrets.put on the same name. Omitting allowedHosts keeps the existing list, so rotation never widens where the secret may go.
  • The vault is write-only. No API returns a secret's value, so verify a rotation by running a controlled action, not by reading the key back.
  • An approval does not preserve a credential. A secret removed or rebound after review refuses the dispatch with credential_unavailable, graded refused.
  • Reconciliation uses the current vault value. Keep the replacement on the same provider account, with read access, until open effects settle.
  • Revoking the agent's Anlyon key is a different intervention. Its pending effects are refused at dispatch with authority_revoked.

Which credentials are involved, and which one are you rotating?

There are at least three credentials on the path of one agent action, and each revocation means something different. Record which one changed and when.

CredentialWho holds itWhat revoking it does
Provider key (Stripe, GitHub, Resend, your API)The Anlyon vault, referenced by nameThe next dispatch and every later read-back resolve whatever the vault holds then
Agent's Anlyon key, actions:invokeThe agent's processCalls with it get HTTP 401. Effects it requested are refused at dispatch with authority_revoked
Operator key, secrets:write, actions:writeYour deploy script or runbookNo new secrets or action edits from that key. Existing actions keep running

The agent holds an Anlyon credential, not the provider key. That is the reason rotation is an operator task with one place to change: the provider key was never copied into prompts, environment variables of the agent, or tool code. If it was, see AI agent secrets management before rotating, because a copy outside the vault is a second execution path that rotation in the vault does not touch.

An invalid, expired or revoked Anlyon key gets the same answer, HTTP 401. The response does not say which of the three it was, so your logs should.

How does a rotation work?

secrets.put() on an existing name replaces the value. Writing a secret needs secrets:write. Defining or editing an action that references a secret needs secrets:read, because a reference is a use. Invoking that action needs actions:invoke and nothing else.

Each secret can carry its own destination policy:

  • allowedHosts: the hosts it may be sent to. A leading dot matches subdomains, so .stripe.com admits api.stripe.com. Checked when an action is authored and again at dispatch against the host actually called.
  • allowedPlacements: url, header or body. Checked again at dispatch on a declared action. On an action with no declaration, a tightened placement applies at the next edit.

Omitting allowedHosts on a rotation leaves the existing value alone. Passing null clears it, which means any public host. Do not pass null during a rotation unless you mean it.

import { Client } from '@anlyonhq/sdk';

const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

// 1. Inventory: which actions reference this secret?
const NAME = 'STRIPE_KEY';
const { data: actions } = await ops.actions.list();
const dependents = actions!.filter(
  (a) =>
    a.adapter?.credentialSecret === NAME ||
    JSON.stringify([a.urlTemplate, a.headers, a.bodyTemplate]).includes(`{{secret:${NAME}}}`),
);
console.log(dependents.map((a) => a.name));

// 2. Current binding and last use. Metadata only: no method returns the value.
const { data: secret } = await ops.secrets.get(NAME);
console.log(secret!.allowedHosts, secret!.allowedPlacements, secret!.lastUsedAt);

// 3. Rotate. allowedHosts is omitted, so the existing host list is kept.
await ops.secrets.put(NAME, { value: process.env.NEW_STRIPE_KEY! });

The key itself should come from your secret manager or the provider's console, never from a prompt, a chat message or an incident note. Record the rotation time and the secret name, never the value.

What happens to an approved request when the credential changes?

Anlyon executes the approved request snapshot using the credentials bound to that action. The snapshot freezes what the approver reviewed. It does not preserve a credential that has since been revoked, and destination bindings are checked again at dispatch.

So the outcome depends on what changed between approval and dispatch:

Change after approvalWhere it stopsGrade
Secret rotated to a new valid valueIt runs with the new valueWhatever the provider returns
Secret deleted, or its host or placement binding now excludes the requestDispatch, credential_unavailable, nothing sentrefused
Provider key revoked at the provider, vault unchangedThe provider rejects the requestfailed
Agent's Anlyon key revoked, or lost actions:invokeDispatch, authority_revoked, nothing sentrefused
Action edited, for example to reference a different secretDispatch, action_changed, nothing sentrefused

None of these is "the approver rejected it". The approver may have decided correctly while the environment changed afterwards. Report a changed execution prerequisite as exactly that, in your tool result and in your incident record. Approval drift caused by the request or the provider, rather than the credential, is covered in what happens when an approval expires or the request changes.

A refusal at dispatch writes an invocation error of the form Dispatch refused (<reason>): <message>, and the effect carries the same rejectionReason. Read it before deciding what to restore.

Why do pending and unknown effects matter during a rotation?

Reconciliation reads the provider with whatever the vault holds when it runs. That is what makes rotation safe for outcomes, and also what makes a careless rotation harmful:

  • A Stripe refund whose response was lost is looked up by refund id or by the anlyon_effect metadata on the payment intent. A key for a different Stripe account will not find it.
  • A Resend send is read back by email id, or found by a bounded scan for the effect tag. The Resend adapter needs a full access key. A sending access key cannot read back, so a confirmed receipt becomes impossible after a downgrade.
  • A declared action repeats its verify read-back with the action's own headers, so the same secret and the same bindings apply.

When the provider cannot be reached, a reconciliation attempt records that it could not reach the provider and leaves the outcome unchanged. Reconciliation stops after 12 attempts. After that the effect stays unknown, with its allowance held, until an operator resolves it. A rotation that breaks read access can turn a recoverable outcome into a manual one.

Check open work before you revoke anything:

import { Client } from '@anlyonhq/sdk';

const ops = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

// Effects still holding capacity: pending, unknown or possibly partial.
const { data: open } = await ops.actions.effects({ unresolved: true });
for (const effect of open ?? []) {
  console.log(effect.id, effect.action.name, effect.outcome, effect.reconciliation);
}

// Requests waiting for a decision. They will resolve the credential when they run.
const { data: waiting } = await ops.approvals.list({ status: 'pending' });
console.log(waiting?.length, 'approvals pending');

// After the rotation, ask the provider about one open effect now. Read-only.
if (open?.[0]) await ops.actions.reconcileEffect(open[0].id);

reconcileEffect never writes. If it settles an effect with the new key, the key can read. For the full runbook on unresolved outcomes, see how to reconcile an unknown agent action.

What should you check about the replacement key?

A valid key can still be the wrong key. Validate the replacement against the actions that use it, not just against the provider's authentication endpoint.

CheckWhy it matters
Same provider accountLookups for earlier effects search this account
Mode matches the adapter configstripe.refund with mode: "live" needs sk_live_ or rk_live_, and mode: "test" needs sk_test_ or rk_test_
Write and read permissionsExecution and read-back are separate capabilities
Resend key is full accessThe read-back and the lookup use it
allowedHosts and allowedPlacements unchangedDestination restrictions survive the rotation
No agent-side copyA copy outside the vault is an execution path rotation does not reach

Then exercise one controlled operation through the action: a refund on a test payment, a file update on a fixture branch, an email to a recipient you control. Read its receipt. A confirmed grade shows the new key could both write and read back. A refused grade with credential_unavailable points at the secret or its bindings.

In what order should you rotate?

  1. Inventory. List the actions that reference the secret, their environments and their provider accounts. Secrets belong to an environment, so staging and production have their own.
  2. Check open work. Pending approvals, pending provider results and unknown effects. Settle what you can and assign an owner to the rest.
  3. Create the new key at the provider with the same account and the permissions the adapter needs.
  4. Rotate in the vault with secrets.put, leaving the bindings as they are.
  5. Run one controlled action and read its receipt.
  6. Reconcile one open effect, if any, to prove read access.
  7. Revoke the old key at the provider once open effects no longer depend on it.

If you are revoking because of a suspected leak, the order changes: revoke first, accept that open effects may need operator resolution, and consider halting the environment while you look. A halt stops new dispatch. A request an external server already accepted is not recalled. See how to resume after an environment halt.

How do you recover without broadening access?

When a refusal points at a credential, restore only the intended credential and destination binding. Keep the original request for comparison, and decide whether a fresh preview and approval are needed. A different provider account or target deserves an explicit review, not a quiet resend.

Two shortcuts are tempting during an incident and both widen what the agent can do:

  • A wildcard host binding as a temporary fix. allowedHosts: null lets the secret go to any public host. Fix the binding you meant instead.
  • Moving the provider key into the agent's runtime to get past a failed hosted call. That creates an execution path outside the limit, the bound approval and the receipt you are trying to repair. Anlyon governs the actions routed through its hosted executor, and a call your own code makes directly is not one of them.

The local approval gate (approvals.gate) is not a substitute either. It waits for a decision and then your process runs your function with your credential, so the provider key would be back in your process.

Exercise the failure path in staging before you need it: create a request that waits for approval, delete or rebind its secret, approve it, and read the credential_unavailable refusal. Then restore the secret, refresh the preview and run it again. The reference for bindings and rotation is Secrets, and the dispatch checks are listed in When approval expires or changes.

Frequently asked questions

How do I rotate an API key that an AI agent uses through Anlyon?
Call secrets.put with the same secret name and the new value, from an operator key. The next dispatch resolves the new value. Omitting allowedHosts on a rotation leaves the existing host list in place, so a rotation never widens where the secret may be sent. The agent's process is not involved, because it never held the provider key.
What happens to an approved action if the credential is revoked before it runs?
Anlyon executes the approved request snapshot using the credentials bound to that action, and resolves the secret at dispatch. If the secret is missing, or its host or placement binding no longer allows the request, dispatch is refused with credential_unavailable, the receipt grades refused, and nothing is sent. The approval does not preserve access to a revoked credential.
Can I revoke the old provider key as soon as the new one is stored?
Not before checking unresolved work. Reconciliation of an unknown or pending effect reads the provider with whatever the vault holds now. If the new key belongs to a different account or lacks read access, those lookups cannot settle the effect and its allowance stays held. Resolve or reconcile open effects first, and confirm the new key can read back.
What happens to pending approvals if I revoke the agent's own Anlyon key?
The key that requested an effect must still be active at dispatch. If it was revoked, or no longer holds actions:invoke, an approved effect is refused at dispatch with authority_revoked and grades refused. Calls made with the revoked key itself get HTTP 401, the same answer as an invalid or expired key.

Let your agent act for your users, safely.

A few lines of server code, then send a user a connect link. Nothing to host.

$ claude mcp add --transport http anlyon https://api.anlyon.com/mcp