DEV Community

Cover image for Stop rebuilding BYOK from scratch — I extracted it into a package
Adam Boon
Adam Boon

Posted on

Stop rebuilding BYOK from scratch — I extracted it into a package

Every AI SaaS project I've worked on hits the same wall.

You need to let users bring their own API keys — or your infrastructure needs to route across providers with fallbacks. Either way, you end up building the same thing: key validation, provider selection, cost estimation, health checks.

Then you maintain it. Then you build it again in the next project.

I got tired of it, so I extracted that layer into a package.


What it is

Restormel Keys is a headless BYOK and provider routing library for AI apps.


pnpm add @restormel/keys
Enter fullscreen mode Exit fullscreen mode
import { createKeys, openaiProvider, anthropicProvider } from "@restormel/keys";

const keys = createKeys(
  { routing: { defaultProvider: "openai" } },
  { providers: [openaiProvider, anthropicProvider] }
);

// Resolves which key to use: BYOK → fallback chain → platform key
const resolved = await keys.resolve("openai", "gpt-4o");

// Cost estimation before you make the call
const cost = keys.estimateCost("gpt-4o-mini");
Enter fullscreen mode Exit fullscreen mode

That's the core. Everything else builds on it.


What it actually handles

  • BYOK flows — users supply their own keys; you validate and store them however you want (the package is headless, no storage opinion)
  • Multi-provider routing — OpenAI, Anthropic, Google, plus 8 more (Mistral, Groq, Together, DeepSeek, Fireworks, Cohere, Perplexity, Azure)
  • Fallback chains — if a key fails, fall through to the next configured provider
  • Cost estimation — before you make a request, not after
  • Key validation — per-provider, with async persistence hooks
  • Policies — allow/deny models, enforce budget caps, keep routing behaviour inspectable

Framework support

The headless core works anywhere. UI components (KeyManager, ModelSelector,
CostEstimator) are available for SvelteKit today.

# SvelteKit
pnpm add @restormel/keys @restormel/keys-svelte

# React / Next.js App Router
pnpm add @restormel/keys @restormel/keys-react @restormel/keys-elements
Enter fullscreen mode Exit fullscreen mode

Before installing the UI packages, run npm view @restormel/keys-react version
to confirm availability. The headless core always works.


The CLI

npx keys init          # detect framework, generate config
npx keys add openai    # prompt, validate, store
npx keys validate      # exit 1 if invalid — good for CI
npx keys estimate gpt-4o-mini --input 10 --output 2
npx @restormel/doctor  # is everything wired up correctly?
Enter fullscreen mode Exit fullscreen mode

I've been dogfooding it

I've been running this in production through usesophia.app
worth checking out to see what a real BYOK integration looks like with this stack.


Early access

It's free to start. First 50 Pro signups get 12 months free — that's the
founding cohort offer while the product is in early access.

restormel.dev/keys


Two questions I'd genuinely like your input on:

  1. Is BYOK a real constraint you're dealing with, or do you absorb AI costs yourself?
  2. Is there another part of the AI product layer you keep rebuilding that should just be a package?

Enter fullscreen mode Exit fullscreen mode

Top comments (0)