A static API key is a secret code for software that keeps working until someone changes or deletes it.
This guide is for anyone who sets up, buys or looks after AI agents at work. You do not need to write code. If your team gives an AI agent a key so it can reach email, files or other tools, this page explains why the type of key matters.
In short
- An AI agent is software with its own identity, so the keys it uses are non-human identity credentials.
- A static API key has no built-in end date, so a copied key can keep working for months.
- Short-lived credentials expire on their own, which limits how long a stolen copy is useful.
- Where a static key cannot be avoided yet, keep it in a vault, give it narrow access, give it an owner and change it on a schedule.
What you will learn
- Explain the difference between a static key and a short-lived credential.
- Spot the places where agent keys tend to end up.
- Check who owns each key your agents use, and when it was last changed.
- Ask suppliers whether their agent can use expiring credentials.
- Software password (API key)
- a secret code one program shows another to prove it may connect.
- Lasting key (static credential)
- a secret with no built-in end date, which works until a person changes it.
- Expiring pass (short-lived credential)
- a secret that stops working by itself after a set time.
What is a static API key?
Think of a front door key that works for whoever holds it. The door does not check the face of the person. It only checks the key.
An API key works the same way for software. An API (a doorway one program uses to ask another for data or actions) checks the key, and lets in whoever shows it. A static key is one with an expiry date far in the future, or none at all [1]. It keeps working until someone changes it or deletes it.
An AI agent is a program that uses an AI model to plan and carry out tasks. It might read a mailbox or update a ticket. To do that, it needs keys to other services. That makes the agent a software workload, and so a non-human identity.
Where the comparison stops working: a lost door key leaves a gap on the hook. A copied API key leaves no gap. The real owner still has it, so nobody may notice a second copy exists.
Why does it matter?
Agents often run all day, connect to many tools and act without a person watching each step. A key that never ends can give a stranger the same long reach, for as long as the key stays valid [1].
If you set up AI tools for your team
What could happen: a key pasted into an agent's settings is copied to a shared file, and stays valid long after the project ends.
Check this: list every key you have given an agent, with a named owner for each.
If you manage a team or budget
What could happen: a leaked key to a paid AI service is used by someone else, and the bill comes to you.
Check this: ask whether each paid key has a spending limit and an end date.
If you are new to IT or security work
What could happen: one key is shared by several agents, so nobody can tell which agent did what.
Check this: give each agent its own credential with only the access it needs.
What does it look like?
Here is a made-up settings file for an AI agent that sorts support emails. It shows two ways the agent could get access.
Example only. All values are made up.
# settings for EXAMPLE-mail-sorter agent MAIL_API_KEY=FAKE-KEY-0000-EXAMPLE (1) MAIL_KEY_CREATED=2024-01-01 (2) MAIL_KEY_EXPIRES=never (3) MAIL_SCOPE=read,send,delete,admin (4) # safer pattern TOKEN_SOURCE=vault.example.invalid (5) TOKEN_LIFETIME=1 hour (6)
- In a real file, this line would contain a working key. Anyone who reads the file could copy it.
- The key was made long ago, and nothing says it has been changed since.
- No end date, so a copy keeps working until a person acts.
- Far more access than a sorting job needs, including delete and admin.
- The agent asks a trusted service for a pass when it starts work, so no key sits in the file.
- The pass ends after an hour, and the agent asks for a fresh one.
Why this is risky: the first key lives in a file, has broad access and has no end date. Google's guidance warns that keys stored in code or files can be intercepted or stolen [2].
The safer way: the agent gets a short-lived pass with narrow access each time it needs one. A trusted service checks what the agent is first.
How does it work?
Here is how the two kinds of credential behave for an agent.
- Static key: a person creates the key once and pastes it into the agent's settings. The agent shows the same key every time it calls the service.
- The key works for any holder. Google describes API keys as bearer credentials, meaning whoever holds the key can use it [2].
- Short-lived credential: the agent first proves what it is to a trusted service. That service hands back a pass with an expiry time. On AWS, for example, workloads can receive temporary role credentials, so long-lived keys do not need to be handed out [3].
- The pass expires. Once it ends, the agent asks again. The Model Context Protocol is a common way to connect agents to tools. Its rules say token issuers should give out short-lived access tokens to reduce the harm from leaks [4].
- Least access in both cases. Whatever the credential type, giving it only the access the task needs makes a stolen copy less harmful [1].

Some services only accept static keys today. AWS lists cases where long-term keys are still needed, and recommends updating them when needed and using last-used information to remove them safely [3]. Google recommends restricting each key, deleting keys you no longer use and creating new keys from time to time [2].
A worked example
Quinn Osei runs operations at a small design firm. Last spring, a contractor built an AI agent that reads the shared inbox, sorts requests and drafts replies. To make it work, the contractor created an API key for the email service and pasted it into the agent's settings file.
In October, Quinn starts a review of the tools the firm pays for. She asks a simple question for each one: what keys does it use, and who owns them?
The answers are uncomfortable. The email key has no end date. It can read, send and delete mail across every mailbox, not just the shared one. The contractor has left, and the key still sits in a file that three people can open.
Quinn does not panic, and she does not delete the key straight away, because the agent depends on it. Instead, she works through it with the firm's IT supplier.
First, they check the email service's records for signs of use from unknown places. They find no unusual activity in the records available to them. Next, they create a new key limited to the shared inbox, with read and draft access only. They store it in the firm's vault, so the agent fetches it at start-up and the file holds only a name.
Then they switch the agent to the new key, confirm it works and delete the old one. Quinn becomes the named owner, with a reminder to change the key every quarter.
Finally, she asks the supplier whether the email service can issue expiring passes to the agent instead. It can, so moving to short-lived passes goes on next quarter's plan.
Myths and mistakes
| What people think | What is true |
|---|---|
| The agent is only a chatbot, so its key is not important. | The key opens whatever the agent can reach. Treat it like any other credential with that access. |
| Nobody has seen our key, so it is safe. | A copied key leaves no gap. Check where it is stored and who can open that place. |
| Deleting the key from the settings file fixes a leak. | Copies may remain in backups, history or chats. Replace the key at the service as well. |
| Changing keys once a year is enough. | A leaked key can be used every day until it is changed. Shorter lifetimes, or expiring passes, cut that window. |
| One key for all our agents is simpler. | It is simpler until something goes wrong. Then you cannot tell which agent acted, or switch one off alone. |
What can I do this week?
- List each AI agent your team uses and the keys it holds.
- Name one owner for every key on the list.
- Remove access the agent does not need, such as delete or admin rights.
- Move any key found in a file, chat or ticket into a vault, then replace it.
- Ask each supplier whether the agent can use expiring credentials instead of a static key.
Checklist
- Every agent has its own credential, not a shared one.
- Every key has a named owner.
- No key is stored in code, settings files, chats or tickets.
- Each key has only the access its task needs.
- Each static key has a planned change date.
- Keys that are no longer used are deleted.
- Paid AI service keys have spending limits where the service offers them.
- Short-lived credentials are used wherever the service supports them.
Common questions
Is a static API key the same as a password?
Nearly. Both are secrets that prove access. A password belongs to a person and is often paired with a second check. A static API key belongs to software, usually works alone and is often kept in files, which makes it easier to copy without anyone noticing.
Why are AI agents a special worry?
Agents often run without a person watching each step, and they may connect to many tools. A long-lived key gives that reach to anyone who copies it. Because agents act quickly and often, misuse can blend in with normal activity unless someone reviews the records.
What is a short-lived credential?
It is a pass for software that expires by itself after a set time, such as an hour. The program proves what it is to a trusted service, gets a fresh pass and asks again when it ends. A stolen copy is only useful until it expires.
What if our tool only accepts static keys?
Then manage the key carefully. Store it in a vault, give it narrow access and name an owner. Set a spending limit if the service offers one, and change the key on a schedule. Ask the supplier when expiring credentials will be supported.
How often should a static key be changed?
Your organisation's policy sets the timing. Change it at once if it may have leaked, when its owner leaves and when the project ends. Regular changes shorten how long a copied key stays useful, but they do not replace short-lived credentials.
Where next?
Ready for the detail? Read the practitioner guide: AI Agent Credential Lifecycle and Rotation Guide. It goes further into issuing agent credentials, rotation schedules and how to retire keys safely.
Also useful:
- Short-Lived Credentials for Beginners
- API Keys for Beginners
- Secrets Rotation for Beginners
- From Model API Keys to Workload Identity
Related NHI Mgmt Group resources: Non-Human Identities for Beginners, Secrets Management for Beginners and Leaked Secret Response for Beginners.
Key terms
- API key
- A secret code a program uses to prove it may call another service. Many are static and long-lived.
- Static credential
- A long-lived secret, such as an API key or password, that exists outside the moment of use and can be copied.
- Short-lived credentials
- Secrets that expire quickly, which shrinks the time a stolen copy can be used.
- AI agent identity
- The identity an AI agent uses to prove itself to other systems and services.
- Non-human identity (NHI)
- An identity for software, such as an app, service account, workload or AI agent, rather than a person.
- Bearer token
- A credential that works for whoever holds it, so theft and reuse are the main risks.
- Secrets vault
- A locked, central store that keeps keys and passwords and hands them only to approved programs.
Sources and further reading
- OWASP Non-Human Identities Top 10, "NHI7:2025 Long-Lived Secrets", OWASP Foundation, 2025. https://owasp.org/www-project-non-human-identities-top-10/2025/7-long-lived-secrets/ (accessed 2 Dec 2026).
- Google Cloud, "Best practices for managing API keys", Google Cloud documentation. https://docs.cloud.google.com/docs/authentication/api-keys-best-practices (accessed 2 Dec 2026).
- Amazon Web Services, "Security best practices in IAM", AWS Identity and Access Management User Guide. https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html (accessed 2 Dec 2026).
- Model Context Protocol, "Authorization", specification version 2025-06-18. https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization (accessed 2 Dec 2026).