SDK & npm package
The complete API of the brimkern package: a chat widget in one call, or headless sessions and one-shot generation for your own UI. Everything runs on the visitor’s GPU — no server, no API key, nothing leaves the browser. For the guided tour and live demo, see the SDK page.
Install
From npm — TypeScript types included:
npm i brimkern
import { embed, createSession, generate, preload, status } from 'brimkern';Or as a script tag, with no build step — the IIFE exposes the same API on a global:
<script src="https://brimkern.com/sdk.js"></script>
<script>
Brimkern.embed({ title: "Ask us anything" });
</script>embed(config?)
Mounts the chat widget in the page (it waits for the document if called early). The model downloads only when a visitor actually opens the widget: your page speed is untouched.
systemstringtitlestringgreetingstringaccentstringmodelstringmaxTokensnumberexamples{ user, assistant }[]knowledge / knowledgeBudgetsee belowworker / workerUrlboolean / stringcreateSession(config?)
Headless: a conversation object for your own interface. Same config as embed() minus the visual options, plus temperature.
const session = createSession({ system: "You are a sommelier.", temperature: 0.7 });
const reply = await session.ask("A wine for oysters?", {
onToken: (text) => output.textContent += text, // streaming
signal: controller.signal, // cancellable
});
session.history // the Msg[] so far
session.reset() // same config, blank history
session.destroy()generate(options)
One shot: a prompt, a reply, no history kept. Takes the session config plus prompt, onToken and signal.
const answer = await generate({
system: "Answer in one sentence.",
prompt: "Why is the sky blue?",
onToken: (text) => process(text),
});Knowledge documents
Give the assistant your content — pages, FAQs, product sheets. Documents are chunked into passages in the browser, and only the 1–3 passages closest to the visitor’s question are given to the model. The ranking is local (lexical): nothing is sent anywhere.
knowledge: [
"Plain strings work.",
{ title: "Shipping", text: "Free in France from 60 euros." },
],
knowledgeBudget: 800 // max tokens of passages per questionpreload() & status()
preload() downloads the engine and the model ahead of the first question — call it on a hover, or on the pricing page before support opens. onProgress receives the phase and, during download, the bytes: enough for a real progress bar.
await preload({
onProgress: (status, p) => {
if (p) bar.style.width = (100 * p.loaded / p.total) + "%";
},
});
status() // 'unavailable' (no WebGPU) | 'idle' | 'loading' | 'ready' | 'error'status() answers synchronously — use it to decide whether to show the widget at all on browsers without WebGPU.
Versions & CDNs
Pin a version if you would rather the widget did not change under your feet:
https://brimkern.com/sdk-0.1.0.js instead of https://brimkern.com/sdk.js <!-- or from the npm CDNs --> https://unpkg.com/brimkern@0.1.0/dist/brimkern.iife.js https://cdn.jsdelivr.net/npm/brimkern@0.1.0/dist/brimkern.iife.js
Servers, licence, links
Importing the package on a server does nothing until a browser runs it: Next.js, Remix and Astro pass without guards. MIT licence, like the whole engine.
Brimkern — open WebGPU engine, built by Romain Khanoyan. Local AI, WebGPU, on-device engines.