Feature · key management

BYOK for AI APIs: bring your own key

Keep control of the key material that protects your AI data, without pretending that key custody is the whole security programme. This page separates the custody models, the encryption mechanics and the operational failure modes.

Short answer. BYOK means your organisation controls the key that protects data at rest, usually through a cloud KMS or HSM. The provider wraps and unwraps data keys through that service. It changes custody, not the need for access control, audit and rotation. Verify the key-wrap protocol, regions, operator access and failover behaviour in the current contract; do not treat the label as a certification.

Two meanings of BYOK

MeaningWhat you bringWhat it controlsWhat it does not control
Gateway BYOKYour own OpenAI, Anthropic or cloud keyWhich upstream account pays and which quota appliesHow the gateway stores prompts or logs
Encryption BYOK / CMEKA key in your KMS or HSMWho can unwrap the data-encryption keysApplication access, retention or model behaviour
HYOKKey material held outside the providerProvider cannot use the key without your serviceAvailability if your key service is down

Most enterprise RFPs mean the second row. If a vendor answers “yes, BYOK” but cannot name the KMS, the key-wrap algorithm, the region and the audit events, the answer is not yet an architecture.

Key custody models

ModelWho holds the KEKProvider can read?Operational cost
Provider-managedProviderYes, under its controlsLowest
CMEK / BYOKCustomer KMS, provider calls itOnly through your key policyMedium; key policy and region drift
HYOK / externalCustomer HSM or key serviceNo, unless your service releases the keyHigh; availability and latency
Client-sideCustomer applicationNo; provider sees ciphertextHighest; limited model features

Plugsky documentation describes customer-managed keys through AWS KMS, GCP KMS, Azure Key Vault, HashiCorp Vault, Thales Luna and AWS CloudHSM. Treat that as a starting list, not a promise for every region or plan; verify integrations, key specs and failure behaviour in the contract.

Envelope encryption

Envelope encryption avoids sending data to the KMS. The service asks KMS for a data key, encrypts the payload, stores the ciphertext and wrapped key, then discards the plaintext key. To read, it sends the wrapped key back to KMS.

  1. Generate a data encryption key (DEK) through KMS.
  2. Encrypt the prompt, response or stored object with the DEK.
  3. Store the ciphertext and the KMS-wrapped DEK together.
  4. On read, ask KMS to unwrap the DEK, decrypt, and clear the plaintext key.
import boto3, base64
from cryptography.fernet import Fernet

kms = boto3.client("kms", region_name="me-central-1")

def encrypt(payload: bytes, key_id: str):
    dek = kms.generate_data_key(KeyId=key_id, KeySpec="AES_256")
    f = Fernet(base64.urlsafe_b64encode(dek["Plaintext"]))
    return {
        "ciphertext": f.encrypt(payload),
        "wrapped_key": dek["CiphertextBlob"],
    }

def decrypt(blob, key_id: str):
    plaintext_key = kms.decrypt(
        CiphertextBlob=blob["wrapped_key"], KeyId=key_id
    )["Plaintext"]
    f = Fernet(base64.urlsafe_b64encode(plaintext_key))
    return f.decrypt(blob["ciphertext"])

A production implementation needs authenticated encryption, key caching, zeroisation and an audit event per unwrap. The KEK never leaves KMS in plaintext.

Rotation and multi-region keys

Rotation has two different jobs. Rotating the KEK changes the key that wraps DEKs; existing ciphertext is re-wrapped, not re-encrypted. Rotating a DEK requires re-encrypting the object.

KeyTypical cadenceWhat changesImpact
KEK / master keyAnnual or per policyNew wrapping key; old DEKs re-wrappedLow if the old key stays available for unwrap
DEKPer object or per cryptoperiodNew data key; object re-encryptedHigh for large corpora
API key90 days or on suspicionNew bearer tokenDeploy and revoke; no data rewrite
Break-glass keyQuarterly testProcedure, not routine rotationRequires two-person approval

Use one key per region and per environment. A key in me-central-1 should not be the only way to decrypt data in eu-west-1; a regional outage becomes a data outage. Replicate the key policy deliberately, and record which key ID protected which object. For per-provider keys, keep separate keys for separate upstream accounts so a revoked key does not take down every model.

Audit and failure modes

Log every key operation with actor, key ID, operation, resource, request ID, decision and source IP. Never log plaintext key material or the payload. Export the trail to your SIEM and keep it for the retention period your regulator or contract requires.

FailureSymptomMitigation
KMS outageUnwrap calls fail; new reads stallCache DEKs within cryptoperiod; test break-glass
Key revokedEvery request fails immediatelyTwo-person change control; staged rotation
Wrong regionKey not found or latency spikeRegion-scoped key map; failover test
Permission driftIntermittent AccessDeniedInfrastructure as code; policy tests
Deleted keyPermanent data loss after waiting periodDeletion protection; 7–30 day wait; approval
Rotation raceOld ciphertext cannot be readKeep old key for unwrap; version the key ID

Test the failure mode, not the happy path. Disable the key in a staging account and measure what the application does. A BYOK design that has never lost its KMS has an untested single point of failure.

Migration and when BYOK is not worth it

  1. Inventory data stores, regions and retention periods.
  2. Choose the custody model and the KMS/HSM integration.
  3. Create keys, policies and break-glass procedures in staging.
  4. Backfill: encrypt existing objects with new DEKs; record key IDs.
  5. Cut over reads and writes; monitor unwrap latency and error rate.
  6. Keep the old keys available for the retention window, then retire them.

BYOK is not worth it when the data is public or low-sensitivity, when no contract or regulator requires customer-held keys, or when the team cannot operate a KMS, rotation and break-glass process. Provider-managed encryption with strong access controls is often better for a small team.

For the wider control set, read what BYOK means for AI and API keys, RBAC, SSO and audit logs. Enterprise deployment and contract terms are covered in the enterprise guide. Compliance note: BYOK does not by itself make a workload HIPAA-compliant, PCI-compliant or resident in a jurisdiction. A BAA, access review, retention terms and a security assessment are separate; verify the current terms in the contract with counsel review.

FAQ

What does BYOK mean for an AI API?

It usually means the customer controls the encryption key that protects data at rest, through a cloud KMS or HSM. It can also mean bringing your own model-provider API key to a gateway. They are different controls; name them separately.

Does BYOK mean the provider cannot read my data?

Not automatically. It depends on where encryption and decryption happen and whether the provider can call your KMS. Verify the key-wrap protocol, operator access and audit trail in the contract; do not infer zero access from the BYOK label.

How often should keys rotate?

Set a cryptoperiod that matches your policy and the provider's limits. Annual KEK rotation is common, with 90-day rotation for API keys and immediate rotation after exposure. Rotation should re-wrap data keys, not re-encrypt the entire corpus.

What happens if my KMS is unavailable?

New writes or reads that need the key fail unless you have cached data keys within their cryptoperiod or a documented break-glass path. Test the failure mode before production; a key-management outage is a data-availability incident.

Is BYOK required for HIPAA?

BYOK is not a substitute for a HIPAA compliance programme. A BAA, access controls, audit logs, retention terms and a security review are separate. Verify the current terms with counsel; this page is not a certification or legal opinion.

Sources

AWS KMS envelope encryption, checked 20 November 2026: docs.aws.amazon.com/kms. NIST SP 800-57 Part 1 Rev. 5, checked 20 November 2026: csrc.nist.gov. OWASP Secrets Management Cheat Sheet, checked 20 November 2026: cheatsheetseries.owasp.org.

Reviewed 20 November 2026. Key-management integrations and contract terms were checked against the Plugsky documentation on that date and are subject to change. This page is not legal, audit or certification advice. HIPAA, PCI, residency and key-custody claims require verification in the current contract and counsel review.