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

@swartzrock/byok-runtime

v3.1.0

Published

Build BYOK AI apps with one TypeScript API for user-owned cloud keys, local models, model discovery, and CLI providers.

Readme

BYOK Runtime

npm CI License: MIT

Build BYOK AI apps with one TypeScript API for user-owned cloud keys, local models, model discovery, and CLI providers.

ESM-only · Node.js 20+ · trusted host runtimes only

Contributing? See CONTRIBUTING.md to build, test, and submit changes.

Install

npm install @swartzrock/byok-runtime

If your application creates Zod schemas directly, install zod as an application dependency too:

npm install zod

Quick Start

import { ByokProvider, generateText } from "@swartzrock/byok-runtime";

const { text } = await generateText({
	provider: ByokProvider.OpenAI,
	apiKey: process.env.OPENAI_API_KEY!,
	model: "gpt-4o-mini",
	instructions: "Answer for a technical audience. Be concise.",
	prompt: "Explain retrieval-augmented generation in two sentences.",
});

console.log(text);

Change the provider, credential, and model to run the same call against Anthropic, Google Gemini, xAI, OpenRouter, Groq, Mistral, DeepSeek, DeepInfra, Together AI, Fireworks AI, Ollama, or LM Studio.

BYOK Runtime is designed for trusted servers, desktop backends, Electron main processes, and local tools. Browser and Electron renderer UIs should call it through a trusted host boundary rather than receive provider credentials directly.

Why BYOK Runtime?

  • One generation API across cloud keys, local model servers, and authenticated CLI tools.
  • Lazy text streaming with explicit native or buffered delivery metadata.
  • Model discovery through a provider-neutral runtime API.
  • Connection testing with user-readable provider errors and rate-limit handling.
  • Reusable clients that bind a credential or local provider URL while keeping the model per call.
  • Optional structured output and custom transports through the lower-level provider runtime.
  • No built-in credential persistence: the host application owns storage, encryption, and runtime policy.

Provider Support

| Provider | Credentials | Model listing | Generation | | ------------ | ------------------- | ---------------------- | -------------------- | | Anthropic | API key or env | Account models | Text and object | | OpenAI | API key or env | Model IDs | Text and object | | Google | API key or env | Gemini model IDs | Text and object | | xAI | API key or env | Model IDs | Text and object | | OpenRouter | API key or env | Portable model options | Text and JSON-like | | Groq | API key or env | Model IDs | Text and JSON-like | | Mistral | API key or env | Model IDs | Text and JSON-like | | DeepSeek | API key or env | Model IDs | Text and JSON-like | | DeepInfra | API key or env | Model IDs | Text and JSON-like | | Together AI | API key or env | Model IDs | Text and JSON-like | | Fireworks AI | API key or env | Model IDs | Text and JSON-like | | Ollama | Local or remote URL | Installed models | Text | | LM Studio | Local or remote URL | Local model IDs | Text and JSON-like | | Codex CLI | Local CLI session | Codex model IDs | Text | | Claude CLI | Local CLI session | Anthropic model IDs | Text with JSON hints |

Cloud and local-server providers use the main entrypoint. CLI providers can spawn local commands and are available only from @swartzrock/byok-runtime/node.

Groq, Mistral, DeepSeek, DeepInfra, Together AI, and Fireworks AI reuse BYOK Runtime's OpenAI-compatible chat-completions and model-listing subset. This does not imply compatibility with every OpenAI API or provider-specific feature.

Optional instructions stay separate from the required user prompt and are never concatenated into it. Each provider maps instructions to its own native channel — see Instruction Channels in the API reference.

Common Workflows

Stream Text

Use streamText when the caller can render incremental output. Creating the stream is lazy: the provider request starts when iteration begins, not when streamText returns.

import { ByokProvider, streamText } from "@swartzrock/byok-runtime";

const { delivery, textStream } = streamText({
	provider: ByokProvider.OpenAI,
	apiKey: process.env.OPENAI_API_KEY!,
	model: "gpt-4o-mini",
	prompt: "Explain BYOK in one paragraph.",
});

let text = "";
for await (const delta of textStream) {
	text += delta;
}

console.log(delivery, text);

delivery is "native" for verified OpenAI-compatible routes and Ollama's fetch-backed transport. It is "buffered" when an adapter completes generation first and emits the exact text as one delta, including Codex CLI, Claude CLI, and unsupported custom transports. Concatenating all deltas reconstructs the generated text exactly.

The stream accepts the same optional signal as generateText. Aborting that signal, returning the iterator, or breaking from for await aborts the underlying request or local process. Streams are single-consumer. Rate-limit retries may occur before the first text delta; after a delta is emitted, BYOK never restarts the request and risk duplicating text. Existing generateText behavior is unchanged.

For reusable credentials, model discovery, connection testing, structured objects, local model servers, and local CLI providers, see the API reference.

Credentials and Security

Host applications own credential collection and storage; BYOK Runtime does not read process.env on its own, parse .env files, persist credentials, or log credential values. Explicit apiKey values are recommended — trusted scripts can opt into environment-backed credentials instead (see env-backed credentials for supported variable names).

instructions and prompt are ordinary caller-provided model content, not credentials; hosts should apply their normal content-handling and privacy policies to both. See the security policy for reporting instructions.

Hosts should pass the current persisted BYOK subtree through parseByokStoredSettings(unknown) before use — see Storage And Setup State.

Entry Points

  • @swartzrock/byok-runtime — API-key providers, Ollama, LM Studio, helpers, metadata, and shared types.
  • @swartzrock/byok-runtime/node — everything above plus provider discovery, local CLI providers, and command execution.

Import from these public entrypoints only. Files under src/providers and src/models are package internals.

Documentation and Examples

License

MIT. See LICENSE.