
LM Studio as a Local OpenAI-Compatible API: Server Setup, Model IDs and LAN Access
Also available in Hindi: यह लेख हिंदी में पढ़ें
LM Studio can act as a local replacement for the OpenAI API: start its server, and any app that uses an OpenAI client can talk to a model on your own computer by changing one base URL. This guide covers the exact commands, the model ID trap, memory settings and how to share the server on your network without leaving it open.
What the server gives you
LM Studio's docs list these OpenAI-compatible endpoints: /v1/models, /v1/chat/completions, /v1/responses, /v1/embeddings and the legacy /v1/completions. The docs' examples use port 1234.
Step 1: download a model and start the server
The lms command-line tool ships with LM Studio. Open the app once, then in a terminal:
lms get openai/gpt-oss-20b
lms server start
lms ls
You can also use the Start server switch in the Developer tab. Add --port 3000 to pick a port; without it, LM Studio uses the last port you used.
Step 2: find the model ID and change the base URL
Call http://localhost:1234/v1/models and copy the model's id. That exact string goes in the model field. In Python:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="not-needed")
OpenAI's own LM Studio guide uses this pattern, noting that LM Studio does not require an API key by default. Want a stable name? Load with lms load <model> --identifier="my-model".
Step 3: keep memory under control
- JIT loading is on by default, so the first request loads the model.
- Idle TTL: JIT-loaded models unload after 60 idle minutes by default. Send
"ttl": 300in a request for five minutes. - lms load models have no TTL unless you add
--ttl 3600. - Auto-Evict (on by default) keeps only one JIT-loaded model in memory, so switching models in your app frees the old one.
Step 4: share it on your network, safely
Run lms server start --bind 0.0.0.0 or turn on Serve on Local Network. LM Studio warns that any bind other than 127.0.0.1 exposes the server beyond your machine and recommends authentication. In LM Studio 0.4.0 or newer, open Server Settings, turn on Require Authentication, then create a token under Manage Tokens. It is shown only once. Clients send it as Authorization: Bearer <token>. Use --cors only if a browser app needs it; the docs flag it as a security risk.
For more local setups, see the best tools to run LLMs locally, moving Ollama models to another drive and Continue with local Ollama, or the LM Studio tool page.
Sources
- LM Studio as a Local LLM API Server, LM Studio Docs
- OpenAI Compatibility Endpoints, LM Studio Docs
- lms CLI and lms server start, LM Studio Docs
- Idle TTL and Auto-Evict, LM Studio Docs
- Serve on Local Network and Authentication, LM Studio Docs
- LM Studio 0.3.9 (Idle TTL) and LM Studio 0.4.0 (permission keys), LM Studio Blog
- How to run gpt-oss locally with LM Studio, OpenAI Cookbook
FAQ
Do I need an API key?
Not by default. If you turn on Require Authentication, send your LM Studio token as a Bearer token.
Which port does it use?
The docs' examples use 1234. Start with --port to choose another.
Why is the first request so slow?
JIT loading loads the model into memory on the first request. Later requests are faster.
Can Codex use LM Studio?
LM Studio says yes, because it implements the OpenAI-compatible /v1/responses endpoint.