An AI agent’s API key in LumoAuth starts with agk_, and the agent sends it as a bearer token. LumoAuth shows the key once and stores only its SHA-256 hash. A new key expires after 180 days unless you choose another lifetime, in the portal or through the Admin API. To rotate a key, use the agent’s edit page or the Admin API, and pick the new key’s lifetime as you rotate. LumoAuth returns a new key and rejects the old one from that moment. Store the new key in the same step.
TL;DR
- An
agk_key is a bearer credential: whoever holds the string can act as the agent. LumoAuth stores only a SHA-256 hash, so it can show the key only once. - A new key expires after 180 days, unless you choose 30, 90 or 365 days, a date, or never. You choose in the portal or through the Admin API. After that date, LumoAuth answers every call that uses the key with
401. - Rotation replaces the key at once. The old key stops working in the same moment, so there is no period in which both keys are valid.
- You choose the new key’s lifetime when you rotate: 180 days by default in the portal, or
apiKeyExpiresInDayswith the Admin API call. - The agent’s page warns 14 days before the key expires. The audit log records every rotation, every revocation and every change of lifetime.
What is an agent API key?
An agent API key is a secret string for one AI agent. It has the prefix agk_, followed by 64 hexadecimal characters from a random 256-bit value. The agent sends the key in the Authorization header, like an OAuth access token:
ORG=acme-corp
curl -sS "https://app.lumoauth.dev/orgs/$ORG/api/v1/agents/me" \
-H "Authorization: Bearer $AGENT_API_KEY"
Only agents with the identity type api_key get one. The key itself is the credential. No client ID or second secret goes with it. LumoAuth uses three prefixes that are easy to confuse, so check which one you hold:
| Prefix | What it is | Secret? | What it can do |
|---|---|---|---|
agt_ |
The agent’s ID | No | Names the agent in URLs, logs and the Admin API |
agk_ |
The agent’s API key | Yes | Acts as the agent on the APIs for agents |
lmk_ |
An organization API key | Yes | Calls the Admin API, within its scopes and its creator’s permissions |
An agk_ key works only on APIs that are built for agents. Examples are the agent’s own identity and the Ask API (/agents/…), just-in-time permissions (/jit/…) and authorization checks (/api/v1/authz/check). LumoAuth rejects the key on the portal, on the account pages and on the routes where people approve just-in-time requests. Someone who holds a leaked key therefore cannot use it to sign in to the portal or to approve a just-in-time request.
Each successful call with the key also updates the agent’s last used time, at most once every five minutes. Dormancy rules and the agent’s risk score use that time.
Why does an agent’s API key need to expire?
An API key is one string, and copies of it end up in many places: environment variables, CI logs, shell history and other people’s laptops. An agent adds one more place, which is its own context. Suppose that the key is stored in an environment variable and the agent can run shell commands. An attacker can then use prompt injection to make the agent print the key.
LumoAuth stores only a SHA-256 hash of the key. Someone who reads the database cannot recover the key from the hash. For the same reason, LumoAuth cannot show the key again after it issues it. If you lose the key, rotate it.
An expiry limits how long a copy of the key stays useful. Without one, a key that leaked into a log two years ago still works today. With the default lifetime, a copied key stops working within 180 days, even if nobody notices the leak. LumoAuth also flags a client secret as old after 180 days, so both kinds of shared secret follow the same schedule.
How long does a key last, and how do you choose?
You choose the lifetime when you register the agent, and you can change it later. Both places offer the same choices:
- In the portal, go to Agents and choose Register agent. In step 2, How it proves its identity, choose API key. The field Key expires after appears below the cards.
- In the Admin API, send
apiKeyExpiresInDaysorapiKeyExpiresAtwhen you create the agent.
| Lifetime | In the portal | In the Admin API | Good for |
|---|---|---|---|
| 30 days | 30 days | "apiKeyExpiresInDays": 30 |
A demo or a short test |
| 90 days | 90 days | "apiKeyExpiresInDays": 90 |
A prototype that you rotate every quarter |
| 180 days | 180 days — recommended, selected by default | Send neither field | Most prototypes |
| 365 days | 365 days | "apiKeyExpiresInDays": 365 |
A key that you rotate once a year |
| A fixed date | A date I choose… | "apiKeyExpiresAt": "2027-03-31T23:59:59Z" |
A key that must stop at the end of a project |
| Never | Never — valid until revoked | "apiKeyExpiresInDays": null |
Only a key that you rotate on your own schedule |
The Admin API accepts any whole number of days from 1 to 3,650 in apiKeyExpiresInDays. apiKeyExpiresAt takes an ISO 8601 time in the future. Send either field as null for a key that never expires. Never is a choice that you have to make on purpose, and the agent’s page shows a warning for it.
To register an agent with a 90-day key, call the Admin API with an organization API key that has the admin:agents:write scope:
ORG=acme-corp
curl -sS -X POST "https://app.lumoauth.dev/orgs/$ORG/api/v1/admin/agents" \
-H "Authorization: ApiKey $LUMOAUTH_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"name": "Support triage prototype",
"identityType": "api_key",
"capabilities": ["tickets:read", "tickets:reply"],
"apiKeyExpiresInDays": 90
}'
The response holds the key in apiKey. This response is the only place where the key appears. Here it is, trimmed to the fields about the key:
{
"data": {
"agentId": "agt_3f9a51c07be24d18",
"identityType": "api_key",
"status": "active",
"apiKeyExpiresAt": "2027-02-06T10:14:03+00:00",
"apiKeyExpired": false,
"apiKey": "agk_6d2c…",
"_note": "Store the API key securely. It will not be shown again."
},
"message": "Agent created successfully"
}
To change the lifetime later, open the agent’s edit page and use Key expires after in the Credentials section, or send PATCH /admin/agents/{agentId} with one of the two fields. The new lifetime counts from the moment that you save it. A change of lifetime does not issue a new key. It applies to the current key, even to a key that has already expired. That change makes the old key valid again, so rotate the key instead if it may have leaked.
What happens when a key expires?
LumoAuth rejects every call with the key:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="API", error="invalid_token"
Content-Type: application/json
{"error": "invalid_token", "error_description": "The access token is invalid or expired"}
The response is the same as for a key that never existed, so it does not show whether the key once worked.
Nothing else changes. The agent stays active, and it keeps its capabilities, budget and history. Its page shows a critical item, API key has expired, and the fix is to rotate the key. The posture card on the agent’s page has one line for the key’s expiry, and one for its age:
| Posture line | Severity | When it appears |
|---|---|---|
| API key has an expiry | OK | More than 14 days are left |
| API key expires soon | Warning | 14 days or fewer are left |
| API key has expired | Critical | The expiry date has passed |
| API key never expires | Warning | No expiry is set |
| Credentials are old | Warning | More than 180 days have passed since the key was issued or rotated |
The portal rates the API key identity type itself as a warning. Every API key agent therefore appears under the Needs attention filter in the agent list. Open an agent to see which lines apply to it.
How do you rotate an agent’s API key?
Rotation issues a new key and replaces the stored hash in one step. The old key stops working at that moment. You choose the new key’s lifetime as you rotate.
In the portal, open the agent’s edit page. Under Rotate the API key in the Credentials section, pick New key expires after. It offers the same choices as at registration, with 180 days — recommended selected. Same as the current key keeps the old date. Then choose Rotate API key and confirm. The next page shows the new key once, with its expiry date.
From a script, use the Admin API. An agent has one API key at a time, so plan the switch:
- Check the current key.
GET /admin/agents/{agentId}returnsapiKeyExpiresAt,apiKeyExpiredandcredentialsRotatedAt. - Rotate, with a lifetime.
POST /admin/agents/{agentId}/rotate-credentialswithapiKeyExpiresInDaysin the body returns the new key once, with its expiry date. - Store the new key in the same script, before anything can print it or log it.
- Check the new key.
GET /agents/mewith the new key should answer200.
Send the lifetime in step 2. Without it, the new key keeps the old expiry date. Suppose that you rotate a 180-day key on day 170 without a lifetime: the new key expires 10 days later, on the old date. Only a key whose date has already passed gets a full 180 days by default.
A new key carries the agent’s authority, so the rule for registration applies here too. You can rotate a key only if you hold every catalogue permission among the agent’s capabilities. The previous post on capabilities explains this rule, called creator containment.
This script rotates a key with a 90-day lifetime and stores it in AWS Secrets Manager. It keeps the key in a shell variable and never prints it:
set -euo pipefail
ORG=acme-corp
AGENT_ID=agt_3f9a51c07be24d18
ADMIN="https://app.lumoauth.dev/orgs/$ORG/api/v1/admin/agents/$AGENT_ID"
# 1. Rotate with a 90-day lifetime. The new key appears only in this response.
NEW_KEY=$(curl -sSf -X POST "$ADMIN/rotate-credentials" \
-H "Authorization: ApiKey $LUMOAUTH_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"apiKeyExpiresInDays": 90}' | jq -r '.data.apiKey')
# 2. Store it before anything else happens.
aws secretsmanager put-secret-value \
--secret-id support-agent/lumoauth-key \
--secret-string "$NEW_KEY" > /dev/null
# 3. Check that the new key works. Prints 200.
curl -sSf -o /dev/null -w '%{http_code}\n' \
"https://app.lumoauth.dev/orgs/$ORG/api/v1/agents/me" \
-H "Authorization: Bearer $NEW_KEY"
POST /admin/agents/{agentId}/rotate-key also issues a new key, for API key agents only, and takes the same lifetime fields. It returns the key in api_key and the expiry date in api_key_expires_at. The LumoAuth CLI rotates with a lifetime too: lumo agents rotate-credentials <agent-id> --key-expires-in-days 90. It also takes --key-expires-at with a date, or --key-never-expires.
How do you rotate a key without downtime?
The old key stops working when you rotate, and the agent still holds it until it loads the new one. Two patterns keep that gap short:
- Read the key again after a
401. The agent reads its key from the secret store when it starts, and again whenever LumoAuth answers401. Then it retries the call once. The gap shrinks to one failed call. - Rotate during a deploy. If every deploy starts new agent processes, rotate just before the deploy. The new processes start with the new key.
Here is the first pattern in Python, for an agent that reads its key from AWS Secrets Manager and calls the Ask API:
import boto3
import requests
ORG = "acme-corp"
BASE = f"https://app.lumoauth.dev/orgs/{ORG}/api/v1"
SECRET_ID = "support-agent/lumoauth-key"
secrets = boto3.client("secretsmanager")
def load_key() -> str:
return secrets.get_secret_value(SecretId=SECRET_ID)["SecretString"]
class AgentClient:
def __init__(self) -> None:
self.key = load_key()
def post(self, path: str, body: dict) -> requests.Response:
resp = self._send(path, body)
if resp.status_code == 401:
# The key may have been rotated: read the current key and retry once.
self.key = load_key()
resp = self._send(path, body)
return resp
def _send(self, path: str, body: dict) -> requests.Response:
return requests.post(
f"{BASE}{path}",
json=body,
headers={"Authorization": f"Bearer {self.key}"},
timeout=10,
)
agent = AgentClient()
decision = agent.post("/agents/ask", {"action": "tickets:reply", "context": {"ticket": "T-1042"}})
print(decision.json()["allowed"])
Do you need two valid credentials during a switch? Then an API key is the wrong identity type. A private key JWT agent can register several public keys. You add the new key, move the agent over, and then remove the old key. The identity type is fixed after registration, so moving to another type requires a new agent. The post on six ways an AI agent can prove who it is compares the types.
What should you do when a key leaks?
Rotation stops the leaked key. However, someone may already have used the key to obtain short-lived tokens, such as just-in-time tokens. Suspend the agent first, so that those tokens stop working too:
- Suspend the agent with
POST /admin/agents/{agentId}/disable. LumoAuth rejects the key at once. It also revokes the tokens and grants that the agent holds, and sends a CAEPsession-revokedevent to your shared signals streams. Suspension also revokes the agent’s vault grants, so users who connected accounts for the agent must connect them again. - Rotate the key with
POST /admin/agents/{agentId}/rotate-credentials, and store the new key. - Read the audit log for the agent. Start from the earliest time when the key could have leaked, and look for calls that the agent would not make. Entries that the agent caused name it as the actor.
- Reactivate the agent with
POST /admin/agents/{agentId}/enable. Reactivation restores nothing that the suspension revoked. The agent obtains new tokens with its new key.
Is the agent not needed for a while? Then POST /admin/agents/{agentId}/revoke-key removes the key without a replacement. The agent cannot authenticate with a key until you rotate again.
How LumoAuth does it
In the Organization Portal, go to Agents (/portal/agents) and choose Register agent. In step 2, How it proves its identity, choose API key. The field Key expires after appears, with 180 days — recommended selected. After registration, the next page shows the key once, with a Copy button and the expiry date.
The agent’s page has an Authentication credential section. It shows whether a key is issued and when the credentials were last rotated. On the edit page, the Credentials section holds Key expires after for the current key, with Keep as is selected. Below it, Rotate the API key offers New key expires after and the Rotate API key button. The portal asks you to confirm your sign-in before it rotates the key, then shows the new key once. The posture card on the agent’s page shows the lines from the table above.
From a script, registration, lifetime changes, rotation, revocation and suspension use the Admin API, with an organization API key that has the admin:agents:write scope. The caller also needs the agents.edit permission. LumoAuth records each step in the audit log:
| Event | When it is written |
|---|---|
agent.credentials_rotated |
The portal or rotate-credentials issued a new key |
agent.key_rotated |
rotate-key issued a new key, with the expiry date and whether rotation extended it |
agent.key_revoked |
revoke-key removed the key |
agent.updated |
The lifetime of the key changed, with the old and new dates |
agent.credentials_revoked |
A suspension revoked the agent’s tokens and grants, with a count for each kind |
The docs for the agent registry cover key expiry and the Admin API fields. The API authentication reference lists the routes that accept an agk_ key. The governance docs describe everything that a suspension revokes. This series starts with What is an AI agent identity?
Standards involved
- Bearer token usage, RFC 6750, for sending the key in the
Authorizationheader - OpenID Shared Signals Framework and the Continuous Access Evaluation Profile (CAEP), for the
session-revokedevent that a suspension sends
The full list is on the standards reference.
FAQ
How long does an AI agent’s API key last in LumoAuth?
180 days, unless you choose otherwise. In the portal, Key expires after offers 30, 90, 180 or 365 days, a date that you pick, or never, when you register the agent and on its edit page. The Admin API accepts any number of days from 1 to 3,650, an ISO 8601 time, or null for a key that never expires.
Does rotating an agent’s API key reset its expiry?
You choose. In the portal, New key expires after is set to 180 days by default, and Same as the current key keeps the old date. In the Admin API, send apiKeyExpiresInDays with the rotation. Without it, the new key keeps the old date, unless that date has passed; then it gets 180 days.
Can an agent have two valid API keys during a rotation?
No. An agent has one API key at a time, and rotation replaces it at once. To keep the gap short, let the agent read its key again after a 401. If you need two valid credentials during a switch, use a private key JWT agent, which can register several public keys.
I lost an agent’s API key. Can I see it again? No. LumoAuth stores only a SHA-256 hash of the key, so nobody can display it again, including LumoAuth. Rotate the key to get a new one.
Does an expired key suspend the agent? No. The agent stays active, with its capabilities, budget and history. Only calls with the expired key are rejected. Rotate the key, and the agent works again with the new one.
Related: AI agent identity on the solutions pages, and six ways an AI agent can prove who it is on this blog.
Register your first agent at app.lumoauth.dev/register.