Skip to main content

lmstudio.js is Apache 2.0 licensed and available on npm/yarn.
It is developed in lmstudio-ai/lmstudio.js on GitHub.

Quick Start Guide

Here you'll find the minimal steps to create an LM Studio SDK TypeScript/JavaScript project.

Download LM Studio

If you haven't already, download and install the latest version of LM Studio from the LM Studio website.

Set up LM Studio CLI (lms)

lms is the CLI tool for LM Studio. It is shipped with the latest versions of LM Studio. To set it up, run the following command:

  • Windows:

    cmd /c %USERPROFILE%/.cache/lm-studio/bin/lms.exe bootstrap
  • Linux/macOS:

    ~/.cache/lm-studio/bin/lms bootstrap

Open up a new terminal and run the following command to verify that the CLI is installed:

lms

Create Your First Project

If you already have a project, please continue here.

Typescript (Recommended)

To create a basic TypeScript project with Node.js, follow these steps:

  1. Install Node.js:
    Make sure Node.js is installed on your system. You can download Node.js from the official website nodejs.org.

  2. Create a folder to house the project
    Create a new directory where you want to create your project:

    mkdir my-projects
    cd my-projects
  3. Create an empty project with lms create:
    Run the following command to start LM Studio interactive project creator:

    lms create node-typescript-empty
  4. Enter the project:
    The above command will create a new directory with the project name you provided. Enter the project directory with the following command:

    cd <project-name>

    You can find the source code in the src directory.

JavaScript

To create a basic JavaScript project with Node.js, follow these steps:

  1. Install Node.js:
    Make sure Node.js is installed on your system. You can download Node.js from the official website nodejs.org.

  2. Create a folder to house the project
    Create a new directory where you want to create your project:

    mkdir my-projects
    cd my-projects
  3. Create an empty project with lms create:
    Run the following command to start LM Studio interactive project creator:

    lms create node-javascript-empty
  4. Enter the project:
    The above command will create a new directory with the project name you provided. Enter the project directory with the following command:

    cd <project-name>

    You can find the source code in the src directory.

Use an LLM in your Node.js Program

First, download an LLM you can run on your computer

From LM Studio, search and download any LLM you would like. In this example, we'll use lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF (about 4GB on disk).

Once the file is done downloading, read on!

Start the Local Server

To use the LLM in your Node.js program, you need to start the LM Studio local server. Run the following command in the terminal:

lms server start

Code!

Add the following code to your project's entrypoint file (src/index.ts or src/index.js):

// index.js
const { LMStudioClient } = require("@lmstudio/sdk");

async function main() {
// Create a client to connect to LM Studio, then load a model
const client = new LMStudioClient();
const model = await client.llm.load("lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF");

// Predict!
const prediction = model.respond([
{ role: "system", content: "You are a helpful AI assistant." },
{ role: "user", content: "What is the meaning of life?" },
]);
for await (const text of prediction) {
process.stdout.write(text);
}
}

main();

Execute your code:

npm start

🎉 That's it! You have successfully loaded a model and made a prediction from your own JavaScript/TypeScript program.