npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@byomsdk/sdk

v0.3.0

Published

Bring Your Own Model - SDK for accessing user-owned AI providers via the Bring Your Model browser extension

Readme

@byomsdk/sdk

Browser SDK for websites that integrate with the Bring Your Model extension.

Bring Your Model lets users connect their own AI providers in a browser extension and approve which websites can use them. This SDK gives websites a small, zero-dependency API for text generation, streaming, embeddings, classification, extraction, chat sessions, extension events, and capability checks.

Requirements

  • Browser only — uses window, document, and crypto. Not for Node.js or SSR.
  • Users must have the Bring Your Model browser extension installed.
  • Users must configure at least one provider in the extension.
  • The site must be approved by the user before provider calls run.

Install

npm install @byomsdk/sdk

Quick start

import { byom } from '@byomsdk/sdk';

const available = await byom.isAvailable();
if (!available) {
  throw new Error('Bring Your Model extension is not available');
}

const caps = await byom.getCapabilities();
if (!caps?.vaultUnlocked) {
  throw new Error('Unlock the extension vault first');
}

const result = await byom.ask({
  task: 'summarize',
  input: 'Long text to summarize...',
});

console.log(result.text, result.costUSD);

Streaming

import { byom } from '@byomsdk/sdk';

async function runStream() {
  const gen = byom.stream({ input: 'Write a haiku about TypeScript.' });
  let result = await gen.next();

  while (!result.done) {
    console.log(result.value.text);
    result = await gen.next();
  }

  const finish = result.value;
  console.log(finish.model, finish.costUSD);
}

Chat session

import { byom } from '@byomsdk/sdk';

const session = byom.chat({ systemMessage: 'You are a concise assistant.' });

const reply = await session.send('What is BYOM?');
console.log(reply.text);

console.log(session.history());
session.close();

Error handling

All methods throw typed errors. Use instanceof for recoverable cases:

import {
  byom,
  BudgetExceededError,
  PermissionDeniedError,
  ExtensionNotInstalledError,
  ByomError,
} from '@byomsdk/sdk';

try {
  await byom.ask({ input: 'Hello' });
} catch (err) {
  if (err instanceof ExtensionNotInstalledError) {
    // prompt user to install the extension
  } else if (err instanceof PermissionDeniedError) {
    // site needs consent — trigger a request to open the consent flow
  } else if (err instanceof BudgetExceededError) {
    console.log(err.details); // { budgetType, current, limit }
  } else if (err instanceof ByomError) {
    console.log(err.code, err.message);
  }
}

Configuration

For advanced use, create a client with a custom timeout (applied on first getClient() call only):

import { getClient } from '@byomsdk/sdk';

const client = getClient({ timeoutMs: 60_000 });
await client.ask({ input: 'Long running task...' });

CDN (IIFE)

<script src="https://cdn.jsdelivr.net/npm/@byomsdk/sdk/dist/byom.iife.min.global.js"></script>
<script>
  byom.isAvailable().then(function (ok) {
    if (!ok) return;
    return byom.ask({ input: 'Hello from BYOM' });
  }).then(function (result) {
    if (result) console.log(result.text);
  });
</script>

The IIFE build attaches byom to window.byom.

Teardown

byom.destroy() disconnects the bridge and resets global state. Use in tests or SPA unmount — not required for normal pages.

Progressive enhancement (fallback)

import { createByomWithFallback, createInstallPromptState, getInstallUrl } from '@byomsdk/sdk';

const ai = createByomWithFallback({
  askFallback: async (req, signal) => {
    const res = await fetch('/api/ai/ask', {
      method: 'POST',
      body: JSON.stringify(req),
      signal,
    });
    return res.json();
  },
});

const state = await createInstallPromptState();
if (state.recommendedAction === 'install-extension') {
  window.location.href = getInstallUrl();
}

See fallback strategy.

OpenAI compatibility

import { OpenAI } from '@byomsdk/sdk/openai';

const client = new OpenAI();
const completion = await client.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Hello' }],
});

See OpenAI compat.

Prompt API shim

import { createPromptApi } from '@byomsdk/sdk/prompt-api';

const ai = createPromptApi();
const session = await ai.languageModel.create();
const text = await session.prompt('Summarize this page.');

See Prompt API compat.

API reference

Full API documentation: docs/sdk-api.md

Main methods

| Method | Description | |--------|-------------| | byom.isAvailable() | Ping the extension bridge | | byom.getCapabilities() | Version, supported tasks, grant/vault status | | byom.ask() | Single-shot text generation | | byom.stream() | Streaming text generation | | byom.embed() | Embedding vectors | | byom.classify() | Text classification | | byom.extract() | Structured extraction via JSON Schema | | byom.chat() | Multi-turn chat session | | byom.on() | Subscribe to extension events | | byom.destroy() | Tear down global bridge/client state |

License

Apache-2.0 — see LICENSE.