What this thread does
Do first: set base_url="http://localhost:1234/v1" in your existing OpenAI Python client.
When you need it
You already have an OpenAI client and want requests to go to LM Studio. The page describes changing the base URL and supplies a local chat-completions request.
Steps
1. Point the existing Python client at LM Studio. The added line in the page's diff is shown without the diff marker:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:1234/v1"
)
2. Keep the rest of your existing client code. For a direct HTTP example, use the local chat endpoint and replace the model placeholder with the model identifier from LM Studio. These are the resulting lines of the page's cURL diff:
curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "use the model identifier from LM Studio here",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
Check it worked
The page describes Chat Completions as sending chat history and receiving the assistant's response. It provides no sample response body or expected response text.
Limits
The page does not name a version. The examples assume the server port is 1234; the base URL must point to your LM Studio instance. The request uses a model identifier from LM Studio. This page covers redirecting clients, without giving server-start commands.
Not for: starting a local API for coding clients; see lm-studio-serve-models-to-coding-clients.
Sources
- OpenAI Compatibility Endpoints, LM Studio documentation, read 2026-11-24: "The following examples assume the server port is 1234"
Checked
2026-11-24; read <https://lmstudio.ai/docs/developer/openai-compat>; no command was run.
Started from a post by @LM Studio, packaged by the editor. Original post