All posts

Bring your own key (BYOK) for AI SaaS: letting enterprise customers use their own LLM account

Enterprise buyers ask to use their own LLM provider account or encryption keys. What BYOK means in an AI SaaS product, how to store customer keys, and what it does to cost, support and quality.

CodeKrypt 6 min read

A security questionnaire comes back with one line circled: "Can we use our own OpenAI or cloud account for the AI features?" Or it says "customer-managed encryption keys". Both get called BYOK for AI SaaS, and they are different projects. This post separates them, shows how to build the first one safely, and lays out what it does to your costs and your support load. It covers the domain in general, not any past CodeKrypt engagement.

What do enterprise customers mean by BYOK?

There are two requests hiding under one acronym:

RequestWhat the customer wantsWhat you build
Bring your own model accountYour product calls the LLM through their provider account or cloud projectPer-tenant credentials, per-tenant routing, error handling for their account limits
Bring your own encryption keyData you store for them is encrypted under a key they control and can revokeEnvelope encryption with a customer-managed key in a key management service
Bring your own model (a third, rarer ask)A specific model or endpoint they hostA provider interface that accepts a custom base URL and model name

Ask the buyer which one it is, and why. The reasons are usually procurement (they already have a negotiated contract with a provider), data handling (they want prompts to stay inside their own cloud account), or spend visibility (they want the bill on their own invoice). The "why" decides whether a cheaper answer, such as the controls in our post on LLM data retention and zero data retention, would satisfy them.

How does bring-your-own-model-account work?

The core change is that the model client stops being a global singleton. Each request resolves credentials for the tenant first:

  1. Look up the tenant's AI configuration: provider, model allow-list, and a reference to the stored credential.
  2. Decrypt the credential inside the service that makes the call, for the duration of the request.
  3. Call the provider with that credential, and tag the usage record with the tenant and key source.
  4. On an authentication or quota error, return a clear tenant-facing message rather than your generic failure.

Keep a platform key as the default and treat the customer key as an override. Tenants who have not configured anything keep working, and you keep a single code path with one extra lookup.

How should you store a customer's API key?

Treat it like a password to someone else's bill:

This is also where the prompt-injection and tool-permission thinking in AI agent security applies: an agent that can read configuration should never be able to read another tenant's secret.

What does BYOK do to cost, quality and support?

It changes who pays for tokens, but it does not make the feature free to run.

AreaPlatform keyCustomer key
Token billYou pay, and recover it through pricingCustomer pays their provider directly
Rate limitsShared across your tenantsTheir account limits apply, so one tenant's 429s are theirs
Model choiceYou choose and testCustomer may choose, so you test more combinations
Quality guaranteesYou can promise against your eval setOnly for models on your allow-list
SupportOne configuration to debugTheir account, quota and region settings to debug
Usage meteringYou meter to billYou still meter for limits and diagnostics

Three consequences are easy to miss:

Which failures should you design for?

A shared key fails in one way. A key per tenant fails in many ways at different times:

For each, decide whether to fail closed with a clear message, or fall back to the platform key. Falling back silently can break the very promise the customer asked for, namely that their data stays within their account, so make fallback an explicit per-tenant setting and default it to off for BYOK tenants. Provider-level fallback logic from LLM API fallback needs the same check.

What about customer-managed encryption keys?

If the request is about data at rest, the work is different and larger. You encrypt stored content (documents, conversation history, embeddings metadata) under a per-tenant key held in the customer's own KMS account, and you give them an audit trail and a revocation switch. AWS notes that customer managed keys give the customer full control over lifecycle and usage and carry a monthly fee plus per-request charges, so cost and latency both need budgeting.

Design questions to settle before you promise it:

What should you do next?

  1. Ask which BYOK the buyer means, and what they are trying to protect or control.
  2. Offer the lightest option that satisfies the reason: retention controls, a regional endpoint, or invoice visibility may be enough.
  3. If you build bring-your-own-account, ship the credential store, per-tenant routing and a model allow-list together, then meter by tenant from day one.
  4. Write the support boundary into the contract: which models are supported, who owns quota errors, and whether quality commitments apply.
  5. Treat customer-managed encryption as a separate project with its own estimate.

If your product is heading into enterprise sales and you want these tenant-level controls designed in from the start, that is the kind of work our AI SaaS development service covers.

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

What does BYOK mean for an AI SaaS product?
It is used for two different requests. Either the customer wants your product to call the LLM through their own provider account or API key, or they want their stored data encrypted under a key they control. Clarify which one before you scope anything.
Should I store a customer's LLM API key in my database?
Only encrypted, with access limited to the service that makes the model call, and never returned to the browser after it is saved. A secrets manager or envelope encryption with a key management service is the usual approach.
Does BYOK reduce my LLM costs?
It moves the model bill to the customer for the calls made with their key. Your own infrastructure, support and evaluation costs stay, and they usually grow because you now support more model and account configurations.
Can I promise the same answer quality with a customer's own key?
Only if you control which models the key may be used with. If the customer picks any model, quality becomes their choice and your SLA should say so.

Related reading

Chat on WhatsApp