Team Shared API Key Management: Per-User Keys, Budgets, Rotation

Blog / Developer tools

Team Shared API Key Management: Per-User Keys, Budgets, Rotation

The safest way to handle API keys on a team is to not share a single key at all. Give each member and each project its own key, set a limit on every key, rotate them regularly, and revoke a key the moment someone leaves or a project ends. When usage spikes or a key leaks, you then know exactly which key is involved, and replacing it doesn't affect anyone else.

The steps below walk through how to do this. Console menu names and whether per-key budgets are supported vary by provider, so check the official documentation of the service you use.

Why shouldn't a whole team share one key?

The problems with a shared key usually show up only after something goes wrong:

  • The bill shows a usage spike, but you can't tell which member, script, or environment caused it.
  • If the key leaks (committed to a repo, pasted in a chat group, visible in a screenshot), you have to replace it for everyone, and every person's tools break at once.
  • When someone leaves, you can't be sure they don't still hold the key unless everyone switches to a new one.
  • One runaway loop script can burn through the whole team's quota, and everyone else's requests start failing.

Once keys are split, each one maps to one owner or one purpose, which limits the blast radius of any problem.

Step 1: At what granularity should you split keys?

You don't need to go very fine-grained. Two dimensions are enough:

DimensionApproachBest for
Per memberOne dev key per person, named with their initialsLocal debugging, coding tools (such as Claude Code, Codex)
Per project/environmentOne key per service and per environment (dev, staging, production)Production services, CI

Never share a production key with anyone's personal dev key. CI should have its own key rather than borrowing a colleague's.

Put the purpose and the owner in the name, for example dev-zhangsan, prod-search-service, ci-main. When you later go through the bill or clean up, the name itself is the clue.

Step 2: How do you set a budget for each key?

First see how far your service lets you go:

  1. Some services let you set a usage or spend limit per key (or per project). This is the most direct option; set it in the console, and check the official docs for the exact location and parameters.
  2. If you can only set a total quota per account, you have to make up for it in your own layer: record usage per key in your own gateway or call wrapper, and alert or reject when a threshold is crossed.
  3. Either way, set two lines: an alert at a certain percentage, and a hard stop at the limit.

You can work backward from real usage to pick the numbers: let everyone run for a week or two, look at daily usage, then add some headroom. For more on spend limits and alerts, see How to control API spending: budget caps, alerts, and per-key splitting.

Step 3: Where do keys live, and how do you keep them out of the repo?

Never put a key in code. Read it from an environment variable only. A minimal setup:

# Project root
cat > .env.example <<'EOF'
# Copy to .env and fill in your own key. Do not commit .env
LLM_API_KEY=
LLM_BASE_URL=
EOF

cp .env.example .env
echo ".env" >> .gitignore

Key points:

  • Commit only .env.example to the repo; it contains no real values.
  • Keep real keys in a local .env, or in the secret store provided by your CI and deployment platform.
  • Don't send keys through chat tools or email. When handing something over, have the other person create their own key in the console.
  • You can add a secret scan before commits (for example an open-source tool like gitleaks); see its official docs for usage.

If your team uses a tool such as Codex that supports custom endpoints, the config usually references an environment variable name rather than hard-coding the key. For field syntax, see Codex config.toml field reference.

Step 4: How often should you rotate, and how do you avoid downtime?

There is no one-size-fits-all interval. A common practice is to rotate on a schedule (for example, quarterly), and also immediately when a leak is suspected or when people change roles.

A rotation order that avoids downtime:

  1. Create a new key in the console and keep the old one.
  2. Write the new key into the secret store or deployment config, and do a rolling release so services switch to it.
  3. Watch for a while until the old key's call volume drops to zero.
  4. Revoke the old key.

Step 3 is only possible if usage is tracked per key, which is another benefit of not sharing. If the old key still receives calls, something hasn't been updated yet; find it first, then revoke.

Step 5: What do you reclaim when someone leaves or a project ends?

Turn this into a checklist and put it in your offboarding process:

  • Revoke all dev keys under that member's name
  • Check whether they created any production or CI keys; if so, transfer ownership or recreate them
  • Check whether they have admin rights in the team console; if so, remove them
  • Any .env on their machine or in their notes can't be cleaned up remotely, so you must rely on revoking the key, not on asking them to delete it
  • When a project is retired, revoke its keys and delete them from the secret store

What if you suspect a key has leaked?

Revoke first, investigate second. Don't reverse the order.

  1. Immediately revoke or disable the key in the console, then create a new key to replace it.
  2. Look at the key's call log and time range to see whether there are requests you don't recognize.
  3. Search the repo history, CI logs, and screenshots for where the key appeared. Deleting it from the latest commit is not enough; it is still in the history.
  4. If the bill has charges you can't explain, contact the provider and follow their official policy.

If usage doesn't add up but there's no sign of a leak, see How to check when API billing looks wrong to verify it line by line.

Subscriptions, API keys, and gateways: which should a team choose?

How you manage keys depends on how you connect. Common cases:

  • One subscription account per person: no shared-key problem, but quota can't be shared and cost scales per head. For a comparison, see How to choose a team AI subscription.
  • Official API keys: pay-as-you-go, which suits the per-key management described above.
  • An aggregation gateway: you create several keys under one team account, and whether you can limit each one separately depends on the gateway's features. Check the terms before choosing; see How to choose an API relay.

One more option worth mentioning. AGI Plan is a multi-provider LLM aggregation gateway with monthly subscriptions, paid in RMB, with no overseas credit card needed. One subscription shares a single quota across capability groups such as frontier reasoning, balanced general-purpose, Chinese flagship models, and fast lightweight models. To keep using tools like Claude Code or Codex, you only need to change one endpoint URL. It is not an officially authorized channel, and some models are available only outside China; see the AGI Plan models page for specifics. AGI Plan is a commercial partner of cdnping, so please treat the description above as a summary and rely on the official site. For setup steps, see the AGI Plan quick start. Whether it supports per-key budgets and how to manage multiple keys is something to confirm in its console and docs.

Summary: three things you can do today

  1. List every key your team currently uses, and mark who uses it and where. Split any that several people share.
  2. Add .env to .gitignore and add a .env.example to the repo.
  3. Set a limit and an alert on every key, and add "revoke keys" to your offboarding process.

When calls fail, check the API status page first to tell whether it's a provider outage or your key being rate-limited or revoked. It can save you some detours.

Related articles

Keep reading