SuperAPI AI Directory

lm-studio

General & other

View repository

Updated 10-16 06:14

About this skill

LM Studio CLI & API

Complete workflow to use local models with LM Studio: setup → use → cleanup.

Phase 0 — Verify LM Studio

which lms

If it doesn't exist: LM Studio includes lms since v0.2.22+. Download from https://lmstudio.ai and start the app at least once so the CLI is registered in PATH.

lms status

Check if the app or the daemon are running. If nothing is running, start LM Studio or use lms daemon up for headless mode.

Phase 1 — Setup: Server + Model

1a — Start server

lms server start --port 1234
lms server status

Add --cors only if access from browser or extensions (VS Code, etc) is needed — it implies a security risk.

1b — Download model (if you don't have one)

lms get                          # muestra modelos recomendados
lms get llama-3.1-8b             # descarga quant recomendada
lms get llama-3.1-8b@q4_k_m     # quantización específica
lms get --mlx                    # solo modelos MLX (Apple Silicon)
lms get --gguf                   # solo modelos GGUF

Check downloaded models:

lms ls              # lista legible
lms ls --json       # para parsear programáticamente
lms ls --llm        # solo LLMs (excluye embeddings)

1c — Load model into memory

Before loading, estimate memory usage:

lms load --estimate-only <model>

Load with GPU configuration:

lms load <model> --gpu <valor> --context-length 4096

GPU configuration:

Available VRAM --gpu Notes
≥16 GB max Full GPU offload, maximum speed
8–16 GB auto LM Studio decides the optimal split
4–8 GB 0.5–0.8 Partial offload, adjust per model
<4 GB / no GPU off CPU only, slower but works

Additional useful flags:

  • --identifier "mi-modelo" — custom name to reference it in the API
  • --ttl 3600 — auto-unload the model after 1h of inactivity
  • --host 192.168.1.5 — load on a remote instance

Check loaded model:

lms ps

Phase 2 — Usage: Text and Files

Quick chat via CLI

lms chat <model> -p "tu prompt acá"
lms chat <model> -p "Resumí esto: $(cat archivo.txt)"
lms chat <model> -s "Sos un experto en seguridad" -p "analizá este log"
lms chat <model> --stats    # muestra tokens/segundo al final

Ctrl+C stops generation at any time.

Via API — The 3 endpoints

Once the server is running, there are 3 ways to access it:

Native API (/api/v1/chat) — stateful chats, MCP, reasoning, streaming events:

curl http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-id",
    "input": "Analizá este texto: ...",
    "stream": false
  }'

OpenAI-compatible (/v1/chat/completions) — tools, structured output, drop-in replacement:

curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-id",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Anthropic-compatible (/v1/messages) — requires LM Studio 0.4.1+:

curl http://localhost:1234/v1/messages \
  -H "x-api-key: lm-studio" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-id",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 1024
  }'

Send large file via API

CONTENT=$(cat archivo.txt)
curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg c "$CONTENT" \
    '{"model":"model-id","messages":[{"role":"user","content":("Analizá esto:\n"+$c)}]}')"

From SDKs (Python/TypeScript)

Point any OpenAI or Anthropic SDK to localhost. The value of api_key doesn't matter if auth is disabled (default):

# OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")

# Anthropic SDK (requiere 0.4.1+)
from anthropic import Anthropic
client = Anthropic(base_url="http://localhost:1234", api_key="lm-studio")
// OpenAI SDK (TypeScript)
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "http://localhost:1234/v1", apiKey: "lm-studio" });

Endpoint comparison

Feature Native /api/v1/chat OpenAI /v1/chat/completions Anthropic /v1/messages
Streaming ✅ ✅ ✅
Stateful chats ✅ ❌ ❌
MCP integration ✅ ❌ ❌
Custom tools ❌ ✅ ✅
Reasoning modes ✅ ✅ ❌
Context length override ✅ ❌ ❌

For more details about the native API (stateful chats, MCP, complete schemas): see references/lms-commands.md.

Phase 3 — Cleanup

When you're done using LM Studio:

lms unload --all        # liberar memoria de todos los modelos
lms server stop         # parar servidor HTTP
lms daemon down         # cerrar daemon (si se usó modo headless)

Check that everything is clean:

lms ps                  # debería estar vacío
lms server status       # debería decir "not running"

If you prefer, simply closing the LM Studio app does all of this automatically.

Gotchas

  • LM Studio must be opened at least once before lms works — the first run registers the CLI in PATH
  • --cors is required for access from browser/VS Code but is a security risk — only enable it when needed
  • --ttl in lms load has no default → the model stays loaded indefinitely. In lms chat the default is 3600s (1h)
  • Anthropic-compat endpoint requires v0.4.1+ (not 0.4.0)
  • lms import by default moves the original file, it does not copy. Use --copy or --symbolic-link to preserve
  • Auth is opt-in: if enabled in Server Settings, tokens are generated only once — save them immediately
  • flash_attention and eval_batch_size only apply to the llama.cpp engine, not to MLX
  • If a model fails to load without a clear error → check for a compatible engine with lms runtime ls

Troubleshooting

Problem Solution
lms not found Open LM Studio at least once
Model does not load / OOM lms load --estimate-only <model>, reduce --gpu
Port in use lms server start --port <otro>
Server does not respond lms server status + lms log stream
Incompatible runtime lms runtime ls, try another engine
Auth rejected Check token in Server Settings → Manage Tokens