An application that already exchanges JSON over HTTP can request local model output through the same interface. LM Studio's OpenAI-compatible embeddings API converts text into a numeric vector and returns it in the response.

The client sends the text together with an identifier for the embedding model. That identifier belongs to the server's model inventory, so the HTTP request does not need a model-file path or knowledge of the inference runtime. A shell client can use this boundary without installing LM Studio's native SDK.

Saving the JSON response keeps the complete vector available for later storage or similarity calculations. The model name, vector length and a few coordinates provide a readable inspection of the result without reducing the precision of the stored values.

Steps to generate embeddings with the LM Studio API:

  1. Start the local LM Studio daemon.
    $ lms daemon up

    LM Studio and lms must already be installed and available on your command path. On a headless Linux machine, llmster provides the daemon.
    Related: How to run LM Studio headlessly with llmster

  2. Install libgomp1 on Ubuntu or Debian for the GGUF inference runtime.
    $ sudo apt install --assume-yes libgomp1

    This dependency step applies to Ubuntu and Debian. Only OS package installation needs sudo; the daemon, model and HTTP client run under your normal account.
    Related: How to select an LM Studio runtime from the CLI

  3. Download Nomic Embed Text v1.5 in Q4_K_M GGUF format.
    $ lms get \
      https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF@q4_k_m \
      --gguf --yes

    The publisher's full repository URL selects the embedding model, and @q4_k_m selects its quantization. The file occupies about 84 MB. LM Studio reuses it if already present, including a bundled copy. A chat model cannot replace this embedding model.
    Related: How to download a model with lms in LM Studio

  4. Find the downloaded embedding model's key in the local inventory. Example output:
    $ lms ls --embedding
     
    You have 1 models, taking up 84.11 MB of disk space.
     
    EMBEDDING                               PARAMS    ARCH          SIZE        DEVICE
    text-embedding-nomic-embed-text-v1.5              Nomic BERT    84.11 MB    Local
  5. Load the Nomic model with the API identifier local-embedding. Example output:
    $ lms load text-embedding-nomic-embed-text-v1.5 \
      --identifier local-embedding --gpu off
    ##### snipped #####
    Model loaded successfully in 215.00ms.
    (80.21 MiB)
    To use the model in the API/SDK, use the identifier "local-embedding".

    –gpu off selects CPU inference. The model key comes from lms ls –embedding, while local-embedding is the name used in the HTTP request. The identifier must be unused; a different identifier also needs to replace local-embedding in the requests. Loading time and memory use vary.
    Related: How to load a model with lms in LM Studio

  6. Start LM Studio's HTTP server on loopback port 1234. Example output:
    $ lms server start --bind 127.0.0.1 --port 1234
    Success! Server is now running on port 1234

    Loopback limits access to clients on this computer. An existing server on another port needs the corresponding port in the request URLs. If API-token authentication is already enabled, requests require an LM Studio token; disabling authentication is unnecessary.
    Related: LM Studio API authentication

  7. Check that the compatibility API lists local-embedding. Example output:
    $ curl --fail-with-body --silent --show-error \
      http://127.0.0.1:1234/v1/models
    {
      "data": [
        {
          "id": "local-embedding",
          "object": "model",
          "owned_by": "organization_owner"
        },
    ##### snipped #####

    The id must match the identifier assigned during loading. With just-in-time loading enabled, the list can also include downloaded models that are not loaded. A connection error means the HTTP server is unreachable at that address.

  8. Generate an embedding for the document text in the request body.
    $ curl --fail-with-body --silent --show-error \
      http://127.0.0.1:1234/v1/embeddings \
      -H 'Content-Type: application/json' \
      -d '{
        "model": "local-embedding",
        "input": "search_document: A bicycle has two wheels."
      }' \
      --output embedding.json

    The JSON body makes this a POST request. input contains the text to embed; model selects the loaded embedding model. The response is saved to embedding.json in the current directory, replacing that file if it exists. –fail-with-body reports HTTP errors while retaining the error response.
    Related: LM Studio embeddings endpoint
    Related: Nomic task prefixes

  9. Read the returned model name, vector length and first five coordinates from embedding.json. Example output:
    $ python3 -c 'import json
    with open("embedding.json") as response:
        result = json.load(response)
    vector = result["data"][0]["embedding"]
    print("Model:", result["model"])
    print("Dimensions:", len(vector))
    print("First 5 values:", [round(value, 6) for value in vector[:5]])'
    Model: local-embedding
    Dimensions: 768
    First 5 values: [0.010607, 0.094336, -0.157394, 0.040864, 0.084526]

    data[0].embedding contains the vector for this input. The Nomic model returns 768 coordinates without dimensionality reduction; other embedding models may use a different length. Only the displayed preview is rounded, and embedding.json retains every value. The coordinates can vary with quantization and runtime. An error object, missing vector or zero-length list does not establish that an embedding was generated.
    Related: How to generate embeddings with lmstudio-python

Share this guide