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

@nest-langchain/openai-compatible

v0.2.0

Published

OpenAI-compatible provider tokens and model factory wiring for Nest LangChain.

Readme

@nest-langchain/openai-compatible

English | 한국어

OpenAI-compatible Chat Completions provider for NestJS dependency injection.

Use this package for providers that expose an OpenAI-compatible API, including MiniMax, Kimi/Moonshot, GLM/Z.AI, OpenRouter, Together, Fireworks, and internal gateway endpoints.

Install

pnpm add @nest-langchain/openai-compatible @langchain/openai

Register Models

import { Module } from '@nestjs/common';
import { OpenAICompatibleProviderModule } from '@nest-langchain/openai-compatible';

@Module({
  imports: [
    OpenAICompatibleProviderModule.forRoot({
      models: [
        {
          name: 'minimax',
          apiKey: process.env.MINIMAX_API_KEY,
          baseURL: 'https://api.minimax.io/v1',
          model: 'MiniMax-M3',
          temperature: 1,
          modelKwargs: {
            reasoning_split: true,
          },
        },
        {
          name: 'kimi',
          apiKey: process.env.MOONSHOT_API_KEY,
          baseURL: 'https://api.moonshot.ai/v1',
          model: 'kimi-k2.7',
        },
        {
          name: 'glm',
          apiKey: process.env.ZAI_API_KEY,
          baseURL: 'https://api.z.ai/api/paas/v4',
          model: 'glm-5.2',
        },
      ],
    }),
  ],
})
export class AiModule {}

Injection

import { Injectable } from '@nestjs/common';
import { ChatOpenAI } from '@langchain/openai';
import { InjectOpenAICompatibleModel } from '@nest-langchain/openai-compatible';

@Injectable()
export class ProductWorkflow {
  constructor(
    @InjectOpenAICompatibleModel('minimax')
    private readonly model: ChatOpenAI,
  ) {}

  async run(prompt: string) {
    return this.model.invoke(prompt);
  }
}

InjectOpenAICompatibleModel() is a constructor-parameter helper. For dynamic lookup, use getOpenAICompatibleModelToken(name).

Runtime Factory

Each named entry also exposes a factory. Inject it to create models with per-call model ids / overrides while inheriting the entry's connection info and defaults (temperature, modelKwargs, timeout, maxRetries):

import { Injectable } from '@nestjs/common';
import { ChatOpenAI } from '@langchain/openai';
import {
  InjectOpenAICompatibleModelFactory,
  OpenAICompatibleChatModelFactory,
} from '@nest-langchain/openai-compatible';

@Injectable()
export class ProductWorkflow {
  constructor(
    @InjectOpenAICompatibleModelFactory('minimax')
    private readonly factory: OpenAICompatibleChatModelFactory,
  ) {}

  run(model: string, prompt: string) {
    return this.factory.create({ model, temperature: 0.5 }).invoke(prompt);
  }
}

For dynamic lookup use getOpenAICompatibleModelFactoryToken(name). model is required on create().

Environment Fallbacks

For name: 'minimax', the module checks both long and short env names:

OPENAI_COMPATIBLE_MINIMAX_API_KEY
OPENAI_COMPATIBLE_MINIMAX_BASE_URL
OPENAI_COMPATIBLE_MINIMAX_MODEL

MINIMAX_API_KEY
MINIMAX_BASE_URL
MINIMAX_MODEL

The unnamed default model reads:

OPENAI_COMPATIBLE_API_KEY
OPENAI_COMPATIBLE_BASE_URL
OPENAI_COMPATIBLE_MODEL

When a provider uses non-matching env names, bind them explicitly:

OpenAICompatibleProviderModule.forRoot({
  name: 'kimi',
  apiKeyEnv: 'MOONSHOT_API_KEY',
  baseURLEnv: 'KIMI_BASE_URL',
  modelEnv: 'KIMI_MODEL',
});

Client Options

  • configuration is forwarded to the OpenAI client used by @langchain/openai.
  • baseURL and baseUrl both work; the resolved value is written into configuration.baseURL.
  • defaultHeaders, timeout, maxRetries, and modelKwargs are forwarded to ChatOpenAI.

Demo

OPENAI_COMPATIBLE_API_KEY=...
OPENAI_COMPATIBLE_BASE_URL=https://api.example.com/v1
OPENAI_COMPATIBLE_MODEL=example-chat
pnpm --filter @nest-langchain/demo-providers start

curl -X POST "http://localhost:3006/providers/openai-compatible/invoke" \
  -H "content-type: application/json" \
  -d '{"prompt":"Write one sentence about compatible model endpoints."}'