The most useful thing about LM Studio’s local server is that it speaks OpenAI’s API. Any code, tool or library written for OpenAI works against it once you change the base URL and the model name — no LM Studio SDK needed. The LM Studio docs list serving local models on OpenAI-like endpoints as a core capability, and the local server runs on port 1234 by default.
Related guide: How to Call the LM Studio Local Server with the Python SDK
Start the server, then call it like OpenAI
Load a model in LM Studio, open the Local Server tab, and click Start Server. Then call the chat completions endpoint:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
response = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.choices[0].message.content)
Two details from the guides matter: the base URL is http://localhost:1234/v1, and the model name in the request must match the model identifier shown in LM Studio’s server tab — it is the Hugging Face repo path, not a short name like Ollama uses. The API key can be any string; LM Studio does not check it unless you configured one.
If the request fails
Check the server first with lms server status and lms ps: a running server with no loaded model cannot answer. A 404 usually means the model name does not match the identifier; copy it from the server tab. A connection error means the server is not running, or is bound to a different port — check the port in the Local Server tab.
Expected result. We checked the LM Studio docs for the OpenAI-compatible endpoints and the linked guides for the base URL, the model identifier rule, and the example client code. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.
Limits
The OpenAI compatibility covers the common endpoints, not every OpenAI feature — check the LM Studio docs for the endpoint you need before building on it. The server is local by default; if you bind it to your network, set the server’s access controls first. We did not run LM Studio or send a request, so the example is from the sources, not a recorded run.
Sources
- LM Studio docs — serve local models on OpenAI-like endpoints, locally and on the network; OpenAI Compatibility API and LM Studio REST API
- LM Studio guide — the local server exposes an OpenAI-compatible API at http://localhost:1234/v1; the model name in the request must match the model identifier shown in LM Studio’s server tab
- Reading image-only PDFs with a local vision model — LM Studio exposes an OpenAI-compatible server on http://localhost:1234; a vision request is a user message with text and image_url parts
Checked 2026-11-28.
