Guide and insight

Customer-Scoped AI API Keys: Isolate Tenants, Budgets, and Abuse Without Provider-Key Sprawl

SaaS products, agencies, and reseller platforms need customer-level AI access without exposing upstream provider credentials. Use gateway-issued virtual keys as policy handles for tenant attribution, model access, budgets, rate limits, revocation, rotation, and usage ledgers.

When a product lets many customers call AI models, the wrong primitive is often the upstream provider key. A provider key usually represents an account, project, workspace, or service account. Your product needs something narrower: a customer-facing key that identifies one tenant, customer, application, environment, model policy, budget, and audit rule.

That is the purpose of customer-scoped AI API keys. The gateway issues the key, authenticates requests, applies policy, meters usage, and then calls upstream providers using hidden credentials. Downstream customers never receive the provider key. They receive a stable contract with your platform.

Reader Problem: Customer Isolation Without One Provider Project Per Customer

SaaS builders, agencies, and reseller platforms usually need to answer practical questions before they can expose AI access downstream:

  • Which customer generated this usage?
  • Which application, environment, or integration made the call?
  • Which models and modalities are allowed?
  • How much can this customer spend this month?
  • What happens if a key leaks?
  • Can this customer be suspended without affecting everyone else?
  • Can usage be reconciled against provider reports later?

Provider-side projects and workspaces can help, but they are not always the right unit for every downstream customer. Creating one upstream boundary per customer can improve hard isolation and reporting, but it also creates provisioning overhead, quota fragmentation, credential sprawl, and more reconciliation work.

A gateway-issued key gives the product a customer-level control point even when upstream credentials are pooled. It also supports stronger modes, such as tenant-bound provider credentials or bring-your-own-key, when a customer needs contractual separation, residency boundaries, or direct provider account ownership.

Facts, Recommendations, and Predictions

Facts

  • OpenAI projects support members, service accounts, API keys, usage limits, budgets, and scoped project resources. That makes projects useful as upstream boundaries, but not automatically the right primitive for every end customer.
  • OpenAI usage reporting can group usage by dimensions such as project, user, API key, model, batch, and service tier. SaaS chargeback still needs those provider records joined to product-owned customer identifiers.
  • Anthropic workspaces separate API resources by use case, team, department, project, or product. API keys are tied to the workspace where they are created and cannot be moved between workspaces.
  • Anthropic usage and cost reporting supports grouping by API key, workspace, model, service tier, context window, data residency, and speed-related options, with costs returned in daily USD buckets.
  • Google Gemini API key guidance recommends restricting keys, and Gemini API keys are restricted to the Generative Language API by default. Application restrictions such as IP addresses may be available depending on deployment shape.
  • OWASP guidance treats API keys as required controls for protected endpoints and says keys should be revoked when clients violate usage agreements.
  • OWASP secrets guidance emphasizes least privilege, revocation when secrets are no longer required or are compromised, and automated rotation to reduce implementation error.

Recommendations

  • Use gateway-issued customer keys as policy handles, not just authentication tokens.
  • Keep upstream provider credentials hidden from downstream customers.
  • Write a gateway usage ledger at request time, before relying on provider dashboards.
  • Use provider projects or workspaces selectively for high-risk, high-volume, regulated, residency-sensitive, or contractually separate customers.
  • Build key rotation as an overlap workflow, not as an immediate breakage event.

Predictions

  • More providers will expose richer usage grouping and budget controls, but product-owned customer attribution will still be necessary for SaaS billing and reseller reporting.
  • Reseller and agency platforms will increasingly treat gateway keys as commercial objects: tied to plans, credit balances, scopes, and support workflows.
  • Customers with strict compliance or procurement needs will ask for BYOK or provider-account ownership, while most ordinary customers will prefer a managed gateway contract.

The Gateway Key Object

A customer-scoped key should resolve to a structured policy object. At minimum, model the key as more than a hash and a name.

{
  "key_id": "key_01J9...",
  "tenant_id": "tenant_acme",
  "customer_id": "cust_4812",
  "application_id": "app_support_bot",
  "environment": "production",
  "owner": {
    "type": "service_account",
    "id": "svc_support_ai"
  },
  "model_profile_id": "profile_support_standard",
  "allowed_modalities": ["text", "image_input"],
  "tool_policy_id": "tools_readonly_kb",
  "monthly_budget": {
    "currency": "USD",
    "amount": "500.00"
  },
  "rate_limits": {
    "requests_per_minute": 120,
    "input_tokens_per_minute": 250000,
    "output_tokens_per_minute": 80000
  },
  "retention_policy": "metadata_only",
  "status": "active",
  "created_at": "2026-09-05T10:00:00Z",
  "last_used_at": null
}

The exact fields will vary, but the principle should not: every incoming request resolves the key into tenant policy before dispatch. Authentication answers “who is calling?” Policy resolution answers “what may this caller do, how much may they spend, where may the request route, and what must be logged?”

This is also where semantic product strategy matters. A platform selling an AI API for agencies may need customer and campaign dimensions. A developer tool may need workspace and repository dimensions. A reseller may need external customer IDs that match its billing system.

Key Creation Workflow

Key creation should be deterministic enough for automation and strict enough for security review.

1. Create The Customer Record First

Do not create orphan keys. The key should belong to a tenant and a customer record before it exists. For reseller platforms, the customer record should include external IDs from the reseller’s CRM or billing system, plan metadata, tax or invoice grouping if needed, and a status field that can suspend all child keys.

2. Attach A Model Profile

A model profile maps customer-facing model names to provider models and capabilities. For example, support-standard might allow a balanced text model, image input, and no code execution. research-premium might allow long-context models, web search, and higher per-request ceilings.

Do not force downstream applications to hard-code provider model IDs. Use the gateway profile to manage availability, fallback, pricing, and deprecation.

3. Set Spend And Rate Limits

Use budgets and rate limits together. A monthly budget prevents invoice damage over time. Rate limits prevent sudden abuse, retry storms, or accidental loops from consuming the entire budget in minutes.

Useful controls include:

  • Monthly customer budget.
  • Daily soft cap for anomaly detection.
  • Per-key request rate.
  • Input and output token rate.
  • Per-request maximum estimated cost.
  • Tool-specific limits for hosted search, file processing, or code execution.

Budget enforcement should reserve estimated cost before dispatch, settle actual cost after completion, and release unused reserve. This connects the key policy to AI API billing instead of treating billing as a delayed reporting task.

4. Generate And Store The Secret Correctly

Display the plaintext secret once. Store only a strong hash, plus a short prefix or fingerprint for support lookup. The prefix helps support teams identify “the key ending in 8F2A” without seeing the secret.

A typical storage pattern is:

  • key_id: stable database identifier.
  • secret_hash: hash of the full secret using an appropriate password or token hashing strategy.
  • secret_prefix: short non-sensitive display prefix.
  • fingerprint: deterministic identifier for audit lookup.
  • created_by: user or Partner API client that created the key.
  • status: active, draining, revoked, quarantined, expired.

Never store upstream provider keys on the customer key object. Provider credentials belong in a separate credential vault with its own access rules.

Request-Time Enforcement

The gateway should treat each model call as a policy decision followed by a provider dispatch. A practical request path looks like this:

  1. Parse the presented gateway key.
  2. Look up the key hash and status.
  3. Resolve tenant, customer, application, environment, owner, and model profile.
  4. Check whether the tenant and customer are active.
  5. Validate requested model alias, modality, tools, retention mode, region, and service tier.
  6. Estimate request cost and reserve budget.
  7. Check rate limits and abuse thresholds.
  8. Select upstream credential mode: pooled, tenant-bound, or BYOK.
  9. Dispatch to the provider.
  10. Capture usage, cost, provider references, errors, and safety signals.
  11. Settle the budget reservation and write the final ledger event.

This sequence keeps the gateway responsible for the customer contract. Provider dashboards become reconciliation inputs, not the only source of truth.

Usage Ledger Fields That Actually Help Later

A gateway ledger should preserve enough detail to answer support, billing, abuse, and routing questions without requiring raw prompt storage by default.

Useful fields include:

  • request_id and trace_id.
  • tenant_id, customer_id, application_id, and key_id.
  • End-user identifier, preferably pseudonymous where appropriate.
  • Model alias requested by the customer.
  • Resolved upstream provider and model.
  • Input, output, reasoning, cached, audio, image, video, and tool usage where applicable.
  • Quoted cost, reserved amount, settled cost, currency, and pricing catalog version.
  • Provider request ID, usage report reference, project, workspace, or API key grouping dimension if available.
  • Retention policy applied.
  • Safety, abuse, or policy decision codes.
  • Error category and retry metadata.

This structure supports chargeback, customer support, incident response, and an API key management workflow that can answer “what did this key do?” without exposing unrelated tenants.

Credential Modes: Pooled, Tenant-Bound, And BYOK

Pooled Provider Credentials

In the default mode, many customer keys route through a smaller set of provider credentials. This is operationally simple and reduces provider-side sprawl. It works when the gateway has strong tenant attribution, budget enforcement, rate limiting, abuse isolation, and cache-boundary controls.

The trade-off is that provider-side reporting may only show the gateway credential or provider project. You must join provider records back to gateway ledger records to produce customer-level billing and analytics.

Tenant-Bound Provider Credentials

For larger or riskier tenants, bind a tenant to a dedicated provider project, workspace, service account, or key. This gives stronger upstream separation and may simplify provider-side reporting. It can also provide a hard quota backstop if the provider supports limits at that boundary.

The cost is operational complexity. Provisioning, rotation, provider limits, incident response, and reconciliation now happen across more upstream objects.

Bring Your Own Key

BYOK can be useful when customers must own the provider account, negotiate their own provider contract, or keep provider billing separate. The gateway still applies model profiles, routing policy, analytics, and application-level controls where possible.

The trade-off is support complexity. Each customer’s provider account may have different model access, quotas, pricing, retention settings, and incident status. The gateway must detect and explain these differences clearly.

Revocation And Quarantine

Revocation should block new requests immediately for a customer key without rotating unrelated upstream provider credentials. This is one of the main advantages of virtual keys.

Use separate states for different operational actions:

  • active: requests are allowed.
  • draining: old key is accepted during a rotation window, but warnings and audit events are emitted.
  • revoked: new requests are rejected permanently.
  • quarantined: new requests are blocked because of abuse, payment, policy, or incident response.
  • expired: key exceeded its lifetime and must be replaced.

Quarantine should be reversible when the incident is resolved. Revocation usually should not be reversible, because restoring old secrets increases confusion and risk.

When a key violates usage policy, log the reason, actor, time, and scope of enforcement. If the decision was automated, preserve the rule version and signals that triggered it. This keeps customer conversations factual.

Rotation Without Breaking Production

Key rotation should use a two-key overlap workflow:

  1. Create a replacement key with the same customer, application, model profile, and limits unless the operator changes them intentionally.
  2. Display the new secret once.
  3. Mark the old key as draining.
  4. Accept both keys for a bounded period, such as 7, 14, or 30 days depending on customer plan and risk.
  5. Emit usage warnings on the draining key.
  6. Notify the owner or Partner API client when the old key is still used near the deadline.
  7. Revoke the old key at the end of the window.
  8. Keep attribution across both key IDs under the same customer and application.

This avoids the common failure mode where a security improvement becomes a production outage. Rotation is still a control, but it becomes an operational workflow with evidence and deadlines.

Partner API Surface

If downstream platforms manage customers programmatically, expose key operations through a Partner API. The API should support idempotency keys and audit events because provisioning often happens inside billing, onboarding, or CRM workflows.

Minimum endpoints:

  • POST /customers: create or upsert a customer.
  • POST /customers/{customer_id}/keys: create a key.
  • GET /customers/{customer_id}/keys: list keys and statuses.
  • PATCH /keys/{key_id}: update scopes, owner, limits, model profile, or status.
  • POST /keys/{key_id}/rotate: create replacement and mark old key as draining.
  • POST /keys/{key_id}/revoke: revoke immediately.
  • GET /customers/{customer_id}/usage: return usage and cost by time range, key, app, model, or end-user dimension.

Every mutating request should accept an idempotency key. Every change should write an audit event with actor, target, before-and-after fields, source IP or client identity, and reason where available.

When To Use Provider Projects Or Workspaces

Do not treat gateway keys and provider boundaries as mutually exclusive. They solve different problems.

Use gateway keys for normal customer-level control:

  • Per-customer attribution.
  • Per-application keys.
  • Budget and rate limits.
  • Fast suspension.
  • Rotation workflows.
  • Usage analytics and reseller reporting.

Add provider projects, workspaces, or dedicated provider credentials when the customer needs stronger separation:

  • High monthly volume that deserves dedicated quotas.
  • Regulated workloads with explicit residency or retention requirements.
  • Contractual invoice separation.
  • Hard provider-side budget or quota backstops.
  • Dedicated abuse monitoring or safety review boundaries.
  • Customer-owned provider accounts through BYOK.

The practical default is gateway-enforced isolation with selective upstream hard boundaries. That keeps the common path simple while preserving an escalation path for customers that need more separation.

Implementation Checklist

  • Define a customer key schema with tenant, customer, application, environment, owner, model profile, limits, retention policy, and status.
  • Hash secrets at rest and display plaintext only once.
  • Separate gateway keys from upstream provider credential storage.
  • Resolve every request into policy before dispatch.
  • Reserve budget before provider calls and settle after final usage is known.
  • Record usage with customer, key, model alias, upstream model, token categories, tool usage, quoted cost, settled cost, and provider references.
  • Implement active, draining, revoked, quarantined, and expired states.
  • Support two-key rotation overlap.
  • Expose Partner API operations with idempotency keys.
  • Use provider projects or workspaces only where their operational cost is justified.

Actionable Conclusion

Customer isolation for AI access should usually start at the gateway key, not at the provider key. The gateway key is the customer-facing contract: it names the tenant, customer, application, model profile, budget, rate limit, retention rule, and audit policy. The provider key is an implementation detail behind that contract.

This architecture gives SaaS builders and reseller platforms fast revocation, accurate attribution, per-customer budgets, controlled rotation, and useful usage analytics without creating one upstream provider project for every customer by default. Use upstream projects, workspaces, tenant-bound credentials, or BYOK when the risk, volume, residency, or contract requires it. For the ordinary path, enforce customer isolation in the gateway ledger and policy engine, then reconcile provider records afterward.

Related reading

FAQ

Frequently asked questions

Are customer-scoped AI API keys the same as provider API keys?
No. A customer-scoped key is issued by the gateway and maps to product-owned policy: tenant, customer, application, model profile, budget, rate limit, retention, and audit rules. A provider API key is an upstream credential used by the gateway to call a model provider.
Should every customer get a separate provider project or workspace?
Usually no. Separate provider projects or workspaces are useful for high-risk, high-volume, regulated, residency-sensitive, or contractually separate customers. For ordinary customers, gateway keys with strong ledgers and policy enforcement are simpler and more flexible.
How should leaked customer keys be handled?
Block new requests by revoking or quarantining the gateway key immediately, preserve audit records, create a replacement key if appropriate, and review recent usage by key ID, customer ID, application ID, model, cost, and policy signals.
How does BYOK fit into this model?
BYOK lets a customer supply provider-owned credentials while the gateway still enforces application policy, usage analytics, and routing controls where possible. It reduces provider credential custody for the platform but increases support and reconciliation complexity.