tinycodinglm / lmstudio /lmstudio-0105.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
2.66 kB
opencode trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

How do I use LM Studio's native REST API v1 (/api/v1/chat, /api/v1/models) including stateful chats with response_id and MCP integrations? Include curl code examples.

Assistant

LM Studio native REST API v1 (/api/v1/*). Start the local server first (default http://localhost:1234). Authorization: Bearer is only needed if you enabled auth; otherwise omit it.

bash
# Chat
curl http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-identifier-from-lm-studio",
    "input": "Hello, how are you?",
    "temperature": 0.7,
    "max_output_tokens": 1024,
    "store": true
  }'

Endpoints:

  • POST /api/v1/chat - chat (supports MCP, stateful chats)
  • GET /api/v1/models - list available 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
  • GET /api/v1/models/download/status - download progress

Stateful chats: when store: true (default), the response includes response_id like resp_.... Pass it as previous_response_id to continue without resending history:

bash
curl -X POST http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"model": "model-identifier", "input": "Show me a Python example.", "previous_response_id": "resp_abc123..."}'

MCP (only connect to servers you trust):

bash
curl -X POST http://localhost:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-identifier",
    "input": "What are trending models?",
    "context_length": 8000,
    "integrations": [{
      "type": "ephemeral_mcp",
      "server_label": "huggingface",
      "server_url": "https://huggingface.co/mcp",
      "allowed_tools": ["model_search"]
    }]
  }'

Response contains output[], stats (tokens/sec, TTFT), and response_id when stored.