Skip to content
,

LM Studio API Guide (2026): OpenAI, Anthropic and REST Endpoints on localhost:1234

9–13 minutes
Amazed woman with curly hair in a gold satin shirt on a rooftop at dusk holding an LM STUDIO card, with the hook text Local AI API Free on Port 1234

LM Studio is not just a chat app. Flip one switch and it becomes a local AI server on http://localhost:1234 that speaks the OpenAI API, the Anthropic API and its own native REST API.

Any script, app or coding agent that works with ChatGPT or Claude can then run on a free model on your own PC.

This guide covers the whole LM Studio API in one place:

  • how to start the server from the app or the lms command line;
  • every endpoint;
  • copy-ready curl, Python and JavaScript examples;
  • how to connect tools like Claude Code, Codex and Aider;
  • API tokens;
  • how to reach the server from another device;
  • how to fix the common errors.

Facts are checked against LM Studio’s developer docs and API changelog in November 2026.

TL;DR

  • Start it: Developer tab > toggle Start server, or run lms server start. Default address: http://localhost:1234.
  • OpenAI-compatible: base URL http://localhost:1234/v1 with /v1/models, /v1/chat/completions, /v1/responses, /v1/embeddings and /v1/completions.
  • Anthropic-compatible: POST /v1/messages (LM Studio 0.4.1+), so Claude Code can use local models.
  • Native REST v1: /api/v1/chat plus model list, load, unload and download endpoints (0.4.0+).
  • Auth: off by default. Turn on Require Authentication in Server Settings, create a token, send Authorization: Bearer $LM_API_TOKEN.
  • Model name: use the model identifier LM Studio shows (or from GET /v1/models).

Which LM Studio API Should You Use?

LM Studio runs one server that offers several “flavours” of API at the same address. Pick by what your code already speaks:

API Path Use it when
OpenAI-compatible /v1/... Your app, library or tool already uses the OpenAI SDK (most do)
Anthropic-compatible /v1/messages Claude Code or code written for the Anthropic SDK
Native REST v1 /api/v1/... You want LM Studio features: stateful chats, MCP tools, loading and downloading models by API
SDKs lmstudio-python, lmstudio-js You are building an app tightly tied to LM Studio

There is also an older REST API at /api/v0/.... LM Studio recommends the v1 API for new projects.

If you have not installed LM Studio or downloaded a model yet, follow our LM Studio beginner guide first, then come back here.

How to Start the LM Studio Server

From the app

  1. Download a model in the Discover tab if you have none. A 4-bit (Q4_K_M) build of a 7B to 14B model is a good first choice on an 8 to 16 GB GPU.
  2. Open the Developer tab (the terminal-style icon on the left).
  3. Toggle Start server. The status changes to Running and shows the address, normally http://localhost:1234.
  4. Load a model at the top of the Developer page, or let just-in-time loading load it on the first request.
  5. Copy the model identifier shown next to the loaded model. You will pass it as model in every request.

From the command line

The lms CLI ships with LM Studio. Open a terminal and run:

lms server start
# or choose the port explicitly
lms server start --port 1234

lms server status
lms server stop

This is handy for scripts and for running LM Studio on a machine you reach over SSH.

All Endpoints at a Glance

Method Path What it does
OpenAI-compatible (base URL http://localhost:1234/v1)
GET /v1/models List models
POST /v1/chat/completions Chat (messages array), streaming and tools supported
POST /v1/responses OpenAI Responses API, stateful via previous_response_id (0.3.29+)
POST /v1/embeddings Text embeddings with an embedding model
POST /v1/completions Plain text completion from a prompt
Anthropic-compatible
POST /v1/messages Anthropic Messages API (0.4.1+)
Native REST v1 (0.4.0+)
POST /api/v1/chat Stateful chat, MCP integrations, load and progress events
GET /api/v1/models List your models
POST /api/v1/models/load Load a model
POST /api/v1/models/unload Unload a model
POST /api/v1/models/download Download a model (returns a job_id)
GET /api/v1/models/download/status/{job_id} Download progress

First Request With curl

With the server running and a model available, test the OpenAI-style chat endpoint. Replace the model name with your own identifier:

curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3-8b",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain VRAM in one sentence."}
    ],
    "temperature": 0.7
  }'

List the models the server can see:

curl http://localhost:1234/v1/models

On Windows PowerShell, curl may be an alias for another command. Use curl.exe, or run the Python example below instead.

Python and JavaScript (OpenAI SDK)

Python

  1. Install the SDK: pip install openai
  2. Point it at LM Studio with base_url. The SDK insists on an API key, so pass any placeholder text when auth is off, or your LM Studio token when it is on.
from openai import OpenAI

client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")

resp = client.chat.completions.create(
    model="qwen3-8b",
    messages=[{"role": "user", "content": "Give me 3 tips for faster local AI."}],
)
print(resp.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="qwen3-8b",
    messages=[{"role": "user", "content": "Write a haiku about GPUs."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Embeddings

Download an embedding model first (for example a Nomic embed model), then:

emb = client.embeddings.create(
    model="text-embedding-nomic-embed-text-v1.5",
    input="Local AI keeps your data on your PC.",
)
print(len(emb.data[0].embedding))

JavaScript / TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://localhost:1234/v1",
  apiKey: "lm-studio",
});

const r = await client.chat.completions.create({
  model: "qwen3-8b",
  messages: [{ role: "user", content: "Hello from Node!" }],
});
console.log(r.choices[0].message.content);

The official OpenAI JS SDK uses baseURL (capital URL). Calling from a web page in the browser? Turn on CORS in Server Settings, or the browser will block the request.

Native REST API: Chat, Load and Download

The native v1 API exposes features the OpenAI format does not have. The model loads automatically if it is not loaded yet.

curl http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ibm/granite-4-micro",
    "input": "Write a short haiku about sunrise."
  }'

It is stateful: LM Studio can keep the conversation for you, so you do not resend the whole history each turn (see LM Studio’s Stateful Chats docs for the continuation field).

Give the model MCP tools

You can attach a remote MCP server for a single request:

curl http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ibm/granite-4-micro",
    "input": "What is the top trending model on Hugging Face?",
    "integrations": [{
      "type": "ephemeral_mcp",
      "server_label": "huggingface",
      "server_url": "https://huggingface.co/mcp",
      "allowed_tools": ["model_search"]
    }],
    "context_length": 8000
  }'

MCP servers you configured in LM Studio’s mcp.json can be used with "type": "plugin" and an id such as mcp/playwright. That option requires an API token.

Download a model by API

curl http://localhost:1234/api/v1/models/download \
  -H "Content-Type: application/json" \
  -d '{"model": "ibm/granite-4-micro"}'

# check progress with the job_id from the reply
curl http://localhost:1234/api/v1/models/download/status/JOB_ID

The model field accepts an LM Studio catalogue name or a Hugging Face model URL.

Connect Claude Code, Codex and Other Apps

Claude Code

Because LM Studio 0.4.1+ speaks the Anthropic Messages API, Claude Code can talk to it directly:

lms server start --port 1234
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
claude --model openai/gpt-oss-20b

If Require Authentication is on, set ANTHROPIC_AUTH_TOKEN to your LM Studio token. LM Studio recommends a model and settings with more than about 25k context, because coding agents use a lot of context. Our gpt-oss local guide helps you pick a size.

Codex and Responses-based tools

OpenAI’s Codex works with LM Studio because LM Studio implements POST /v1/responses. Point the tool’s OpenAI base URL to http://localhost:1234/v1.

Any OpenAI-compatible app

Most apps have a “custom OpenAI endpoint” or “OpenAI-compatible” option. Use these values:

Setting Value
Base URL http://localhost:1234/v1
API key Any text (auth off) or your LM Studio token
Model The identifier from /v1/models

That covers editors and agents such as Aider (use the openai/ prefix with OPENAI_API_BASE), chat front-ends, n8n and document tools like AnythingLLM.

API Tokens and Security

By default the API needs no authentication. That is fine when the server only listens on your own PC. Turn auth on before you expose it to a network.

  1. Open the Developer page and go to Server Settings.
  2. Turn on Require Authentication.
  3. Click Manage Tokens > Create Token, give it a name and choose its permissions.
  4. Copy the token straight away. LM Studio will not show it again.
  5. Send it with every request: Authorization: Bearer $LM_API_TOKEN. LM Studio also accepts an x-api-key header, which Anthropic-style clients use.
export LM_API_TOKEN=your-token-here
curl -H "Authorization: Bearer $LM_API_TOKEN" http://localhost:1234/api/v1/models

Once auth is on, REST, Python SDK and TypeScript SDK requests all need a valid token. You can edit a token’s name and permissions or delete it from the same API Tokens window.

Use LM Studio From Another Device

Want your laptop or phone to use the big GPU in your desktop?

  1. In Server Settings, turn on Serve on Local Network.
  2. Turn on Require Authentication and create a token (strongly recommended).
  3. Find the desktop’s local IP address (for example with ipconfig on Windows).
  4. Allow LM Studio through the firewall when Windows asks, for private networks only.
  5. On the other device use http://192.168.x.x:1234/v1 as the base URL.

Do not forward port 1234 on your router to the internet. If you need remote access, use a VPN such as Tailscale or WireGuard instead.

Useful lms Commands

Command What it does
lms server start / stop / status Control the API server
lms ls List downloaded models
lms ps Show loaded models (add --json for scripts)
lms load <model> Load a model into memory
lms unload --all Free VRAM by unloading every model
lms get <model> Download a model
lms log stream Watch server and model logs live (great for debugging requests)

Prefer a pure llama.cpp server with no GUI? Compare with our llama-server guide. Coming from Ollama, where a too-small context is the usual trap? Our Ollama context length guide explains the same issue.

Troubleshooting

Problem Cause Fix
Connection refused Server not running or wrong port Start it in the Developer tab or with lms server start; check lms server status
Port 1234 already in use Another app or a second LM Studio instance Close it, or start on another port with --port and update your base URL
401 Unauthorized Require Authentication is on Send Authorization: Bearer TOKEN, or set the SDK api_key to your token
Model not found Wrong model string Copy the exact identifier from GET /v1/models
First request very slow Model loading on demand Preload it with lms load or in the Developer tab
Answers cut off or agent forgets files Context length too small Load the model with a larger context (25k+ for coding agents) if your VRAM allows
Out of memory when loading Model or context too big for VRAM Use a smaller quant, lower context, or unload other models
Browser app blocked CORS off Enable CORS in Server Settings
Other device cannot connect Server only on localhost, or firewall Enable Serve on Local Network and allow it in the firewall
Tool calls ignored Model lacks tool-calling support Use a model marked for tool use in LM Studio

FAQ

What port does the LM Studio API use?

Port 1234 by default: http://localhost:1234. You can change it in the app or with lms server start --port.

Is the LM Studio API free?

Yes. The server is part of the free LM Studio app, and there are no per-token costs because everything runs on your hardware.

Does LM Studio need an API key?

Not by default. You can require one with the Require Authentication switch. SDKs that insist on a key can use any placeholder when auth is off.

Is LM Studio compatible with the OpenAI API?

Yes. It supports /v1/models, /v1/chat/completions, /v1/responses, /v1/embeddings and /v1/completions, so most OpenAI SDK code only needs a new base URL.

Can I use Claude Code with LM Studio?

Yes, from LM Studio 0.4.1, using the Anthropic-compatible /v1/messages endpoint and the ANTHROPIC_BASE_URL setting shown above.

Can several apps use the server at once?

Yes. Many clients can call the same server. The 0.4 series added parallel requests with continuous batching, though speed is shared between requests.

LM Studio API or Ollama API: which is better?

Both work well. LM Studio offers OpenAI, Anthropic and native APIs plus a GUI for tuning models. Ollama is lighter and very popular for headless servers. Many people use LM Studio on a desktop and Ollama on servers.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Amazed woman with curly hair in a gold satin shirt on a rooftop at dusk holding an LM STUDIO card, with the hook text Local AI API Free on Port 1234