New Tool Radar

Local AI

How to Chat with a Local Model Through LM Studio’s Native REST API

Send a curl request to LM Studio's own REST API at /api/v0/chat/completions and read the reply — plus the tokens-per-second stats the OpenAI-style endpoints do not return.

Schematic diagram with three steps: start the server with lms server start, list models at GET /api/v0/models, then chat at POST /api/v0/chat/completions and read the reply plus stats.

LM Studio’s server speaks the OpenAI API, but it also has its own native REST API — still labelled beta and experimental — with one thing the OpenAI-style endpoints do not give you: per-reply stats such as tokens per second and time to first token, plus rich model info like loaded state, quantization, and max context length. If you want to measure a local model while you chat with it, this is the endpoint to use.

Start the server and list models

Start the server from a terminal — the REST API docs give this command:

lms server start

Then list the models with the native endpoint. It returns loaded and downloaded models, each with its state, quantization, and max context length:

curl http://localhost:1234/api/v0/models

The docs’ own example response lists three models, including meta-llama-3.1-8b-instruct at quantization Q4_K_M with a max context length of 131072, and qwen2-vl-7b-instruct at 4-bit with 32768.

Send a chat request

Post a messages array to /api/v0/chat/completions. This is the docs’ own example, with the model granite-3.0-2b-instruct, a system message asking for rhymes, and the user message “Introduce yourself.”:

curl http://localhost:1234/api/v0/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "granite-3.0-2b-instruct",
    "messages": [
      { "role": "system", "content": "Always answer in rhymes." },
      { "role": "user", "content": "Introduce yourself." }
    ],
    "temperature": 0.7,
    "max_tokens": -1,
    "stream": false
  }'

The reply carries the assistant’s message — in the docs’ example, a rhyming introduction — and a stats block with tokens_per_second, time_to_first_token, and generation_time, plus a model_info block with the architecture, quantization, format, and context length.

Check What you should see If you do not see it
Server lms server start reports the server running on port 1234 The server was already running, or lms is not on your PATH
Listed GET /api/v0/models returns your models with state and quantization The model is not downloaded — get it first
Reply POST /api/v0/chat/completions returns an assistant message Check the model name matches one from the list
Stats The reply has a stats block with tokens_per_second The stats block is a native-API extra — the OpenAI-style endpoints do not return it

Expected result. We checked LM Studio’s own docs for the native REST API endpoints, the example request, and the stats in the example reply. We did not run LM Studio or send a request.

Limits

The REST API is labelled “Experimental” in LM Studio’s own docs, requires LM Studio 0.3.6 or newer, and the docs warn it is “still WIP, endpoints may change” — a newer v1 API exists, and this guide covers the documented v0 endpoints only. The rhyming reply and its numbers are the docs’ own example response, not a reply received for this guide. The server needs no login by default, so keep it on localhost unless you have turned on authentication. We did not run LM Studio, so no reply here is a recorded result.

Sources

See all