Skip to content

Multi-tenant Isolation in LLM API: Keys, Quotas, Data, and Prompts

Cover: Multi-tenant Isolation in LLM API: Keys, Quotas, Data, and Prompts When a single LLM API serves multiple tenants—clients, teams, or projects—risks arise: data leakage between tenants, resource exhaustion by one consumer, context contamination in prompts, and exposure of system instructions. Isolation addresses these issues at the level of keys, quotas, storage, and prompts. Below is a practical schema that I apply in production.

Isolation Layers

Isolation is built layer by layer. Each layer addresses its own class of risks and does not replace the others.

Layer What Isolated Mechanism
Authentication API access Separate key per tenant
Quotas Resource usage Limits per key and per model
Context Data in prompt Namespace in storage
Prompts System instructions Tenant-bound templates
Cache Responses Tag tenant:<id> in key
Audit Incident analysis Logs with tenant identifier

Skipping any layer creates a window for leakage or abuse.

Keys and Quotas

Each tenant is issued a unique key. A shared key for all is unacceptable: it does not allow tracking usage or revoking access precisely.

tenants:
  - id: tenant-a
    api_key_ref: secret/tenant-a/key
    quotas:
      requests_per_minute: 120
      tokens_per_day: 5000000
      max_concurrent: 8
    allowed_models: [model-x, model-y]
  - id: tenant-b
    api_key_ref: secret/tenant-b/key
    quotas:
      requests_per_minute: 30
      tokens_per_day: 500000
      max_concurrent: 2
    allowed_models: [model-x]

Keys are stored in a secret store, with only a reference in the configuration. Key rotation does not require application code changes.

Quotas are applied at two levels: a global provider limit and a tenant limit. The global limit protects against account lockout, the tenant limit against monopolization. More on quota distribution is in the guide How to Manage LLM API Rate Limits and Budgets.

flowchart TD
    A[Request] --> B{Is Key Valid?}
    B -- no --> C[401]
    B -- yes --> D{Tenant Quota?}
    D -- exceeded --> E[429]
    D -- ok --> F{Model Allowed?}
    F -- no --> G[403]
    F -- yes --> H[Tenant Namespace]
    H --> I[LLM API Call]

Context and Data Isolation

All stores—vector database, cache, object storage, tables—receive a tenant_id field. Queries are always filtered by it, even if the identifier comes from a trusted source.

```python def retrieve(query: str, tenant_id: str, top_k: int = 5): return vector_db.search( query=query, top_k=top_k, filter={