← Back to blog

Multi-tenant BYOK LLM architecture

2026-05-22 · 7 min read

BYOK is the right model for a multi-tenant platform that orchestrates LLM calls. It removes the markup of model usage, gives each tenant transparency over their own provider bill, and shrinks the operator's risk surface: we never hold "the OpenAI key everyone shares."

Per-user table service_keys(owner_user_id, provider, key_enc, label, ...). Six providers. Each row's key_enc is the result of shared.utils.crypto.encrypt_blob(plaintext), Fernet-encrypted with a server-side master key.

Decryption happens only inside the worker that is about to call the provider. The plaintext lives in a local variable, gets passed to the httpx client, goes out of scope when the call returns. No background process holds plaintext for any user.

Every user-scoped table carries owner_user_id UUID NOT NULL. The api router wraps each request with the authenticated user's id, and every SQL query joins on it. Cross-tenant reads return HTTP 404 — the existence of another tenant's resource is never telegraphed.

Each user row carries a tier_quotas JSONB column with defaults: 3 messenger accounts, 1 Android device, 5 personas, 50 voice sessions per day. Operator can lift any of them per user. Quotas are enforced server-side at create-time.

Start free trial → · All features →


Related