API Key Management: 5 Steps to Separate Keys per Project (2026)
If you run several projects on your own, the easiest way to manage API keys is this: give each project, and each environment within it, its own key. Put the purpose in the key's name, limit permissions and spending per project, and when a key expires or leaks, replace only that one. The steps are below, followed by a naming and rotation table you can copy as-is.
Why not share one key across all projects?
Sharing a key is fine until something goes wrong. Three problems stand out:
- A leak has a wide blast radius. If one key is written into five projects, revoking it stops all five at once, and you have to replace it in each one.
- You can't split the bill. The platform dashboard only tells you how much that key used, not which project burned it. That is awkward if you do contract work or want a budget for a single project.
- Debugging is harder. If usage suddenly doubles one day and there is only one key, you have to dig through every project's logs to find the cause.
This article is about creating multiple keys under the same account. Platforms differ in how many keys they allow, what permission scopes they offer, and whether they have a "project" concept, so check the official docs. It does not cover registering multiple accounts.
Step 1: Split by project and environment. How fine-grained?
A good granularity is project × environment. Each project should have at least a development (dev) key and a production (prod) key: use dev for local debugging and prod for deployed services. That way, if your laptop is lost or you commit a key by mistake, only the dev key is affected and production is untouched.
Don't over-split. A few small scripts or one-off experiments can share a single "sandbox" key with a low spending limit. Create separate keys only for projects that will run long-term and incur steady costs.
Step 2: How do you name keys so they still make sense months later?
Most platforms let you enter a name or note when you create a key, and that field is worth filling in properly. Recommended format:
project-environment-purpose-creation-yymm
Examples: blog-bot-prod-summarize-2611, blog-bot-dev-local-2611, sandbox-experiments-2611.
A few conventions:
- Use lowercase English letters and hyphens only. This makes the names easy to search in the dashboard and easy to put in docs.
- Never put any part of the key itself, or any password, in the name.
- The creation year and month help you decide when a key is due for rotation.
Step 3: How do you limit permissions and spending?
The rule is least privilege. Use read-only where you can, restrict the models or endpoints where you can, and set a spending cap where you can. These options are named and placed differently on each platform. Some platforms offer project-level keys and limits; see this article on our site: How to use OpenAI project API keys: per-project permissions and limits. Every platform has a place to set spending limits and alerts; follow the official docs.
If a platform can't set limits per key, add a safeguard in your own code, such as a maximum token count and a maximum retry count for each task, so an infinite loop can't drain your balance.
Step 4: Where do keys live, and how does code read them?
Keys stay out of the code repository, out of front-end pages, and out of chat screenshots. A common approach is one local environment file per project, added to .gitignore; for deployment, use the platform's built-in secrets or environment variables.
Use the same variable name across projects, for example LLM_API_KEY. When you replace a key, you only change the environment variable's value and leave the code alone. For setting environment variables on Windows, see How to set an environment variable for your API key on Windows (PowerShell and GUI). For more on storage, see How to store an API key securely: local development and team collaboration.
Step 5: How do you track usage per project?
Once keys are separated, usage tracking has a basis: each key maps to one project, so you can read usage by key in the dashboard. If the dashboard doesn't show enough detail, record the token counts returned with each request in your own call wrapper, along with the project name. For how, see How to track AI API usage yourself: calculate daily spend from response headers and logs.
A checklist you can use directly
| Item | Recommended practice |
|---|---|
| Granularity | Project × environment; small experiments share a sandbox key |
| Naming | project-environment-purpose-yymm |
| Permissions | Least privilege; restrict scope where possible |
| Spending limit | Set a cap on every key; if the platform can't, limit in code |
| Storage | Environment variables or platform secrets; never in the repo |
| Rotation | Roughly every quarter or half year; immediately when someone leaves or a device is lost |
| Cleanup | Revoke the old key after each rotation; delete keys that have been idle for a long time |
The order for rotation is: create the new key, swap it into the project, confirm requests work, then revoke the old key. Doing it the other way around causes a period of downtime.
What if a key has already leaked?
Revoke it first, then replace it, then check usage. Because you split keys by project, you only have to deal with the one that was exposed. For the full emergency steps, see What to do when an API key leaks: a 10-minute emergency checklist. For per-person keys and budget splitting in a team, see How to manage API keys on a team: one key per person, budget splits, and rotation.
What if you have more and more keys from different model providers?
The more models you use, the more keys you hold, one per provider, and the management work grows with them. When you need to check whether an API is working, start with cdnping's API status page to tell whether the problem is on the provider side or with your own key. To compare availability of each model across inference providers, see model monitoring.
Another way to reduce the number of keys is an aggregation gateway, which lets one key reach several capability groups. AGI Plan is a commercial partner of cdnping. It is a multi-provider LLM aggregation gateway sold as a monthly subscription, paid in RMB, with no overseas credit card required. Tools such as Claude Code and Codex only need a different endpoint URL. One subscription can switch between capability groups such as frontier reasoning, balanced general-purpose, Chinese flagship models, and fast lightweight models. Some models are marked "overseas only"; see the AGI Plan models page for specifics. The service also states plainly that it is not an officially authorized channel. For setup, see the getting started page. When you use a gateway, the per-project approach above still applies: create a separate key for each project, with the same naming and rotation rules.
What to do next
- List every key your projects use today, compare them against the checklist above, and mark the shared ones and the poorly named ones.
- Create independent keys for your production projects first, swap them in, then revoke the old keys.
- Standardize the variable name and naming rule, and apply them the next time you create a key.