An HTTP request can test a local language model before an application depends on it. LM Studio's native REST API accepts a chat prompt and returns the model's generated reply as JSON.

The native API is available in LM Studio 0.4.0 and newer. Its chat endpoint uses a different JSON format from the OpenAI-compatible API, so a request written for one cannot be sent unchanged to the other.

The request runs on the same machine as LM Studio, with curl installed and a chat model already loaded. The local server uses its default authentication setting, which does not require an API token; an existing authenticated server needs its configured token instead.

Steps to send a chat request to the LM Studio REST API:

  1. Check that the local HTTP server is running on port 1234.
    $ lms server status
    The server is running on port 1234.

    The request below uses 127.0.0.1, which reaches only this machine. The headless setup starts the server bound to that loopback address. A stopped server or a different port needs the corresponding setup or request URL.
    Related: How to run LM Studio headlessly with llmster

  2. Identify your loaded chat model in lms ps.
    $ lms ps
    
    IDENTIFIER    MODEL                    STATUS    SIZE         CONTEXT    PARALLEL    LOAD CONFIG    DEVICE    TTL     
    local-chat    qwen2.5-0.5b-instruct    IDLE      397.81 MB    2048       4           LM Studio      Local     59m / 1h

    The IDENTIFIER column supplies the model value for the request. The loaded instance here is named local-chat. An empty list means no model is loaded.
    Related: How to download a model with lms in LM Studio
    Related: How to load a model with lms in LM Studio

  3. Send a prompt to /api/v1/chat using your loaded model's identifier in place of local-chat. Example output:
    $ curl --fail-with-body --silent --show-error \
      http://127.0.0.1:1234/api/v1/chat \
      -H 'Content-Type: application/json' \
      -d '{
        "model": "local-chat",
        "input": "What is 2 + 2? Answer briefly.",
        "max_output_tokens": 32
      }'
    {
      "model_instance_id": "local-chat",
      "output": [
        {
          "type": "message",
          "content": "2 + 2 equals 4."
        }
      ],
    ##### snipped #####

    -d sends a POST request, and the content-type header declares JSON. The input field contains your prompt; max_output_tokens caps the reply length. The response's model_instance_id identifies the model, and an output item with type set to message contains the generated text in content. The wording and timing statistics vary. Curl reports HTTP failures, including authentication or invalid-model errors, instead of silently treating them as a successful reply.
    Related: Native chat request and response reference

Share this guide