jcardena.com › Blog › API Keys Are Spend Contracts: Bound Every Credential Before It Can Bill
184 posts
EN ES

API Keys Are Spend Contracts: Bound Every Credential Before It Can Bill

A few of our API keys were compromised and we contained it. Why an AI key is a spend contract, and the five bounds every key now carries: scope, vault, caps, owner, limits.

API Keys Are Spend Contracts: Bound Every Credential Before It Can Bill

Published November 2026, dated to the month the work was done.

TL;DR: An API key authorizes access and spend at the same time. A few of our keys were compromised and used to run AI workloads nobody ordered. Our team contained the exposure. Every key now carries a contract: one workload, least privilege, secret store only, an enforced spend ceiling, and limits that mean wait, never pay more.

An API key opens a service and assigns the bill to its owner. When a key has no scope, no vault and no cap, an exposure is not a ticket in the security queue. It is spending that nobody approved.

A few of our API keys were compromised and used to run AI workloads that nobody on our team requested. We contained the exposure and changed the design so that one leaked key can no longer spend without a bound. This post covers the pattern behind exposures like this one, the containment sequence, and the five rules our platform enforces now.

A key is a billing identity

A key does two jobs. It authenticates a caller, and it attributes usage to an owner. When software calls a cloud service, for example to generate an image or run a model, it sends the key with the request, and the service records the usage against the key's owner.

Both jobs must be contracted. Anyone who holds the key can use the service as the owner, and the cost lands on the owner.

A key is copiedinto a fileThe file becomesreachableScanners find thekeyThe key runs AIworkloadsThe cost lands onthe owner
How an exposed key becomes someone else's spending

Why AI workloads change the risk

Leaked keys are not new. What changed is what a key can do and how fast it is found.

  • AI keys spend directly. Traditional credentials can expose data or operations, which is serious on its own. An AI service key can also create immediate variable spend. It can run image and video generation at full speed, and every call costs money.
  • Scanners never stop. Automated tools search public code, web pages and shared files for anything shaped like a key. A short exposure is enough.
  • Keys multiply. Every agent, script and service needs its own access to some model. Each one is another place a key can leak from.
  • Agents copy what they see. Coding assistants write configuration fast. A key sitting in one file is easily copied into the next.

Key handling is now part of daily operations, like backups, not an item for an annual review.

The pattern behind the exposure

Exposures like this rarely come from one mistake. They come from a default pattern that is common across estates, and our review found parts of it in ours:

  • Reuse. A key shared across services propagates into configuration, operational notes and retained artifacts. Every copy is another place it can leak from.
  • No scope. A key that can call any service on its account turns a small exposure into a large one.
  • Shared blast radius. Co-located credentials are exposed together. When one is found, every credential stored beside it has to be treated as exposed.
  • Idle is not off. An environment no longer in active use can still hold a live key with billing enabled.
  • Silent escalation. Automatic fallback from a constrained tier to billable capacity defeats the spending contract. Every call succeeds, and every limit quietly becomes spend.

Containment, in order

Containment requires both speed and a disciplined sequence. The team worked in five steps:

  1. Revoke. Disable the affected credentials and every credential stored beside them.
  2. Map. Find every service that depended on those credentials, and trace every copy outside the secret store. Scan history, not only current files.
  3. Replace with scope. Issue new keys, each restricted to the one service it serves, delivered only through the secret store.
  4. Clean. Remove credentials from files and history, and rebuild runtime secrets from the store.
  5. Prevent. Add the controls below so the same pattern cannot return.

The five rules we run now

In Governance-Driven Contract Design terms, every key now carries a contract: what it may call, where it may live, what it may spend, and who owns it. I will not approve a key into production unless every term is in place. The rules enforce each one.

  • One key per workload. Every agent, service and job gets its own key. If one leaks, we revoke one key, not the whole platform's access, and we know exactly where it came from.
  • Least privilege. A key may call only the one service it needs. An exposed image key cannot run video jobs.
  • Vault only, checked at every door. Code and configuration reference the secret store. Detection runs before a change is committed, repositories and history are scanned, and secrets are injected at runtime. Rotation and audit logs cover the rest. No single scanner is the guarantee. The layers together are.
  • Enforced spend limits. Quotas and caps that stop usage, not only an alert after the fact, and tested so we know they trip. Work runs under the platform's billed account, never an individual identity.
  • Limits mean wait. A limit means wait or skip. No tool may move to a paid key or a larger plan on its own. Spending more is always a human decision.
WORKLOADSAgentServiceScheduled jobCREDENTIALSOne key perworkloadScoped to oneserviceRotated onscheduleSTORAGESecret store onlyChecked beforecommitInjected atruntimeSPENDPlatform billedaccountEnforced capUsage alert toowner
How our team contains credentials now

What the design now guarantees

Leaks happen. Files get copied, tools reproduce configuration, and scanners are fast. What the design controls is the blast radius: how much one exposed key can do, how much it can spend, and how quickly an owner hears about it.

The objectives we hold now are simple to state and to audit. Every key maps to one owner and one workload. Its scope is the smallest that works. Its spend has an enforced ceiling. Unusual usage triggers timely owner notification, while enforced ceilings independently stop excess spend.

A credential is a contract, and it holds only if every term is enforced. Tools are fashion. Trust is the work. Every line holds.

JC
Juan Cardena
Enterprise AI & Agentic Systems Architect

Enterprise architect with 25 years across web, software, data, and AI. MIT CDAO ’25. Writing on agentic AI in production.