Bring your own key integration

Add bring-your-own API keys to your app.

BYOKI is a TypeScript SDK for developers. Your users connect their own OpenAI, Anthropic, or Gemini key. You keep authentication. The SDK stores the key on your server, routes each feature to the model they picked, and records usage without keeping the prompt.

Who it is for

App developers

You already have accounts and a product. You want each customer to bring a model-provider key into that product.

Your auth stays yours

BYOKI does not sign users in. You pass a tenant id and user id from the session your app already trusts.

A settings screen included

@byoki/react renders the key form, model picker, and usage table. The browser package does not store the key.

How a key moves

Four steps, all on your server after the browser submits the key.

1 · Capture

The browser posts the key

The reference UI uses a password field and sends the key to your host with the session cookie and a CSRF token. It does not write the key to localStorage or sessionStorage.

2 · Encrypt

The server seals it

Production storage is yours: a secrets manager or envelope encryption. The development file store uses AES-256-GCM and BYOKI_MASTER_KEY, which never sits in the data file.

3 · Scope

One user, one record

Rows are stored under the tenant and user your auth resolved. Read APIs return “connected”. They do not return the key. Another user cannot list, replace, or delete it.

4 · Call

Use it, then forget the prompt

The router loads the key only for that provider call, then writes a usage row with tokens, latency, and estimated cost. The ledger does not store the prompt, the response, or the key.

Integration is a config object and one call

Declare the capabilities your product offers, then invoke through the signed-in user. The packages are ESM-only and need Node 20 or newer. @byoki/react needs React 19.

server.ts
import { defineAIConnections } from "@byoki/core";
import { createAIConnectionsApp } from "@byoki/server";
import {
  MANUAL_CATALOG,
  PROVIDER_LINKS,
  createProviderAdapters,
} from "@byoki/providers";
import { PRICE_CATALOG, estimateCost } from "@byoki/pricing";

const ai = createAIConnectionsApp({
  config: defineAIConnections({
    appName: "Your app",
    capabilities: {
      chat: {
        description: "Answers questions for the signed-in user.",
        providers: ["openai", "anthropic", "gemini"],
        userCanChooseModel: true,
        required: true,
      },
    },
  }),
  adapters: createProviderAdapters(),
  catalog: MANUAL_CATALOG,
  links: PROVIDER_LINKS,
  estimateCost: (args) => estimateCost(PRICE_CATALOG, args),
});

// tenantId and userId come from your session. Do not take them from the browser.
await ai.router.forScope({ tenantId, userId }).invoke({
  capability: "chat",
  input: [{ role: "user", text: "Summarize this note." }],
});

Mount the settings screen in a client component and pass the CSRF token from your session.

settings-screen.tsx
"use client";

import { useMemo } from "react";
import { AIConnectionsSettings, createConnectionsClient } from "@byoki/react";

export function SettingsScreen({ csrfToken }: { csrfToken: string }) {
  const client = useMemo(
    () => createConnectionsClient({ baseUrl: "/api/ai", csrfToken }),
    [csrfToken],
  );
  return <AIConnectionsSettings client={client} />;
}

This site is safe to click through

No shared accounts. The live demo gives each browser its own anonymous session. There is no alice/alice login that lets a stranger open someone else’s keys.

Mock mode is the default. With BYOKI_USE_MOCK=1, or when that variable is unset, requests stay inside the mock adapter. The server does not need a provider key, and a key typed into the demo is not sent to OpenAI, Anthropic, or Gemini.

Short memory. The default store keeps keys in the Node process for two hours, then drops them. Ending the session deletes them immediately. They are not written to disk and request logs do not include them.

Packages

@byoki/core

Capability routing, config validation, and provider interfaces for BYOKI.

@byoki/server

Authenticated connection handlers and the development credential store for BYOKI.

@byoki/providers

OpenAI, Anthropic, and Gemini adapters for BYOKI.

@byoki/pricing

Versioned price catalog and cost estimates for BYOKI.

@byoki/react

Settings screen and typed host API client for BYOKI. Requires React 19.