2.9 KiB
2.9 KiB
| title | aliases | tags | sources | created | updated | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| LM Studio — OpenAI Compatibility Endpoints |
|
|
|
2026-04-30 | 2026-04-30 |
LM Studio — OpenAI Compatibility Endpoints
LM Studio exposes an OpenAI-compatible HTTP server. Any existing OpenAI client (Python, TypeScript, cURL, C#, etc.) works against it by changing only the base URL.
Default port: 1234.
Supported Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/v1/models |
GET | List loaded/available models |
/v1/responses |
POST | Responses API (Codex-compatible) |
/v1/chat/completions |
POST | Chat with text and images |
/v1/embeddings |
POST | Generate text embeddings |
/v1/completions |
POST | Legacy completions |
Switching Base URL
Only one line changes — the base_url / baseUrl property.
Python
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:1234/v1"
)
# rest of your code unchanged
TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
baseUrl: "http://localhost:1234/v1"
});
cURL
curl http://localhost:1234/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "<model-identifier-from-lmstudio>",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
Codex Support
LM Studio supports OpenAI Codex via the POST /v1/responses endpoint — the same one Codex targets.
Key Takeaways
- Drop-in replacement — swap
base_urltohttp://localhost:1234/v1; no other code changes needed - Five endpoints — models, responses, chat/completions, embeddings, legacy completions
- No API key required by default (LM Studio runs locally)
- Codex works because LM Studio implements
/v1/responses - Model IDs differ — use the model identifier shown in LM Studio, not OpenAI slugs like
gpt-4o - For richer stats (token/s, TTFT, model lifecycle) use the wiki/claude-code/lmstudio-rest-api instead
Related Articles
- wiki/claude-code/lmstudio-anthropic-compat —
/v1/messagesdrop-in for Claude SDK - wiki/claude-code/lmstudio-chat-completions — full param reference for
/v1/chat/completions - wiki/claude-code/lmstudio-embeddings —
/v1/embeddingsfor local RAG pipelines - wiki/claude-code/lmstudio-rest-api — native v1 API with extended model metadata
- wiki/claude-code/lmstudio-idle-ttl-auto-evict — memory management for loaded models
Sources
- LM Studio OpenAI Compat Docs — raw/OpenAI Compatibility Endpoints.md