LM Studio OpenAI-Compatible API: Setup, Endpoints, Fixes
Does LM Studio have an OpenAI-compatible API?
Yes. LM Studio runs a local server that speaks the OpenAI API, so any OpenAI SDK or tool can use a model on your own machine by changing the base URL to http://localhost:1234/v1. The server exposes the endpoints most clients need: GET /v1/models, POST /v1/chat/completions, POST /v1/responses, POST /v1/embeddings and the legacy POST /v1/completions. It also has an Anthropic-compatible Messages endpoint and its own REST API for loading and unloading models.
This guide covers how to start the server, connect clients, pick the right model ID, add authentication, and fix the errors people hit most often. It is based on LM Studio's developer documentation, checked on 30 November 2026. Port 1234 is the default; if you changed it in Server Settings, use your port everywhere below.
Step 1: Start the LM Studio server
You can start the server from the app or from the command line.
In the app: open the Developer tab, load a model, and switch the server to Running. The status line shows the address, usually http://127.0.0.1:1234.
From the terminal with the lms CLI that ships with LM Studio:
lms server start # start the API server
lms ls # list downloaded models
lms load <model-key> # load a model into memory
lms ps # show loaded modelsFor servers and CI machines there is also a headless mode (the llmster service), so you do not need the desktop app running in a GUI session.
Check that the server answers before you touch any client:
curl http://localhost:1234/v1/modelsA JSON list of model IDs means the OpenAI-compatible layer is up.
Step 2: Point an OpenAI client at LM Studio
Only two things change compared with calling OpenAI: the base URL and the model name. The API key can be any non-empty string unless you turn on authentication (see Step 4), but the official SDKs refuse to start without one, so pass a placeholder.
Python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
resp = client.chat.completions.create(
model="qwen3-8b", # an ID returned by GET /v1/models
messages=[
{"role": "system", "content": "Answer in one sentence."},
{"role": "user", "content": "What is an OpenAI-compatible API?"},
],
temperature=0.7,
)
print(resp.choices[0].message.content)JavaScript / TypeScript
const client = new OpenAI({ baseURL: "http://localhost:1234/v1", apiKey: "lm-studio" });curl
curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"qwen3-8b","messages":[{"role":"user","content":"Say this is a test"}]}'Streaming ("stream": true), tool calling and JSON-schema structured output are supported on the chat endpoint, but whether they work well depends on the model you loaded. Small models often ignore tools or break JSON.
Step 3: Use the right model ID
The model field must match an identifier LM Studio reports in GET /v1/models, not the name you saw on Hugging Face and not an OpenAI name such as gpt-4o. Two settings change what happens when the ID is not already loaded:
- Just-in-time (JIT) loading on: LM Studio loads the requested model on the first request, which makes that first call slow.
- JIT loading off: requests for a model that is not loaded fail, so load it first with
lms load.
Idle TTL and auto-evict unload models that have not been used for a while. That saves memory but means the next request pays the load time again. For an always-on integration, keep the model pinned or raise the TTL.
Step 4: Turn on authentication and network access
By default the server accepts requests without a token and listens only on the local machine. Two settings change that:
|
Setting |
Default |
When to change it |
|---|---|---|
|
Require Authentication |
Off |
Turn on before exposing the server to other devices. Create tokens under Manage Tokens (LM Studio 0.4.0 or newer) and send them as |
|
Serve on Local Network |
Off |
Turn on so phones, other PCs or containers can reach it at |
|
Enable CORS |
Off |
Turn on only if a browser page calls the API directly. |
With authentication on, the OpenAI SDK's api_key must be a real LM Studio token. Do not forward port 1234 to the internet without a token and a reverse proxy; the server can run any loaded model for anyone who reaches it.
Step 5: Connect common tools
Most apps that accept a "custom OpenAI endpoint" work with the same three values: base URL http://localhost:1234/v1, a placeholder or real key, and the model ID.
- Agents and coding tools: LM Studio implements
POST /v1/responses, so tools that require the Responses API, such as Codex, can run against a local model. - Frameworks: LangChain's
ChatOpenAI(base_url=...), LlamaIndex'sOpenAILikeand the Vercel AI SDK's OpenAI-compatible provider all work. See our guides to the AI SDK with an OpenAI-compatible API and self-hosted OpenAI-compatible APIs. - Docker containers: inside a container
localhostis the container itself. Usehttp://host.docker.internal:1234/v1on macOS and Windows, or the host's LAN IP with Serve on Local Network enabled.
Troubleshooting LM Studio's OpenAI API
|
Symptom |
Likely cause |
Fix |
|---|---|---|
|
|
Server not running, wrong port, or calling from a container |
Start the server, confirm the port, use |
|
|
Base URL missing |
Set the base URL to |
|
Model not found |
|
Copy the exact ID; load the model or enable JIT |
|
|
Authentication enabled, placeholder key sent |
Create a token and pass it as the API key |
|
First request very slow |
JIT load or model evicted by idle TTL |
Pre-load the model, raise TTL |
|
Output cut off or context errors |
Context length set lower than the prompt |
Raise the context length when loading the model |
|
Tool calls ignored |
Model does not support tool use well |
Use a model trained for tool calling |
If a client works with OpenAI but not with LM Studio, check what "compatible" covers before debugging further; our article on OpenAI compatibility issues lists the fields local servers commonly ignore.
LM Studio vs a hosted OpenAI-compatible API
LM Studio is the quickest way to test prompts privately and offline, and it costs nothing per token. The trade-off is hardware: model size and speed are limited by your GPU or unified memory, and it is a single machine without high availability. A common pattern is to develop against LM Studio and switch the same code to a hosted endpoint for production by changing only the base URL and model ID.
FAQ
What is the LM Studio API base URL?
http://localhost:1234/v1 by default. From another device on your network it is http://<your-computer-IP>:1234/v1 once Serve on Local Network is enabled.
Does LM Studio need an API key?
Not by default. The OpenAI SDK still needs a non-empty string, so pass any placeholder. If you enable Require Authentication, create a token in LM Studio and use that as the key.
Which OpenAI endpoints does LM Studio support?
/v1/models, /v1/chat/completions, /v1/responses, /v1/embeddings and /v1/completions. Image generation and audio endpoints are not part of it.
Can I use embeddings from LM Studio?
Yes. Load an embedding model and call POST /v1/embeddings with its ID. Chat models cannot be used for embeddings.
Why does my request say the model is not found?
The model value must be an ID from GET /v1/models. If JIT loading is off, the model must also be loaded before you call it.
Summary
LM Studio turns a local model into an OpenAI-compatible API at http://localhost:1234/v1. Start the server, copy a model ID from /v1/models, pass a placeholder key, and your existing OpenAI code runs locally. Turn on authentication before sharing it on a network, watch JIT loading and idle eviction for latency, and move to a hosted endpoint by changing only the base URL when you need scale.