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

@felipenmoura/laya-node-client

v1.0.1

Published

Client for laya-node

Readme

Laya Node Client

The official Node.js client for integrating the Laya Text Classification Model into your applications. This package provides a secure, server-side HTTP client that connects directly to a running laya-node inference server.

This should be used alongside with laya-node, a node service (wrapper) you can start in your own insfrastructure, container or local machine.

Features

  • Server-Side Security: Explicitly blocks client-side execution to prevent leaking your SECRET_API_KEY.
  • Router Compatibility: Exposes a Router class matching the Laya Python SDK, so your application logic reads exactly like the official documentation.
  • Dynamic State Support: Supports both simple string payloads and complex dictionary states for your predictions.
  • Native Fetch: Zero-dependency architecture relying on Node's native fetch API.

Installation

npm install @felipenmoura/laya-node-client
# or
pnpm add @felipenmoura/laya-node-client

Getting Started

First, ensure you have the laya-node server running locally or deployed.
For example, by using the node wrapper or starting the inference server in your own server.

Importing and Instantiating

You can import either Router or LayaClient (they are functionally identical, but Router is recommended to match Laya's standard API terminology). The client supports both CommonJS (require) and ES Modules (import).

// Using CommonJS
const { Router } = require('@felipenmoura/laya-node-client');

// Using ES Modules (Named Import)
import { Router } from "@felipenmoura/laya-node-client";

// Using ES Modules (Default Import)
import LayaClient from "@felipenmoura/laya-node-client";
// Initialize the router pointing to your running server
const router = new Router({
  url: 'http://localhost:4000', // URL of your laya-node server
  apiKey: 'your_secret_api_key' // Optional, if you configured one in your on premise server
});

Making Predictions

Laya's API takes a state (the text/data to analyze) and questions (a schema defining what you want to extract).

1. Simple String State

const analyzeIssue = async () => {
  const result = await router.predict(
    "The app crashes every time I try to open the settings menu. Please fix this!",
    {
      "issue_type": {
        "type": "choice",
        "instructions": "What kind of issue is the user reporting?",
        "criteria": {
          "bug": "crash, error, or broken feature",
          "feature_request": "asking for a new capability",
          "question": "how-to or general inquiry"
        }
      }
    }
  );

  console.log(result.answers.issue_type.choice); // "bug"
};

2. Dictionary State

If you want to feed multiple data points (like an email subject and body), pass an object as the state. The Router natively handles translating this structure!

const analyzeEmail = async () => {
  const result = await router.predict(
    {
      "subject": "Cobrança duplicada",
      "body": "Fui cobrado duas vezes este mês. Cancelem a minha assinatura e devolvam o dinheiro."
    },
    {
      "department": {
        "type": "choice",
        "instructions": "Which department should handle this request?",
        "criteria": {
          "billing": "invoices, payments, refunds",
          "technical": "bugs, outages, system errors"
        }
      },
      "churn_risk": {
        "type": "noul",
        "instructions": "Does the user threaten to cancel or leave?"
      }
    }
  );

  console.log(result.answers.department.choice); // "billing"
  
  // The Router will automatically detect the language (Portuguese) and use the multilingual model!
  console.log(result.routing.model); // "multilingual"
};

Running the Built-in Tests

To verify that the client connects to your laya-node server successfully, you can run the interactive test script included in the repository.

  1. Clone this repository and navigate to the laya-node-client directory.
  2. Run the test script using Node:
    node test.js
  3. The prompt will ask you for your server URL and API key. It will then perform English and Portuguese text classification tests against your server!

Security Notes

If the server requires the use of SECRET_API_KEY, then this client must pass it and it will ONLY work on server side, as you should NEVER leak your SECRET keys into the client side.

License

This project is licensed under the MIT License.