Applications that speak the OpenAI API can also use models running on the same computer. LM Studio's OpenAI-compatible API accepts chat requests and returns the local model's reply as JSON.
The compatibility interface uses OpenAI-style message objects and a /v1 base path. LM Studio's native REST API uses /api/v1 with a different chat payload, so changing the address alone does not convert a native request into a compatible one.
The request runs from a POSIX shell with curl on the same machine as LM Studio or llmster. A downloaded chat model must be loaded before the request; an OpenAI account or hosted model name is unnecessary.
Steps to call the OpenAI-compatible API in LM Studio:
- 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
The daemon must already be running. The loopback address limits access to clients on this machine. These requests assume the default local server without API-token authentication; an existing authenticated server requires its LM Studio token, not an OpenAI key. Do not disable authentication on an existing server.
Related: How to run LM Studio headlessly with llmster - Request the model identifiers available through the compatibility API. Example output:
$ curl --fail-with-body --silent --show-error \ http://127.0.0.1:1234/v1/models { "data": [ { "id": "local-chat", "object": "model", "owned_by": "organization_owner" }, ##### snipped #####
The chat request needs a chat model's exact id. Here, local-chat is the identifier assigned when loading the model. With just-in-time loading enabled, the list can include downloaded models that are not currently loaded. An embedding model cannot answer a chat request.
Related: How to load a model with lms in LM Studio - Set the client base URL to LM Studio's local compatibility address.
$ BASE_URL=http://127.0.0.1:1234/v1
The base URL includes /v1 once. The request appends /chat/completions to it. An existing OpenAI-compatible client uses this address as its base_url instead of the hosted service's address. A different server port requires the corresponding port in this URL.
- Send a chat request using your chat model's id in place of local-chat. Example output:
$ curl --fail-with-body --silent --show-error \ "$BASE_URL/chat/completions" \ -H 'Content-Type: application/json' \ -d '{ "model": "local-chat", "messages": [{"role": "user", "content": "What is 2 + 2? Answer briefly."}], "max_tokens": 32 }' ##### snipped ##### "model": "local-chat", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "2 + 2 equals 4.", ##### snipped #####
The JSON body makes this a POST request. The generated wording varies; max_tokens limits the reply length. Curl reports HTTP errors and retains their response bodies.
Related: LM Studio Chat Completions reference - Confirm that the response names your model and contains an assistant reply in choices[0].message.content.
The model value should match the identifier used in the request, and the reply should answer the prompt. A connection error means the local server is unreachable, while a JSON error or an empty choices array does not establish that the model generated a reply.