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

genai-lite

v0.7.3

Published

A lightweight, portable toolkit for interacting with various Generative AI APIs.

Downloads

572

Readme

genai-lite

A lightweight, portable Node.js/TypeScript library providing a unified interface for interacting with multiple Generative AI providers—both cloud-based (OpenAI, Anthropic, Google Gemini, Mistral) and local (llama.cpp, stable-diffusion.cpp). Supports both LLM chat and AI image generation.

Features

  • 🔌 Unified API - Single interface for multiple AI providers
  • 🏠 Local & Cloud Models - Run models locally with llama.cpp or use cloud APIs
  • 🖼️ Image Generation - First-class support for AI image generation (OpenAI, local diffusion)
  • 🔐 Flexible API Key Management - Bring your own key storage solution
  • 📦 Zero Electron Dependencies - Works in any Node.js environment
  • 🎯 TypeScript First - Full type safety and IntelliSense support
  • Lightweight - Minimal dependencies, focused functionality
  • 🛡️ Provider Normalization - Consistent responses across different AI APIs
  • 🎨 Configurable Model Presets - Built-in presets with full customization options
  • 🎭 Template Engine - Sophisticated templating with conditionals and variable substitution
  • 📊 Configurable Logging - Debug mode, custom loggers (pino, winston), and silent mode for tests

Installation

npm install genai-lite

Set API keys as environment variables:

export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GEMINI_API_KEY=AIza...

Quick Start

Cloud Providers (OpenAI, Anthropic, Gemini, Mistral)

import { LLMService, fromEnvironment } from 'genai-lite';

const llmService = new LLMService(fromEnvironment);

const response = await llmService.sendMessage({
  providerId: 'openai',
  modelId: 'gpt-4.1-mini',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Hello, how are you?' }
  ]
});

if (response.object === 'chat.completion') {
  console.log(response.choices[0].message.content);
}

Local Models (llama.cpp)

import { LLMService } from 'genai-lite';

// Start llama.cpp server first: llama-server -m /path/to/model.gguf --port 8080
const llmService = new LLMService(async () => 'not-needed');

const response = await llmService.sendMessage({
  providerId: 'llamacpp',
  modelId: 'llamacpp',  // Generic ID for whatever model is loaded
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Explain quantum computing briefly.' }
  ]
});

if (response.object === 'chat.completion') {
  console.log(response.choices[0].message.content);
}

Image Generation

import { ImageService, fromEnvironment } from 'genai-lite';

const imageService = new ImageService(fromEnvironment);

const result = await imageService.generateImage({
  providerId: 'openai-images',
  modelId: 'gpt-image-1-mini',
  prompt: 'A serene mountain lake at sunrise, photorealistic',
  settings: {
    width: 1024,
    height: 1024,
    quality: 'high'
  }
});

if (result.object === 'image.result') {
  require('fs').writeFileSync('output.png', result.data[0].data);
}

Documentation

Comprehensive documentation is available in the genai-lite-docs folder.

Getting Started

API Reference

Utilities & Advanced

Provider Reference

Examples & Help

Supported Providers

LLM Providers

  • OpenAI - GPT-5 (5.2, 5.1, mini, nano), GPT-4.1, o4-mini
  • Anthropic - Claude 4.5 (Opus, Sonnet, Haiku), Claude 4, Claude 3.7, Claude 3.5
  • Google Gemini - Gemini 3 (Pro, Flash preview), Gemini 2.5, Gemini 2.0, Gemma 3 (free)
  • Mistral - Codestral, Devstral
  • llama.cpp - Run any GGUF model locally (no API keys required)

Image Providers

  • OpenAI Images - gpt-image-1, dall-e-3, dall-e-2
  • genai-electron - Local Stable Diffusion models

See Providers & Models for complete model listings and capabilities.

API Key Management

genai-lite uses a flexible API key provider pattern. Use the built-in fromEnvironment provider or create your own:

import { ApiKeyProvider, LLMService } from 'genai-lite';

const myKeyProvider: ApiKeyProvider = async (providerId: string) => {
  const key = await mySecureStorage.getKey(providerId);
  return key || null;
};

const llmService = new LLMService(myKeyProvider);

See Core Concepts for detailed examples including Electron integration.

Logging Configuration

Control logging verbosity via environment variable or service options:

# Environment variable (applies to all services)
export GENAI_LITE_LOG_LEVEL=debug  # Options: silent, error, warn, info, debug
// Per-service configuration
const llmService = new LLMService(fromEnvironment, {
  logLevel: 'debug',        // Override env var
  logger: customPinoLogger  // Inject pino/winston/etc.
});

See Logging for custom logger integration and testing patterns.

Example Applications

The library includes two complete demo applications showcasing all features:

  • chat-demo - Interactive chat application with all LLM providers, template rendering, and advanced features
  • image-gen-demo - Interactive image generation UI with OpenAI and local diffusion support

Both demos are production-ready React + Express applications that serve as reference implementations and testing environments. See Example: Chat Demo and Example: Image Demo for detailed documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development

npm install
npm run build
npm test

See Troubleshooting for information about E2E tests and development workflows.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Originally developed as part of the Athanor project, genai-lite has been extracted and made standalone to benefit the wider developer community.