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-gateway

v0.0.5

Published

LLM Gateway with direct request to provider

Readme

LLM Gateway

Open-source library built for fast and reliable connections to different LLM providers.

LLM Gateway for Python: https://pypi.org/project/open-llm-gateway/ https://github.com/ottic-ai/llm-gateway-python

The LLM Gateway is a lightweight, open-source library built for fast and reliable connections to LLMs.

It simplifies integrations with multiple providers, offering fallbacks, caching, and minimal latency with a client-side solution.

  • Minimize Downtime: Automatic retries and fallbacks to secondary providers like Azure or Entropic.
  • Automatic input params conversion: Automatically convert input params between OpenAI, Anthropic and Azure formats for fallbacks.
  • Faster Responses: Direct client-side requests for low latency.
  • Unified Control: A single interface to manage requests across LLMs.
  • Unified Output: Consistent output format across LLMs.
    openAI/AnthropicOutput:{...}
    llmGatewayOutput: {
        type: 'text' | 'tool_calls';
        content?: string; - content for text output
        tool_name?: string; - name of the tool for tool_calls
        arguments?: string; - arguments for the tool.
    }[]
}
  • Easy Model Switching: Change between OpenAI, Anthropic, and Azure models with a simple configuration change.

Contribute, fork, or raise issues— so we can make it better together.

Starring this repo helps other developers discover the LLM Gateway! ⭐

Installation

To install the library, use npm or yarn:

npm install llm-gateway

or

yarn add llm-gateway

Usage

Check examples in examples folder.

Here's a basic example of how to use the LLM Gateway library:

import { LLMGateway, EnumLlmModelType } from 'llm-gateway';

const openAIGateway = new LLMGateway({
    provider: EnumLLMProvider.OPENAI, // or ANTHROPIC, AZUREOPENAI, OPENAI
    apiKey: process.env['OPENAI_API_KEY'],
});
const openAIresponse = await openAIGateway.chatCompletion({
    messages: [
        { role: 'user', content: 'Write a one sentence story about a cat.' }
    ],
    model: 'gpt-4o-mini',
    max_completion_tokens:200
})

console.log('Response:', openAIresponse);

LLM Fallbacks Configuration

The LLM Gateway library supports configuring fallbacks to ensure that if one model fails, another can be used as a backup. This is useful for maintaining service availability and reliability.

Example Configuration


import {LLMGateway, EnumLLMProvider} from 'llm-gateway';

const llmGateway = new LLMGateway({
    provider: EnumLLMProvider.OPENAI, // or ANTHROPIC, AZUREOPENAI
    apiKey: 'INCORRECT_API_KEY_TO_EMULATE_FAILURE',
}, {
    fallbacks: {
        fallbackModel: 'claude-3-5-sonnet-latest',
        fallbackProvider: {
            apiKey: process.env['ANTHROPIC_API_KEY'],
            provider: EnumLLMProvider.ANTHROPIC
        }
    }
});


const response = await llmGateway.chatCompletion({
    messages: [
        { role: 'user', content: 'Write a one sentence story about a cat.' }
    ],
    model: 'gpt-4o-mini',
})

console.log('Response:', JSON.stringify(response.llmGatewayOutput, null ,2));

All examples work consistently across different providers (OpenAI, Anthropic, Azure) and automatically handle format conversion when falling back to a different provider.

Streaming Responses

The LLM Gateway supports streaming responses from all providers, with a unified interface that works consistently across OpenAI, Anthropic, and Azure.

Basic Streaming Example

const openAIGateway = new LLMGateway({
    provider: EnumLLMProvider.OPENAI, // or ANTHROPIC, AZUREOPENAI
    apiKey: process.env['OPENAI_API_KEY'],
});

const openAIStream = await openAIGateway.chatCompletionStream({
    messages: [{ role: 'user', content: 'Write a one sentence story about a cat.' }],
    model: 'gpt-4o-mini',
    temperature: 0.7,
});

for await (const chunk of openAIStream) {
    if(chunk.choices[0].finish_reason === 'stop') {
        console.log('message_stop');
    } else {
        console.log(chunk.choices[0].delta.content);
    }
}

Configuration

  • apiKey: Your API key for the chosen LLM provider.
  • modelType: The type of LLM provider you want to use (OPENAI, ANTHROPIC, AZUREOPENAI).
  • endpoint: (Optional) The endpoint for OpenAI models.
  • deployment: (Optional) The deployment name for Azure models.
  • apiVersion: (Optional) The API version for Azure models.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License.