LiteLLM virtual keys, budgets and spend tracking

Virtual keys let you give each team and application its own credential with a budget, rate limits and an approved model list. This page covers how to design, build, verify and hand over that setup.

On this page

Why LiteLLM virtual keys decide who can spend what

When several teams call model providers with shared or scattered API keys, nobody can say which team spent what, and a single leaked key exposes every budget at once. LiteLLM virtual keys issued by the proxy, backed by PostgreSQL, are the control point for budgets, TPM and RPM limits, model restrictions and spend records. Each virtual key is a proxy-issued credential that the gateway checks on every request, so the proxy decides whether a call is allowed before it reaches a provider. The provider credentials and the LITELLM_MASTER_KEY stay on the gateway side and are never handed to applications or teams.

Budgets can sit at the key, user or team level, and LiteLLM also supports temporary budget increases for a defined need. That flexibility is also where the work gets harder than it looks. The key hierarchy has to match how your organization actually owns spend, so a team budget does not silently conflict with a per-key budget issued to one of its applications. Virtual keys need a PostgreSQL database to function, so the database must be set up, backed up and sized before the first key is issued, not added later. Confirm the exact precedence rules for keys, users and teams against the current virtual keys documentation before you design the hierarchy.

The last difficulty is reconciliation. LiteLLM records spend against its own price data and the usage it observes, and provider invoices will not match those records to the cent, because of rounding, pricing tier changes, cached or batched usage and calls made outside the gateway. Plan a monthly comparison between the proxy's spend reports and provider invoices, record the variance and agree on which figure finance will use. Ask your implementation partner or LiteLLM contact to confirm how spend is calculated for each provider you plan to connect.

Which LiteLLM settings and stores make up key, budget and spend control

Key, budget and spend control in LiteLLM rests on a small set of settings and two stores. Each part answers a different question: who can administer the gateway, which keys can call which models, how much each owner can spend, and where the counts live. Confirm how each piece behaves in your chosen version before you write policy around it.

Master key for administration

The LITELLM_MASTER_KEY is the administrative credential for the proxy. It is used to create virtual keys, teams and budgets, so it should not be handed to applications. LiteLLM's production guidance says the key must start with sk- and be kept in a secret manager. Ask who holds it, how it is rotated, and whether administrative actions are logged separately from application traffic.

Production guide

Virtual keys with model allowlists

A virtual key is an application or team credential issued by the proxy, which can be restricted to specific models. Issuing one key per team or application lets you revoke access without touching provider credentials. Confirm in your version that a request for a model outside the allowlist is rejected, and test that with a real key before go-live.

Virtual keys docs

Budgets at key, user and team level

Budgets can be set per key, per user and per team, and LiteLLM also supports temporary budget increases. Decide which level owns the money. A team budget with per-key caps can prevent one application from consuming a whole allocation. Ask how spend is attributed when one user works through several keys and how a budget reset is scheduled.

Budget settings

TPM and RPM limits

Tokens-per-minute and requests-per-minute limits protect shared provider quota and keep one workload from starving others. They are separate from spend budgets, so a key can be within budget and still hit a rate ceiling. Confirm whether each limit is enforced per key, per team or per proxy instance in your version, because that determines how limits behave across replicas.

PostgreSQL as the record store

PostgreSQL is the primary supported database and is required for virtual keys. It holds key records, team and user settings, and spend data. Plan backups and restore tests for it, because losing this store means losing the spend history finance relies on. Ask how spend updates are batched at your scale, since LiteLLM's production guide describes batching database writes every 60 seconds at scale.

Redis for shared limits

Once more than one proxy instance runs, Redis holds shared rate limits, router state and cache. Without it, each replica may count requests independently, so a TPM or RPM limit can be exceeded across the fleet. LiteLLM's guidance requires Redis 7.0 or newer for this setup. Confirm how a Redis outage affects limit enforcement in your version before you rely on it.

Minimum Redis version
7.0+
Production guide

How a request with a virtual key passes budget and model checks

The diagram starts with an application sending a request under its virtual key to the LiteLLM proxy. The proxy checks the key, the allowed models, the RPM and TPM limits and the budget before routing to a provider or private model, then writes spend to PostgreSQL. The admin path shows the master key or an admin identity creating teams, users and keys, and Redis is shown as shared state when several proxy instances run.

Request path through virtual key checks, routing and spend logging, with the admin path.

Which key structure, budget scope and limit settings fit each team

This table compares key structures, budget scopes and limit settings for LiteLLM virtual keys, with the operational cost of each choice. Read each row as a decision: find the team pattern that matches yours, then check what it will cost you in rotation, reporting detail and shared-credential risk.

OptionWhen it fitsOperational costWatch for
One key per teamTeams with a single shared application and a stable model listFew keys to govern and rotate, but spend reports show the team total onlyApplications inside the team share one budget and one credential
One key per application or environmentSeveral services owned by one team, or separate dev, staging and productionMore keys to rotate and label, but spend splits cleanly by service and environmentKey sprawl if no naming and ownership rule is enforced
Per-user keysIndividual developers or analysts using tools directly, such as coding assistantsHighest key count, and offboarding requires revoking each user's keyPersonal keys copied into shared scripts or CI jobs
Budget at key levelAutomated workloads with a predictable, bounded spendOne budget to set and review per key, with spend tied to a single callerA key budget does not cap what the same team spends through other keys
Budget at user or team levelGroups that share a pool of spend across several keysFewer budgets to manage, and team reports match the cost centerA runaway key can consume budget that other team members need
Temporary budget increasePlanned peaks such as a launch, migration cutover or evaluation windowRequires an owner to request and expire the increase, and a review afterwardIncreases that are never reverted and become the new baseline
Model restriction per keyKeys that should reach only approved providers or private modelsModel lists must be updated when approved models changeAliases or new model names missing from the allowlist cause failed calls
TPM and RPM limits per keyShared pools where one caller could starve others, or throughput must be boundedLimits need tuning from observed usage after go-liveLimits set too low cause errors during normal peaks; confirm values in a test run

How to build LiteLLM virtual keys, budgets and spend tracking in order

This sequence takes a self-hosted LiteLLM proxy from a bare deployment to a state where each team and application holds scoped keys, bounded spend and reportable usage. Each step closes with a check so the next one starts from a verified base.

  1. Confirm database, master key and secret storage

    Confirm that the proxy runs on PostgreSQL, since virtual keys require a PostgreSQL database, and that LITELLM_MASTER_KEY starts with sk- and is stored in your secret manager rather than in a config file or container image. The platform or security owner signs off on this. It is done when a read of the proxy configuration shows the database connection string sourced from a secret, and the master key is absent from version control and from logs. If you run more than one proxy instance, also confirm Redis 7.0 or newer is in place, because shared rate limits depend on it.

  2. Define team owners and their applications

    List each team that will consume models through the gateway, name one accountable owner per team, and list the applications each team runs. The business owner, not only engineering, should approve the list, because the owner is the person who will receive spend reports and request budget changes later. It is done when every application appears under exactly one team and every team has a named owner and a backup contact.

  3. Map approved models to each team

    For each team, record which models from your gateway configuration it may call, including the provider, the model alias and any private self-hosted model. Security and procurement should review this map, since it determines what a key can reach. Keep the map short. It is done when the map is written down, each entry has an approver, and every model alias in the proxy configuration appears in at least one team's list or is explicitly marked as restricted.

  4. Create teams and users in the proxy

    Create the team records in the proxy and add the named users who administer or request keys for them. Assign each team the model list from the previous step. Use the admin UI or the admin API with the master key, and avoid sharing the master key with team members. It is done when each team shows its member list and approved models, and a user who is not on a team cannot see or manage its keys.

  5. Issue one virtual key per application and environment

    Generate a separate virtual key for each application and each environment, such as development, test and production, so that a leaked key can be revoked without affecting other workloads. Attach each key to its team, store it in the application's secret store, and record which application owns it. It is done when each key is listed under its team, the key name identifies the application and environment, and no two applications share a key.

  6. Set budgets, TPM and RPM limits and model restrictions

    On each key or team, set the spend budget, tokens-per-minute (TPM) and requests-per-minute (RPM) limits, and the list of models the key may call. Agree the values with the owner, and record the reason for each value. Virtual keys support per-key, per-user and per-team budgets, so decide at which level each limit applies to avoid double counting. It is done when the key settings show the agreed values, and a test call that succeeds on an approved model and fails on a blocked model returns the expected response.

  7. Route temporary budget increases through approval

    Use the temporary budget increase feature only through a written request that names the key, the amount, the duration and the approver. The approver should be someone outside the requesting team, such as a finance or platform lead. Record each approval in your change log so the increase can be reversed when the window closes. It is done when a test increase is requested, approved and then reverted on a non-production key, and the change log shows all three events.

  8. Connect spend reporting to the business

    Set up a recurring export or dashboard that reports spend, token use and limit breaches by team and by application, and send it to each team owner and to finance. Confirm the reporting source with your database administrator, because spend updates are batched to the database at scale and the figures will lag slightly behind live calls. It is done when a team owner receives a report that matches the spend recorded for a set of test calls within the agreed reporting window.

How key and budget setup changes across single node, HA and Kubernetes

A single proxy instance is the simplest model for virtual keys, budgets and spend tracking. The proxy reads and writes key definitions, team and user budgets, and spend records in PostgreSQL, which LiteLLM names as its primary supported database. Because one process handles every request, limit enforcement stays in one place and the counts are easy to reason about during testing.

  • Database as the system of record: Keys, budgets and spend all depend on PostgreSQL, so the database must be backed up and reachable before any key is issued.
  • Limit handling: TPM and RPM limits are evaluated by the one instance, so a limit test on a single node reflects what users will see.
  • Temporary increases: Budget increases granted for a project are recorded in the same database and apply immediately to the one instance.
  • Restart behavior: Confirm how in-flight requests and cached key data behave when the proxy restarts during a maintenance window.
  • Growth path: A single node is a useful staging step, but it is not a high availability design.

Before go-live, confirm the single instance can handle expected peak load and that your team has a documented way to move to multiple instances later.

What drives the effort of setting up LiteLLM virtual keys

This table lists the factors that change how much work it takes to issue, scope and report on LiteLLM virtual keys, with a way to keep each one under control. Read it before scoping the build, because most of the effort comes from the number of keys and models, not from the proxy itself. Each driver is easiest to manage when the catalog, key structure and reporting format are agreed before anyone configures the first key.

DriverWhy it changes effortHow to keep it down
Teams and applications needing keysEvery team or application that gets a key needs its own budget, limits, model list and owner, and each adds review and rotation work.Issue keys per team rather than per application where possible, and add application keys only when spend or access must be separated.
Models and providers to allowlistEach model a key may call must be named, tested through the router and checked against approved provider terms before go-live.Agree a short approved model catalog with security and procurement, and use model groups so teams request a group rather than individual models.
Number of environmentsDevelopment, staging and production usually need separate proxy instances, databases and key sets, so budgets and limits are configured more than once.Keep non-production keys on low limits and a reduced model list, and promote configuration as code rather than editing each environment by hand.
Budget mapping to finance cost centersIf budgets must match cost centers in the general ledger, each key needs a stable mapping, an owner who approves changes and a process for reassignment.Map one cost center to one team key where the organization allows it, and document the mapping before build so finance does not request changes mid-rollout.
Identity integration for admin access and team assignmentAdmin sign-in through SSO and assigning users to teams from identity provider groups adds configuration, testing and an access review process. SSO beyond the free five-user limit requires an Enterprise license.Confirm the license position for your user count early, and limit admin roles to a small named group that is reviewed on a fixed schedule.
Custom reporting needsSpend reports in a format finance or a governance committee can use may need data exports, custom dashboards or callbacks, each of which must be built and maintained.Agree the report fields, period and recipients before build, and start with the standard spend views before adding custom exports.
Rate limit tuning (TPM and RPM)Setting limits per key, user or team requires load data from each application, and limits often need adjustment after the first weeks of real traffic.Start with a small set of limit tiers instead of one limit per key, and review usage on a fixed cadence after go-live.

How to keep virtual keys, budgets and spend records safe

Virtual keys, budgets and spend records all sit on the same gateway, so a weak control in one place undermines the others. The cards below cover the decisions that keep the master key, key issuance, model scope and spend data under the right owners and out of the wrong logs.

Keep the master key out of code

The master key holds administrative control over every virtual key and budget, so it should never appear in application code, container images or CI logs. Store it in a secret manager and inject it at runtime, and confirm the key begins with sk- as LiteLLM requires. Ask who can read it and how it is rotated after an engineer leaves.

Production guide

Limit who can issue and raise keys

Decide which roles may create virtual keys, change budgets and lift TPM or RPM limits, and keep those roles separate from application owners. A budget raise is a spend decision, so route temporary increases through a named approver. Review the admin accounts that hold these rights on a fixed schedule.

Rotate keys when owners change

A virtual key belongs to a team or application, and that ownership changes over time. When a service owner moves on or a project closes, rotate or revoke the key and confirm that the old value no longer works. Keep a register that maps each key to its owner, its budget and the systems that use it.

Restrict each key to approved models

Scope every virtual key to the specific models it needs, so a key issued for a summarization job cannot call an expensive or unapproved model. Review model lists whenever a provider or private model is added or retired. Confirm that requests for models outside the list are rejected in your own test environment before go-live.

Keep prompts and keys out of spend reports

Spend reports need token counts, model names and team totals, not prompt text or key values. Review which logging callbacks are enabled and where logs are stored, and mask or exclude sensitive fields before data reaches finance or dashboards. Ask your team to confirm how spend records are retained and who can export them.

Use Enterprise RBAC and audit logs

Where governance requires role separation by team and a record of administrative changes, the audit log and team RBAC features are part of the LiteLLM Enterprise edition. Confirm the exact features in the edition you plan to run against the Enterprise documentation before you design the approval process around them.

Enterprise docs

How to test that budgets and limits hold and fail safely

Test each control with a key that is allowed to fail. Create a test team and a throwaway virtual key restricted to one approved model, then confirm five behaviors: a request to a model outside the key's allow list returns an error, a burst that exceeds the key's rpm_limit or tpm_limit is refused, a key whose spend reaches its max_budget stops making further calls, a temporary budget increase takes effect and then lapses at its stated expiry, and a deleted or rotated key stops authenticating immediately. Record the exact status code and error body for each case. Confirm these behaviors against your own LiteLLM version before relying on them, because error codes and enforcement timing have changed between releases. Use the virtual keys documentation as the reference for the setting names and expected semantics.

Reconcile recorded spend against provider usage over a fixed window. Pick a test window, run a known volume of requests through the gateway, and compare the spend LiteLLM wrote to PostgreSQL with the usage reported in each provider's own billing or usage console for the same keys and models. Expect small differences, since LiteLLM batches spend updates to the database (the production guide mentions a 60 second interval at scale) and provider usage may be reported with a lag. Decide in advance what variance you will accept and what triggers investigation. Check the model price map as well, because a wrong price override makes both sides agree on the wrong number only if you compare against the same table; compare against the provider's invoice line items.

Run the full suite against every proxy instance. Limits such as RPM and TPM depend on shared state, and the production guide requires Redis 7.0 or newer once more than one instance runs. Send the same test traffic through the load balancer and also directly to each pod, then confirm that a key's limits are enforced across the whole fleet rather than per instance. Repeat the test after a Redis restart and after one instance is taken out of rotation, since those events show whether counters and budgets survive. Keep the results as dated evidence, rerun the suite after every upgrade, and ask your deployment partner or the LiteLLM support team to confirm any behavior you cannot reproduce.

What to monitor, back up, upgrade and document after go-live

Virtual keys, budgets and spend records stay useful only while someone watches them, can restore them, and can explain them. The four areas below connect the daily operating work to the records an auditor or finance lead will ask for.

Monitor usage, budgets and rejections

Review spend against each key's budget, the TPM and RPM limits that are hit, and the requests rejected for exceeding a limit or requesting a model the key is not allowed to use. Assign each key an owner so that a rejection report reaches a person who can raise a budget or fix an application. A rise in rejections for one key often points to a retry loop or a deployment change rather than real demand, so check the application before raising the limit. Confirm with your platform team which alerts and log exports the deployed version provides.

Virtual keys docs

Back up PostgreSQL

Virtual keys, budgets, team assignments and spend history all live in PostgreSQL, so a lost database means lost keys and lost spend records. Schedule regular backups, keep at least one copy outside the cluster that runs the proxy, and test a restore into a separate environment before you need it. Confirm the recovery point and recovery time your finance and security teams expect, then check that the backup schedule meets them. Store backup credentials in the same secret manager used for the master key.

Retest before each upgrade

Before you move to a newer minor version, rerun your test cases for budget enforcement, model restrictions, rate limits and failover routing on a staging copy of the gateway. Stay within the four most recent stable minor versions that LiteLLM supports, and choose stable releases for production. Database migrations between versions need their own plan: back up first, read the release notes for schema changes, and rehearse the migration on a copy of production data before you schedule it. Record the results so the next upgrade starts from a known baseline.

Supported minor versions
4
LiteLLM releases

Document the key register

Keep a register that lists every virtual key with its owning team, application, permitted models, budget, TPM and RPM limits, and the date of its last and next rotation. Finance uses the register to match spend to cost centers, and security uses it to confirm that no key outlives its owner or its application. Review the register on a fixed schedule and remove keys for retired applications. Ask your security team which fields they need for their own review before you design the template.

What buyers ask before setting up LiteLLM virtual keys

How much effort and cost depends on team count, models and reporting needs?

Effort scales mostly with the number of teams and applications that need keys, the number of providers and private models behind the gateway, and how far spend reporting must reach. Each team needs an owner, a budget, rate limits and an approved model list, so twelve teams with three shared models is a different job from two teams on one model. Costs have two parts: the internal time to define the catalog and cost centers, and any outside help to configure, test and document the setup. Ask any partner for a quote that lists teams, keys, providers, reporting destinations and retest work separately, since those are the inputs that move the price. DeployOpen does not publish a price list; a quote follows from the written scope.

How long does setup take and what sets the schedule?

Duration depends on how quickly the organization can make decisions, not only on the configuration work itself. The schedule is usually set by four things: agreeing the team and key structure, deciding which models each team may use, confirming how spend maps to cost centers, and getting access to the database and secret manager in the target environment. Testing budget enforcement and rate limits before applications depend on them also takes time. Ask for a written timeline tied to these milestones, and confirm the dependencies with your own infrastructure, security and finance teams before agreeing a date.

What must the internal team provide before virtual keys can go live?

The internal team provides the decisions and access that only the organization can supply. In practice that means:

  • A named owner for each team, application and budget
  • A model catalog listing which providers and private models are approved for each team
  • A mapping from each team to a cost center so spend reports reach finance
  • Access to the target PostgreSQL database and the secret manager that will hold the master key and provider credentials

Without these inputs, keys get issued with unclear ownership and budgets that nobody reviews. Confirm each item with the relevant owner early, because most delays come from waiting on them rather than from the configuration itself.

Can our team set up LiteLLM virtual keys alone, and where does outside help save time?

A capable platform or engineering team can set up virtual keys alone if it has time to read the LiteLLM documentation, run tests and maintain the configuration after go-live. Outside help usually saves time in three places: defining the team and model structure so it can be audited, testing budgets, TPM and RPM limits and model restrictions against real traffic patterns, and producing the evidence that security or compliance reviewers ask for. Retainers can cover upgrades and ongoing testing. DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside the client's own infrastructure, and most engagements are fixed-scope with the scope agreed in writing before work starts.

Can budgets be enforced without PostgreSQL?

No. LiteLLM virtual keys need a PostgreSQL database, and the per-key, per-user and per-team budgets, TPM and RPM limits, temporary budget increases and model restrictions are stored and enforced through it. Plan the database as a required component from the start, including backups and access control. When more than one proxy instance runs, the production guidance also calls for Redis 7.0 or newer for shared rate limits and router state. Confirm the current database requirements in the LiteLLM documentation for the version you plan to run before you size the environment.

Does spend data from LiteLLM replace provider invoices?

No. LiteLLM spend tracking shows what the gateway recorded for each key, user and team, which is useful for budgets and internal chargeback, but it is an estimate built from the gateway's own calculations and pricing data. Provider invoices remain the record of what you were charged. Reconcile gateway spend against provider invoices each billing period, and check that pricing entries for each model match current provider rates. Differences usually come from pricing overrides, retries, cached responses or requests that bypassed the gateway, so agree on a reconciliation routine with finance before using the reports for decisions.

How DeployOpen works on this

DeployOpen plans, implements, documents and supports self-hosted LiteLLM inside your own infrastructure, including the virtual key, budget and spend tracking model. We agree the scope in writing before work starts, then build, test and hand over a configuration your team can review and operate.

How we scope

  • Inventory the teams, applications and providers that will receive virtual keys and budgets
  • Agree which models each key may call, and which private or approved providers sit behind them
  • Set written scope, deliverables and timelines for key, budget and spend reporting work before any build starts

How we build

  • Configure per-team, per-application and per-user budgets, plus TPM and RPM limits, with PostgreSQL as the backing database
  • Test model restrictions, budget exhaustion, temporary budget increases and key rotation against your own policies
  • Set up spend reporting exports and confirm the figures reconcile with provider invoices in your environment

How we hand over

  • Document the key issuance process, owner assignments, budget approval steps and escalation paths for your team
  • Provide runbooks for revoking keys, changing limits and reading spend reports without touching the database directly
  • Walk your platform, finance and security staff through the configuration and the evidence it produces

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after go-live
  • Retest key scoping and budget enforcement after LiteLLM version changes within your supported release line
  • Confirm with your team in writing which support terms apply, including any LiteLLM Enterprise support you choose to add

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.