obsidian/wiki/claude-code/lmstudio-openai-compat-endpoints.md
2026-04-30 14:42:43 +01:00

2.9 KiB

title aliases tags sources created updated
LM Studio — OpenAI Compatibility Endpoints
lmstudio-openai-compat
lmstudio-oai-endpoints
lmstudio
openai
local-llm
api
embeddings
chat-completions
raw/OpenAI Compatibility Endpoints.md
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_url to http://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

Sources