All guides

Create Virtual Keys for Apps and Agents

Give every app and agent its own key with its own labels, expiry, and credentials, and revoke one without touching the rest.

10 min read Updated October 2026LLM FinOps
On this page
  1. 01What you'll set up
  2. 02Why one key per app
  3. 03Create a key
  4. 04Name keys so reports read well
  5. 05Labels that drive policy and reports
  6. 06Credential overrides
  7. 07Test the key from the console
  8. 08Use the key in your app
  9. 09Rotate and expire
  10. 10Revoke
  11. 11Virtual keys and telemetry keys
  12. 12If something goes wrong

01

What you'll set up

A virtual key is what your app uses to call the gateway. It carries a team, an app, and an environment, so every request is labeled before it leaves your code. In about ten minutes you will create a key, label it well, test it, and learn how to rotate and revoke it.

  • One key per app, agent, or environment
  • Labels that drive policy and reports
  • A test from the console
  • A rotation and revocation routine

You need an owner or admin role. Provider credentials come from the previous guide.

02

Why one key per app

Sharing one key across apps hides who spent what and makes every incident a company-wide one.

One shared keyOne key per app
Spend cannot be traced to an ownerSpend, blocks, and errors show by key
Revoking it breaks everythingRevoke one app and leave the rest
Labels come from every callerLabels are set once on the key
Everything shares one policyEach key can follow its own policy

03

Create a key

Keys are on the Virtual Keys card in AI → Credentials & Keys.

  1. 1

    Choose + Create Key

    It is at the top of the Virtual Keys card.

  2. 2

    Enter a Key name

    Say what and where, such as support-chatbot-prod.

  3. 3

    Set Valid for (days)

    Choose a lifetime that fits your rotation habit. The default is 3,650 days.

  4. 4

    Set the default Team ID, App ID, and Environment

    These labels travel with every request the key makes.

  5. 5

    Optionally set an Upstream credential override

    Override which provider credential the key uses, for all providers or for particular ones.

  6. 6

    Create and copy the secret

    It is shown once. Store it in your secret manager.

AI → Credentials & Keys → Virtual Keys
2Key name
support-chatbot-prod
3Valid for (days)
3650
4Default team ID
platform
4Default app ID
support-chatbot
4Default environment
production
5Upstream credential override
Use policy default
Create Key
Name, lifetime, labels, and credential overrides.

04

Name keys so reports read well

A good name tells a reviewer what the key is for without opening it.

PatternExample
app-environmentsupport-chatbot-prod
team-service-environmentplatform-summarizer-staging
agent-purposebilling-agent-reconcile

05

Labels that drive policy and reports

Team, App, and Environment do two jobs.

  • They choose which policy applies, through the bindings you set
  • They label spend, blocks, and errors in the Explorer
  • They are set once on the key, so every call carries them

Request headers such as x-cloptima-team label usage but cannot move a key onto a different policy. The key decides.

06

Credential overrides

By default a key uses the credentials the policy names. You can point a key at its own.

SettingUse it for
Default credentialA key that should always use one provider account
Per-provider overridesA key that uses account A for OpenAI and account B for Anthropic
Use policy defaultEverything else

Separate bills by team

Two teams share one policy but have separate OpenAI accounts. Each team's key overrides the OpenAI credential, so each provider invoice matches one team.

07

Test the key from the console

Test Virtual Key sends a real call through the gateway so you can check policy and speed before you ship.

  1. 1

    Open Test Virtual Key

    It is at the bottom of the Virtual Keys card.

  2. 2

    Select the key

    A key you just created is ready to use.

  3. 3

    Enter a model and a prompt

    Use something short.

  4. 4

    Choose Send Test Call

    You see the answer, or the block reason if a policy applies.

08

Use the key in your app

Point any OpenAI-compatible client at the gateway and use the virtual key as the API key.

python
from openai import OpenAI

client = OpenAI(base_url="https://api.cloptima.ai/v1/ai", api_key="clop_vk_...")
reply = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say hello"}],
)

A virtual key can only call models through the gateway. It cannot change settings or read your data.

09

Rotate and expire

Rotate issues a new secret for the same key. It is also how you change a key's expiry.

  1. 1

    Choose Rotate on the key

    Set a new name or lifetime if you want one.

  2. 2

    Copy the new secret

    It is shown once.

  3. 3

    Update your app

    Deploy the new secret.

10

Revoke

Revoke ends a key at once and keeps its history.

Use it when a key may have leaked, when an app is retired, or when a person leaves a team. Spend history stays in the Explorer under the key's name.

11

Virtual keys and telemetry keys

Cloptima has two kinds of key. They do different jobs.

Virtual keyTelemetry key
Prefixclop_vk_clop_tk_
Used forSending requests through the gatewaySending usage events from SDKs or OpenTelemetry
Where to createVirtual Keys cardTelemetry Keys card
LabelsTeam, App, EnvironmentOptional team, app, and environment
ShownOnce, at creationOnce, at creation

Use a telemetry key when your app calls a provider directly and reports usage to Cloptima, and a virtual key when your app calls through the gateway.

12

If something goes wrong

Most problems are the secret or the labels.

What you seeLikely causeFix
401 from the gatewayThe secret is wrong, expired, or revokedRotate the key and update the app
403 policy_not_configuredNo policy is bound to the key's labelsBind a policy to the team, app, or key
Spend shows under unknownThe key has no team or appEdit the key and set the labels
The wrong provider account is billedThe key uses the policy's default credentialSet a credential override on the key

Put This Guide Into Practice

Cloptima automates the strategies described in this guide.

No credit card required
5-minute setup
Free trial