App developers
You already have accounts and a product. You want each customer to bring a model-provider key into that product.
Bring your own key integration
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.
You already have accounts and a product. You want each customer to bring a model-provider key into that product.
BYOKI does not sign users in. You pass a tenant id and user id from the session your app already trusts.
@byoki/react renders the key form, model picker, and usage table. The browser package does not store the key.
Four steps, all on your server after the browser submits 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.
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.
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.
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.
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.
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.
"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} />;
}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.
@byoki/coreCapability routing, config validation, and provider interfaces for BYOKI.
@byoki/serverAuthenticated connection handlers and the development credential store for BYOKI.
@byoki/providersOpenAI, Anthropic, and Gemini adapters for BYOKI.
@byoki/pricingVersioned price catalog and cost estimates for BYOKI.
@byoki/reactSettings screen and typed host API client for BYOKI. Requires React 19.