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

llm-chain

v0.1.6

Published

A unified TypeScript client for interacting with various LLM providers

Readme

llm-chain

A TypeScript library for easily interacting with various Large Language Model providers through a unified interface. Equipped with performance metrics for response time and streaming, useful for benchmarking and testing.

Installation

npm install llm-chain

Features

  • Unified interface for multiple LLM providers:

    • OpenAI
    • Groq
    • Gemini (Google)
    • Anthropic
    • Together AI
    • DeepSeek
    • XAI
  • Type-safe API with TypeScript

  • Support for streaming responses

  • Built-in validation using Zod

  • Easy to extend for new providers

  • Automatic model validation and token limits

  • Provider-specific optimizations

  • Support for multiple deployment options (Direct API, AWS Bedrock, Google Vertex)

Usage

OpenAI

import { LLMClient } from "llm-chain";

// Create a client with OpenAI
const client = LLMClient.createOpenAI("your-openai-api-key");

// Simple completion
const response = await client.complete("What is the capital of France?");
console.log(response);

// Chat completion with more options
const chatResponse = await client.chatCompletion({
  model: "gpt-4o-mini",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "What is the capital of France?" },
  ],
  temperature: 0.7,
});

console.log(chatResponse.message.content);

Groq

import { LLMClient } from "llm-chain";

// Create a client with Groq
const client = LLMClient.createGroq("your-groq-api-key");

// Chat completion with Mixtral
const chatResponse = await client.chatCompletion({
  model: "mixtral-8x7b-32768",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "What is the capital of France?" },
  ],
  temperature: 0.7,
});

console.log(chatResponse.message.content);

Gemini

import { LLMClient } from "llm-chain";

// Create a client with Gemini
const client = LLMClient.createGemini("your-gemini-api-key");

// Chat completion with Gemini Pro
const chatResponse = await client.chatCompletion({
  model: "gemini-2.0-flash",
  messages: [{ role: "user", content: "What is the capital of France?" }],
  temperature: 0.7,
});

console.log(chatResponse.message.content);

Anthropic

import { LLMClient } from "llm-chain";

// Create a client with Anthropic
const client = LLMClient.createAnthropic("your-anthropic-api-key");

// Chat completion with Claude
const chatResponse = await client.chatCompletion({
  model: "claude-3.5-sonnet-latest",
  messages: [{ role: "user", content: "What is the capital of France?" }],
  temperature: 0.7,
});

console.log(chatResponse.message.content);

Streaming Responses

await client.streamChatCompletion(
  {
    model: "mixtral-8x7b-32768", // or any other supported model
    messages: [{ role: "user", content: "Write a story about a cat." }],
  },
  chunk => {
    process.stdout.write(chunk);
  }
);

Supported Models

OpenAI Models

  • Default model: gpt-4o-mini
  • Supports all OpenAI chat models

Groq Models

Production Models

  • mixtral-8x7b-32768 (Mistral, 32k context)
  • llama-3.3-70b-versatile (Meta, 128k context)
  • llama-3.1-8b-instant (Meta, 128k context)
  • Various Whisper models for audio processing

Preview Models

  • llama3-groq-70b-8192-tool-use-preview (Groq)
  • llama3-groq-8b-8192-tool-use-preview (Groq)
  • Various LLaMA-3 preview models

Gemini Models

Gemini 2.0

  • gemini-2.0-flash-exp (Experimental, 1M input tokens)

Gemini 1.5

  • gemini-1.5-flash (32k context, versatile)
  • gemini-1.5-flash-8b (32k context, high volume)
  • gemini-1.5-pro (32k context, complex reasoning)

Anthropic Models

  • claude-3-5-sonnet-20241022 (Latest Sonnet)
  • claude-3-5-haiku-20241022 (Latest Haiku)
  • claude-3-opus-20240229 (Most powerful)
  • claude-3-sonnet-20240229 (Balanced)
  • claude-3-haiku-20240307 (Fast)
  • claude-2.1 (Legacy)

DeepSeek

  • deepseek-chat (Latest)

XAI

  • grok-2-latest (Latest)

Advanced Features

Custom Provider

import { LLMProvider, LLMClient } from "llm-chain";

class CustomProvider implements LLMProvider {
  // Implement the LLMProvider interface
  // ...
}

const client = new LLMClient(new CustomProvider(), "your-model-name");

Anthropic Deployment Options

// Direct API
const client = LLMClient.createAnthropic("your-api-key");

// AWS Bedrock
const client = LLMClient.createAnthropic("your-api-key", "bedrock", {
  aws_access_key: "your-access-key",
  aws_secret_key: "your-secret-key",
  aws_region: "us-east-1",
});

// Google Vertex
const client = LLMClient.createAnthropic("your-api-key", "vertex", {
  project_id: "your-project-id",
  region: "us-central1",
});

Error Handling

The library provides built-in error handling and validation:

  • Model availability checks
  • Token limit validation
  • Context window size validation
  • Streaming capability checks
  • Provider-specific error handling
  • Performance metrics for response time and streaming

License

MIT