MacBook Pro screen showing code, the kind of app you can point at a local LM Studio API server instead of a cloud API
Photo by Emile Perron on Unsplash · source · credits

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

Four steps to run LM Studio as a local OpenAI-compatible API
From LM Studio docs. Illustration, not a screenshot.

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

LM Studio server endpoints, memory settings and network safety
From LM Studio docs. Illustration, not a screenshot.

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

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.

About the author

Suraj Kumar builds and edits AIUseFlow, a directory of AI tools for vibe coders, agent builders and creators. Guides like this one walk through a practical workflow with cited sources — not a news wire rewrite. How we rank tools.

Get the weekly stack

Rank movers and new AI tools for builders, once a week. Free, no spam, unsubscribe anytime.