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

ai-server

v2.0.1

Published

An OpenAI and Claude API compatible server using node-llama-cpp for local LLM models

Readme

AI Server

A TypeScript microservice that provides an API compatible with OpenAI and Claude for working with local LLM models through node-llama-cpp.

Features

  • 🔄 Full compatibility with OpenAI Chat API (/v1/chat/completions)
  • 🤖 Compatibility with Anthropic Claude API (/v1/messages)
  • 🐟 Full compatibility with DeepSeek API (/v1/chat/completions)
  • 🌊 Support for streaming generation (Streaming API)
  • 🔑 Your own API key authentication
  • 🧠 Run local LLM models in GGUF format
  • ⚙️ Configuration through environment variables
  • 🔍 Monitoring via /health endpoint
  • 📋 Standard API for retrieving model list (/v1/models)

Requirements

  • Node.js 18+
  • TypeScript 5.3+
  • GGUF model (Llama 2, Mistral, LLaMA 3, or other compatible models)
  • Recommended minimum 16 GB RAM for 7B models

Installation

  1. Clone the repository:

    git clone https://github.com/ivanoff/ai-server.git
    cd ai-server
  2. Install dependencies:

    npm install
  3. Create a directory for models:

    mkdir -p models
  4. Download a GGUF model into the models/ directory (for example, from Hugging Face)

  5. Copy the example .env file and configure it to your needs:

    cp .env.example .env
  6. Compile TypeScript:

    npm run build
  7. Start the server:

    npm start

Project Structure

ai-server/
├── src/
│   └── server.ts         # Main server code
├── models/               # Directory for GGUF models
├── dist/                 # Compiled files
├── .env                  # Configuration
├── package.json
└── tsconfig.json

Configuration

Configure the .env file to change server parameters:

# Path to the model (absolute or relative to project root)
MODEL_PATH=./models/llama-2-7b-chat.gguf

# Server port
PORT=3000

# Default maximum number of tokens
DEFAULT_MAX_TOKENS=2048

# Number of model layers to offload to GPU (0 for CPU-only)
GPU_LAYERS=120

# API key for authentication
API_KEY=your_api_key

Usage Examples

OpenAI API compatible request

const response = await fetch('http://localhost:3000/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_api_key'
  },
  body: JSON.stringify({
    model: 'llama-local',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Tell me about TypeScript' }
    ],
    max_tokens: 500,
    temperature: 0.7
  })
});

const data = await response.json();
console.log(data);

Anthropic Claude API compatible request

const response = await fetch('http://localhost:3000/v1/messages', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your_api_key'
  },
  body: JSON.stringify({
    model: 'llama-local',
    messages: [
      { role: 'human', content: 'Tell me about TypeScript' }
    ],
    max_tokens: 500,
    temperature: 0.7
  })
});

const data = await response.json();
console.log(data);

Streaming mode

To use streaming mode, add the stream: true parameter to the request and process the event stream:

const response = await fetch('http://localhost:3000/v1/chat/completions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'llama-local',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Tell me about TypeScript' }
    ],
    max_tokens: 500,
    temperature: 0.7,
    stream: true
  })
});

// Process the event stream
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  
  const chunk = decoder.decode(value);
  const lines = chunk.split('\n').filter(line => line.trim() !== '');
  
  for (const line of lines) {
    if (line.startsWith('data: ') && line !== 'data: [DONE]') {
      const jsonData = JSON.parse(line.replace('data: ', ''));
      console.log(jsonData);
    }
  }
}

API Endpoints

/v1/chat/completions

OpenAI Chat API compatible endpoint.

Request Parameters:

  • messages: Array of message objects with role and content
  • model: Model identifier (optional)
  • max_tokens: Maximum tokens to generate (optional)
  • temperature: Randomness of generation (optional)
  • stream: Enable streaming mode (optional)

/v1/messages

Claude API compatible endpoint.

Request Parameters:

  • messages: Array of message objects with role and content
  • model: Model identifier (optional)
  • max_tokens: Maximum tokens to generate (optional)
  • temperature: Randomness of generation (optional)
  • stream: Enable streaming mode (optional)

/health

Health check endpoint that returns server status and model path.

/v1/models

Returns a list of available models (currently returns a single model, llama-local).

Development

  • Run in development mode with hot reloading:

    npm run dev
  • Watch for TypeScript changes:

    npm run watch

License

MIT

Created by

Dimitry Ivanov [email protected] # curl -A cv ivanoff.org.ua