Wiring a coding-assistant extension to LM Studio's local server, what base URL, API key and model identifier does it need?
answer
- one port, several route families
- the /v1 suffix matters
- key unchecked until auth is on
- the id the models route lists
- first call loads the model
basics
~10 sAn OpenAI-style client uses http://localhost:1234/v1 and an Anthropic-style client http://localhost:1234. Any placeholder key works while Require Authentication is off, and the model is an identifier that GET /v1/models lists.
solid answer
~40 sStart the server with the **Start server** switch in LM Studio's Developer tab; it listens on port `1234` by default, and the port is a Server Settings value you can change. An OpenAI-style client takes `http://localhost:1234/v1` as its base URL; an Anthropic-style client takes `http://localhost:1234`, because its SDK appends `/v1/messages` itself. LM Studio does not require authentication by default, so the key is not checked and the docs' examples pass a placeholder such as `lm-studio`; once **Require Authentication** is on (LM Studio 0.4.0 or newer) it must be a real API token. The `model` value is an identifier from `GET /v1/models`. With Just in Time Model Loading on, the default, that list holds every downloaded model and the first request for one loads it, so that call is slow.
code
python · 15 linesfrom openai import OpenAI
client = OpenAI(
base_url="http://localhost:1234/v1",
api_key="lm-studio", # any value while Require Authentication is off
)
# The identifiers the server will accept as `model`
print([m.id for m in client.models.list().data])
reply = client.chat.completions.create(
model="your-model", # one of the ids printed above
messages=[{"role": "user", "content": "Say hello."}],
)
print(reply.choices[0].message.content)go deeper
Recall port 1234, the /v1 base URL for OpenAI-style clients, that the key is unchecked by default, and that the model id comes from GET /v1/models.
Explain why OpenAI and Anthropic clients need different base URLs, and how JIT loading changes both what /v1/models lists and how long the first call takes.
Show you know which defaults stop being safe: a placeholder key only works while authentication is off, and the localhost bind is what keeps an unauthenticated server private.
Weigh standardising every tool on one compatible route family against using LM Studio's native API for its extras, given that each client SDK fixes the route it calls.
## What the extension is talking to LM Studio's **local server** is the HTTP API the desktop app (or its headless daemon) exposes so that other programs can use the models you downloaded. You start it from the **Developer** tab by toggling the **Start server** switch; the LM Studio CLI can start it too. Once it is up it answers on **port 1234** by default, bound to `127.0.0.1`, so only programs on the same machine can reach it. The port is the **Server Port** value under Server Settings, which matters if something else on the machine already owns 1234. One port carries several **route families**, and a client picks the family its SDK speaks: - OpenAI-style routes under `/v1`: `/v1/models`, `/v1/chat/completions`, `/v1/responses`, `/v1/embeddings` and `/v1/completions`. - An Anthropic-style route, `/v1/messages`. - LM Studio's own REST API under `/api/v1`, which also loads, unloads and downloads models. A coding-assistant extension almost always ships with an OpenAI-compatible or Anthropic-compatible provider setting, so the job is filling three fields correctly. ## The three values a client needs | Field | OpenAI-style client | Anthropic-style client | When it changes | |---|---|---|---| | Base URL | `http://localhost:1234/v1` | `http://localhost:1234` | You change the port, or reach the server from another machine | | API key | any placeholder | any placeholder | **Require Authentication** is switched on: a real token | | Model | an id from `GET /v1/models` | the same id | You download or load a different model | The base URL differs because each SDK appends its own path. The OpenAI SDK adds `/chat/completions` to whatever base you give it, so the base must already end in `/v1`. The Anthropic SDK adds `/v1/messages`, so its base stops at the port; giving it `/v1` produces a doubled path that the server does not serve. ## Where the model identifier comes from The `model` field is not a file name. It is the identifier LM Studio assigns, the value the `/v1/models` route returns (for example a `publisher/model` key). What that route returns depends on **Just in Time (JIT) loading**: 1. With JIT loading **on** (the default), `GET /v1/models` lists every downloaded model, loaded or not. 2. The first inference request that names an unloaded model makes the server load it, then answer. That first call waits for the load; later calls are fast. 3. With JIT loading **off**, `GET /v1/models` lists only models already in memory, and a request for anything else fails until you load it yourself. So an extension that offers a model picker filled from `/v1/models` shows your whole library by default, and picking an entry is enough to load it. ## When the key starts to matter By default **LM Studio does not require authentication** for API requests, so the key field is decoration. The OpenAI SDK still wants a value, which is why the docs pass a placeholder. That changes when someone switches on **Require Authentication** in Server Settings, available from LM Studio 0.4.0: from then on API clients must present a valid API token in the `Authorization` header, which is exactly where the OpenAI SDK puts its `api_key`. The Anthropic-style route also accepts the token in `x-api-key`. Tokens are created under **Manage Tokens**; this matters most once the server is reachable from other machines. ## First-day failures and their causes - **Connection refused** — the server switch is off, or the port is no longer 1234. - **404 on every call** — an OpenAI client was given a base URL without `/v1`, or an Anthropic client one with it. - **A long pause, then an answer** — JIT loading is loading the model on the first request; nothing is broken. - **The model list shows one entry although ten are downloaded** — JIT loading is off, so only loaded models are listed. - **Rejected requests after a settings change** — authentication was switched on and the placeholder key is no longer accepted. ## Checking the setup before blaming the extension Two requests from a terminal settle most doubts: 1. `GET http://localhost:1234/v1/models` — if it answers, the server is up on that port, and the ids it returns are the only values `model` may take. 2. A one-line chat request naming one of those ids — slow once and fast afterwards means JIT loading is working as designed. If the first fails, fix the server switch or the port. If the second fails with an id the server listed, look at the model itself, for example whether it can be loaded on this machine, rather than at the extension's settings. The request and response bodies themselves follow the hosted APIs' contracts; what is specific here is the port, the path, the key policy and the identifier.
- Why does the first request of the morning take far longer than the rest?With JIT loading on, a request for a model that is not in memory makes LM Studio load it before answering. Models loaded that way are unloaded again after 60 idle minutes by default, so the first call after a quiet spell pays the load and later calls do not.
- The extension's model picker shows only one model although ten are downloaded. What is going on?Just in Time Model Loading is switched off. In that mode `GET /v1/models` returns only models already loaded into memory, and requests for any other model fail until you load it. Turn JIT loading back on, or load the models the extension needs.
- LM Studio's server rejects requests without a valid API key by default.
- An OpenAI client's base URL is http://localhost:1234 with no /v1.
- The model field must be the GGUF file name on disk.
- Every model has to be loaded by hand before an API request can use it.
- An Anthropic client should use http://localhost:1234/v1 as its base URL.