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

@sovea/node-llm-gateway

v0.0.1-alpha.1

Published

Gateway for local LLM backends in NodeJs.

Readme

@sovea/node-llm-gateway

Gateway for local LLM backends in NodeJs.

@sovea/node-llm-gateway is a backend-first runtime and protocol adapter for local model access. The current built-in protocol is OpenAI-compatible Chat Completions. You can call the gateway in-process through a fetch-style facade, or expose the same routes through an optional localhost HTTP server.

Install

pnpm add @sovea/node-llm-gateway

This package is ESM-only and requires Node.js 20 or newer.

Quick Start

Create backend instances, bind public model ids to those backends, then create a gateway from the runtime.

import {
  createGateway,
  createModelRuntime,
  defineModel,
  llamaCppArtifacts,
  nodeLlamaCppBackend,
} from '@sovea/node-llm-gateway'

const runtime = createModelRuntime({
  backends: [
    nodeLlamaCppBackend({
      id: 'node-llama',
      cacheDir: './models',
      artifacts: llamaCppArtifacts({
        model: { source: 'hf:user/model:Q4_K_M' },
      }),
    }),
  ],
  models: [
    defineModel({
      id: 'local-llama',
      aliases: ['default'],
      backend: 'node-llama',
      backendModelId: 'local-llama',
    }),
  ],
})

const gateway = createGateway({
  runtime,
  protocols: ['openai'],
})

const response = await gateway.fetch('/v1/chat/completions', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    model: 'default',
    messages: [{ role: 'user', content: 'Say hello' }],
  }),
})

console.log(await response.json())

To expose the same gateway over localhost, use serveGateway(...):

import { serveGateway } from '@sovea/node-llm-gateway'

const served = serveGateway({
  runtime,
  port: 8080,
  protocols: ['openai'],
})

await served.ready
console.log(served.url)
await served.dispose()

served.close() closes only the HTTP server by default. served.dispose() closes the HTTP server and disposes the runtime. Pass disposeRuntimeOnClose: true when close() should also dispose the runtime.

Current Support

Implemented protocol support is limited to OpenAI-compatible Chat Completions:

  • GET /v1/models
  • GET /v1/models/:id
  • POST /v1/chat/completions
  • GET /gateway/models
  • GET /gateway/models/:id

Model Bindings

The public model id is separate from the backend model id:

defineModel({
  id: 'public-name',
  aliases: ['default'],
  backend: 'llama-remote',
  backendModelId: 'actual-llama-server-model-name',
})

Backends

Built-in backend helpers are backend-first. They implement model loading, generation, streaming, disposal, and capability declarations. Protocol route semantics stay in the OpenAI protocol adapter.

node-llama-cpp

nodeLlamaCppBackend({
  id: 'node-llama',
  cacheDir: './models',
  artifacts: llamaCppArtifacts({
    model: { source: 'hf:user/model:Q4_K_M' },
  }),
})

This backend resolves artifacts through node-llama-cpp, lazy-loads the model, enforces text-only input, supports streaming, function tool calls, JSON mode, and Structured Outputs, and serializes generation per backend instance to protect mutable sessions.

The gateway does not execute tools. Tool definitions are passed to the backend so the model can request function tool calls, which are returned to the caller.

llama-server

Managed mode starts one private llama-server process for the backend instance:

llamaCppServerBackend({
  id: 'vision-local',
  binaryPath: '/usr/local/bin/llama-server',
  cacheDir: './models',
  artifacts: llamaCppArtifacts({
    model: { source: '/models/vision-model.gguf' },
    mmproj: { source: '/models/mmproj.gguf' },
  }),
  args: ['--ctx-size', '8192'],
  apiKey: 'auto',
  capabilities: {
    inputModalities: ['text', 'image'],
    outputModalities: ['text'],
    features: ['streaming'],
  },
})

Remote Runtime

Electron apps can expose a model runtime over a transport and use it from another process:

import {
  createGateway,
  createInMemoryRuntimeTransport,
  createRemoteModelRuntime,
  exposeModelRuntime,
} from '@sovea/node-llm-gateway'

const transport = createInMemoryRuntimeTransport()
exposeModelRuntime(runtime, transport)

const gateway = createGateway({
  runtime: createRemoteModelRuntime({ transport }),
  protocols: ['openai'],
})

Custom transports implement GatewayRuntimeTransport and GatewayRuntimeServerTransport.

Development

pnpm install
pnpm test -- --run
pnpm run typecheck
pnpm run build

License

MIT