Blog

BYOK: Bring Your Own Key

15 April 2026, by Jasper Blues · Also published on Medium

A pop star who looks suspiciously like Björk A pop star who looks suspiciously like Björk

RAGE — Australia’s MTV

I grew up in Wollongong, Australia from the mid 70s through 90s. It is a small city, wedged between the ocean and the mountains, about 100 KM south of Sydney.

Sometimes there wasn’t a lot to do. People made their own fun. To this day I love letting my mind wander and seeing where it takes me.

Saturday mornings in the hours before sunrise we had culture. It worked its way in between the black-and-white snow on the analog TV, via a TV show called RAGE — like Australia’s MTV. This early morning slot was the weird stuff. Metal. Industrial.

One morning I missed it. The (usually boring) charts had already started, counting down from 50 to number 1. But somewhere right at the back, something slipped through.

Björk.

Barefoot. Unfiltered. It felt like it had leaked in. I remember thinking: this is going to be huge.

A week later, it was number one.

Today we’re going to talk about an Embabel feature inspired by Björk: BYOK — Bring Your Own Key. It solves a real problem.

The Problem

For decades, the world’s production systems have quietly run on Java. That’s one reason Embabel exists: it brings AI to where the software already is, instead of forcing teams to rebuild everything just to get close to the models.

But Embabel isn’t just about revitalizing legacy systems.

There are strong reasons to build new, AI-native apps on the JVM too.

And that’s where BYOK comes in.

Let’s say you have a great idea. You execute well. You’re selling directly to consumers.

For most of the internet era, distribution was the cheat code. Build something people love and it spreads. People tell people.

The Math Behind Virality

The maths is deceptively simple: if each user brings in just 1.1 new users on average, you have viral growth:

Round 1:   1 user
Round 10:  1.1¹⁰  ≈  2.6 users
Round 20:  1.1²⁰  ≈  6.7 users
Round 50:  1.1⁵⁰  ≈  117 users
Round 100: 1.1¹⁰⁰ ≈  13,780 users
Round 200: 1.1²⁰⁰ ≈  190,000,000 users

One tenth of one extra person. That’s it. Just one in ten people convincing someone else to try it.

Now introduce AI

Suddenly, usage is billed in tokens.

Every new user isn’t just a potential customer — they’re a cost center.

If you’re paying for their trial, customer acquisition is no longer cheap.

And you still have the original problem too: how do you convince someone to try your product before they’ve seen it work?

People will invest a bit of time if the upside is there. They’re far less willing to hand over a credit card.

Not before they trust you. Often, not before they’ve cleared it with their spouse or boss. And definitely not if cancelling might be painful.

BYOK changes the equation. It separates usage cost from product value.

If your customer already has an API key — from tinkering, from work, from other projects — they can use that to try your product. They pay for their own tokens. You pay almost nothing to acquire them.

If they don’t like it, they revoke the key. No refunds. No disputes. No awkward “what’s this charge?” conversations.

And when they do like it? That’s when you introduce the subscription.

Let’s Put Some Rough Numbers On It

Say your app is heavy — about $5/month in token usage per active user. You charge $10/month. Reasonable pricing.

By Round 200 you have 190 million users. (Yes, this is hypothetical — but the ratios are what matter.) Let’s say 10% convert:

Customer Acquisition Costs Customer Acquisition Costs

Without BYOK, you’re spending five dollars to acquire every dollar of revenue. Uh, yeah, not too sustainable.

Usually getting to millions of active users is a “good problem to have”, but it definitely isn’t when you’ve dug yourself a $760M hole!

You don’t want to be funding the trial usage of 190 million people.

With BYOK, you’re running at a 50% gross margin on paying customers — and your acquisition cost is effectively zero.

BYOK isn’t just a billing model. It is the funnel.

A product funnel A product funnel

Trial on their dime. Convert on yours.

And crucially, the viral loop survives because the cost of getting started is still effectively zero.

How It Works

In Embabel, LlmService is a key abstraction for working with LLMs.

You don’t talk to models directly. You talk through an LlmService, which handles model selection, retries, observation, and provider protocols.

Normally, you never think about this. Embabel ships Spring Boot starters for Anthropic, OpenAI, Mistral, DeepSeek and Gemini. Add one to your build, set your API key in environment variables, and an LlmService is auto-configured and ready to inject. It just works.

But there’s a catch: those starters are all wired to a single key — your key, set at deployment time. One application, one key per provider.

That’s fine when you’re absorbing the inference cost. It’s not fine when your users are bringing their own keys. You need an LlmService per key — validated, production-ready, and identical in behaviour to the auto-configured ones. That’s exactly what BYOK provides.

At the core is a single interface:

fun interface ByokFactory<out T> {
    fun buildValidated(): T
}

For LLMs, T is LlmService<*> — but the type parameter is deliberate. The same race-and-validate pattern works for any future BYOK-validated service: image generation, embeddings, anything else where a user-supplied key needs a low-cost probe before you trust it. The plumbing doesn’t care what it is.

Each supported provider ships a factory:

// Anthropic
val service = AnthropicModelFactory(apiKey = userKey).buildValidated()

// OpenAI
val service = OpenAiCompatibleModelFactory.openAi(userKey).buildValidated()
// DeepSeek, Mistral, Gemini - are all OpenAI compatible at API layer
val service = OpenAiCompatibleModelFactory.deepSeek(userKey).buildValidated()
val service = OpenAiCompatibleModelFactory.mistral(userKey).buildValidated()
val service = OpenAiCompatibleModelFactory.gemini(userKey).buildValidated()

buildValidated() makes a single low-cost probe call to the provider. If the key is valid, you get back a production LlmService — the same thing the starters give you, but bound to the user’s key instead of yours. If the key is invalid, you get an InvalidApiKeyException.

Plug the validated service straight into your prompt runner:

promptRunner
    .withLlmService(service)
    .creating(MyOutput::class.java)
    .create(messages)

The rest of your application doesn’t change.

Auto-Detection

People like quick starts — the user just pastes a key and doesn’t tell you which provider it’s from. For that, detectProvider() races all your candidates concurrently using virtual threads, and returns the first one that validates:

try {
    val service = detectProvider(
        AnthropicModelFactory(apiKey = userKey),
        OpenAiCompatibleModelFactory.openAi(userKey),
        OpenAiCompatibleModelFactory.deepSeek(userKey),
        OpenAiCompatibleModelFactory.mistral(userKey),
        OpenAiCompatibleModelFactory.gemini(userKey),
    )
    val provider: String = service.provider
} catch (e: InvalidApiKeyException) {
    // invalid key
}

“Quick Start” Automatic Key Type Detection “Quick Start” Automatic Key Type Detection

Adding Your Own Provider

If you’re running on an OpenAI-compatible provider that isn’t in the built-in list:

fun OpenAiCompatibleModelFactory.Companion.acme(apiKey: String) =
    OpenAiCompatibleModelFactory.byok(
        baseUrl = "https://api.acme.example.com/v1",
        apiKey = apiKey,
        validationModel = "acme-small",
        validationProvider = "Acme",
    )

LLM Provider Settings Screen in Embabel Hub LLM Provider Settings Screen in Embabel Hub

Security is Your Concern

This is worth being explicit about. Embabel provides the validation and service construction. What you do with the key after that — how you store it, how you transmit it, how long you keep it — is your application’s responsibility.

The Guide which is part of Embabel Hub shows one reasonable approach. The key principle: the server never persists the key.

After validation, the server encrypts the key with AES-256-GCM using a secret known only to the backend, and hands the encrypted blob back to the client. The client stores that blob on the user’s device. The plaintext key passes through server memory during the active session, but is never persisted to disk or database.

// After validation, encrypt the key and send it back to the client
val encryptedBlob = keyEncryptionService.encrypt(apiKey)
return SetKeyResponse(encryptedKey = encryptedBlob)
// On reconnect, the client sends the blob; server decrypts it for the session
val restored = keyEncryptionService.decrypt(blob) ?: return ResponseEntity.status(410).build()

Think about what this means from an attack surface perspective. There is no server-side key store to breach. An attacker would need to compromise individual user devices to get encrypted blobs — and those blobs are useless without the server’s secret.

If the server restarts with a new secret, existing client blobs become invalid. The user is simply prompted to re-enter their key. This limits the blast radius of a compromised server secret.

None of this is the only way to do it. The point is that BYOK doesn’t mandate a storage strategy — it just hands you a validated LlmService and gets out of the way.

And that’s the BYOK feature in a nutshell.

Why This Matters

The direction of AI is clear: more providers, more choice, more fragmentation.

Applications that lock users to a single provider, or absorb all inference costs will feel increasingly constrained.

The products that win will meet users where they are, with whatever key they already have. BYOK makes that straightforward.

One validated service. One clean exception. One detectProvider() call.

The rest of your application doesn’t change.

Björk went to number one in the 90s. Now you can go to number one with your Embabel-powered app

← All posts