Virtual API Key

Quick definition

A virtual API key is a stand-in credential issued in place of a real provider API key. Requests made with it go through a proxy or platform that checks the virtual key's own rules, such as allowed models, budget and expiry, then forwards the call using the real key, which the holder never sees.

AI & agents
Also known as
virtual key, proxy key, derived API key, sub-key, scoped API key
6
min read
October 17, 2026

What is a virtual API key?

A virtual API key looks and behaves like an ordinary API key to the person or tool using it. It is pasted into the same configuration field, sent in the same header and accepted by the same client libraries. The difference is what sits behind it. A real provider key is recognized directly by the AI provider. A virtual key is recognized only by an intermediary, which maps it to a real key before the request ever reaches the provider.

That indirection is the whole point. Because the intermediary sees every request first, it can attach rules to each virtual key that the underlying provider key does not have: a spending cap, a list of permitted models, an expiry time, rate limits or metadata such as the user, team or project it belongs to. One real key can back hundreds of virtual keys, each with different rules.

Virtual keys are most often issued by an AI gateway or by a platform with gateway capability built in. The term is also used for derived keys in other API ecosystems, but in AI it almost always means a key that is validated and metered by a proxy layer.

Why do virtual API keys matter?

Virtual API keys matter because they separate who can use an AI model from who owns the account that pays for it.

  • Containment: if a virtual key leaks, it can be disabled on its own, and its budget and expiry limit the damage.
  • Per-holder rules: each key can have a different budget, model list and lifetime, which a single provider key cannot express.
  • Metering: because every call passes through the intermediary, usage can be recorded per virtual key.
  • Provider independence: the holder's configuration does not change if the organization rotates or replaces the real key behind it.

How does a virtual API key work?

A virtual API key works through a lookup and enforcement step that happens on every request.

Issuance

An administrator or an automated system asks the intermediary to create a key and supplies its rules. The intermediary generates a random token, stores it (ideally hashed) with the rules and a reference to the real provider credential, and returns the token to the requester.

Validation on each call

When a client sends a request with the virtual key, the intermediary looks it up, confirms it exists and has not expired or been revoked, and checks the requested model against its model allowlist.

Budget check and forwarding

The intermediary checks remaining budget, then forwards the request to the provider using the real key. The provider only ever sees the real key and the intermediary.

Metering

When the response returns, the intermediary reads the token counts the provider reports, calculates cost and deducts it from the virtual key's remaining budget. That record is what makes per-key reporting possible.

Virtual API key vs real provider key

A real provider key authenticates directly with the AI provider and carries the full permissions of the account or project it belongs to. A virtual key authenticates with an intermediary and carries only the permissions written into it.

  • Who recognizes it: a provider key is recognized by the provider; a virtual key only by the intermediary that issued it.
  • Scope: a provider key inherits account or project scope; a virtual key has per-key models, budget and expiry.
  • Blast radius: a leaked provider key exposes the account; a leaked virtual key exposes only its remaining budget until revoked.
  • Volume: organizations keep a few provider keys but may issue thousands of virtual keys.
  • Lifetime: provider keys tend to be long-lived; virtual keys are often short-lived and are a natural fit for ephemeral API keys.

Virtual keys are one tool within the broader discipline of AI API key management, which also covers storage, rotation and policy.

Common use cases for virtual API keys

  • Per-learner AI access: each person in a course gets their own key with the same rules, backed by one organizational account.
  • Per-team budgets: internal teams receive keys with monthly ceilings instead of sharing one corporate key.
  • Customer and prospect evaluations: a prospect's POC gets a key scoped to that evaluation and nothing else.
  • Agent workloads: an automated agent receives a key limited to the models and spend its task justifies.
  • Multi-provider access: one virtual key can front several providers, so the holder does not manage separate credentials.

Best practices for virtual API keys

  • Give every virtual key a budget and an expiry, even generous ones; unlimited, never-expiring virtual keys recreate the problem they solve.
  • Issue keys per person or per environment so usage stays attributable.
  • Store virtual keys hashed on the intermediary side, and keep the real key in a secrets store the holders cannot reach.
  • Make revocation instant and individual, and automate it at the end of the work through API key revocation.
  • Deliver keys directly into tools rather than displaying them, unless the user needs to see the value.

How Heropa helps

Heropa uses virtual keys as the foundation of AI Lab Keys. Your AI provider key is stored once, in a dedicated AI cloud account inside the Heropa platform. When a lab launches, a virtual key is minted from it for each user, on the same credential pool machinery Heropa customers already use for cloud accounts, and placed into the AI tooling in the lab. Each key carries the budget, duration and allowed models set on the Template.

Keys can be revoked or reissued per environment or per user, you can choose to show or hide key details, and keys expire with the environment while the provider key they came from stays untouched. The background is covered in How do you put AI in virtual labs without sharing your API key?

Frequently asked questions

What is the difference between a virtual key and an API key?

A virtual key is a type of API key that only an intermediary such as an AI gateway recognizes. The intermediary checks its rules, then calls the provider with the real key. An ordinary provider API key is recognized by the provider itself and carries the full permissions of its account or project.

Can a virtual API key be used directly with OpenAI or Anthropic?

No. A virtual key only works when requests are sent to the intermediary that issued it, which then calls the provider using the real key. Tools are configured with the intermediary's endpoint and the virtual key, so the holder never needs the provider credential.

Does a virtual API key add latency?

It adds one extra network hop and a lookup, which is usually small compared with the time a model takes to generate a response. Where the intermediary runs and how it caches key lookups affect the overhead, so measure it for latency-sensitive workloads.

What happens if a virtual API key is leaked?

Whoever finds it can spend only up to its remaining budget, only on its allowed models, and only until it expires or is revoked. Revoking it affects no other keys and leaves the real provider key untouched, which is why virtual keys are safer to distribute.

See it in action

Give every learner and buyer a real, hands-on lab

Spin up real software environments for training, demos and POCs, right in the browser.