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:
| Request | What the customer wants | What you build |
|---|
| Bring your own model account | Your product calls the LLM through their provider account or cloud project | Per-tenant credentials, per-tenant routing, error handling for their account limits |
| Bring your own encryption key | Data you store for them is encrypted under a key they control and can revoke | Envelope 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 host | A 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:
- Look up the tenant's AI configuration: provider, model allow-list, and a reference to the stored credential.
- Decrypt the credential inside the service that makes the call, for the duration of the request.
- Call the provider with that credential, and tag the usage record with the tenant and key source.
- 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:
- Never return it after saving. Show the last four characters and a rotation date, nothing more.
- Encrypt it at rest with envelope encryption: a data key encrypts the secret, and a key management service key encrypts the data key. AWS KMS documents this model of customer data keys protected under a KMS key, and a secrets manager gives you similar behaviour without writing it yourself.
- Limit who can decrypt. Only the service that makes model calls should hold that permission, not your admin dashboard or your support tooling.
- Keep keys out of logs and traces. Redact authorization headers in your request logging, and check that error reporters do not capture request configuration.
- Validate on save with a cheap test call, and re-validate on a schedule so an expired key shows up as a banner, not as a failed customer workflow.
- Support rotation without downtime: allow two active keys for a short overlap, as with any credential.
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.
| Area | Platform key | Customer key |
|---|
| Token bill | You pay, and recover it through pricing | Customer pays their provider directly |
| Rate limits | Shared across your tenants | Their account limits apply, so one tenant's 429s are theirs |
| Model choice | You choose and test | Customer may choose, so you test more combinations |
| Quality guarantees | You can promise against your eval set | Only for models on your allow-list |
| Support | One configuration to debug | Their account, quota and region settings to debug |
| Usage metering | You meter to bill | You still meter for limits and diagnostics |
Three consequences are easy to miss:
- Pricing: if you recover token cost through your pricing, a BYOK customer should not pay twice. Revisit the model in how to price AI features in a SaaS product and decide whether BYOK tenants get a platform fee instead of a usage component.
- Quality: restrict BYOK to an allow-list of models you have run through your evals. Our post on LLM evals in CI covers how to test each supported model before it is offered.
- Limits: your per-customer caps still matter, because a runaway agent loop on a customer's account is still your product's bug. See AI usage limits per customer.
Which failures should you design for?
A shared key fails in one way. A key per tenant fails in many ways at different times:
- The key is revoked, expires, or hits a spending cap, and the feature stops for that tenant only.
- The customer's account is in a different region, so latency and data-residency answers change.
- The customer's provider has a deprecation schedule you do not control. Plan for it as described in LLM model deprecation.
- Their account has no access to the model your prompts were tuned for.
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 happens to the product when the customer revokes the key? Search and chat over their data will stop, and that is the intent, but your error handling should say so.
- Is retrieval still possible? Encrypted-at-rest content must be decrypted to be embedded and searched, so check how your vector store and caches handle it. See multi-tenant RAG data isolation.
- Do prompts sent to the model count? Customer-managed keys protect your stored copy, not the text once it has gone to a provider.
What should you do next?
- Ask which BYOK the buyer means, and what they are trying to protect or control.
- Offer the lightest option that satisfies the reason: retention controls, a regional endpoint, or invoice visibility may be enough.
- 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.
- Write the support boundary into the contract: which models are supported, who owns quota errors, and whether quality commitments apply.
- 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.