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
{"type": "session", "harness": "opencode", "id": "lmstudio-0105", "name": "rest api v1"}
{"type": "message", "message": {"role": "system", "content": "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."}}
{"type": "message", "message": {"role": "user", "content": "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."}}
{"type": "message", "message": {"role": "assistant", "content": "**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.\n\n```bash\n# Chat\ncurl http://localhost:1234/api/v1/chat \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"model-identifier-from-lm-studio\",\n \"input\": \"Hello, how are you?\",\n \"temperature\": 0.7,\n \"max_output_tokens\": 1024,\n \"store\": true\n }'\n```\n\n**Endpoints:**\n- `POST /api/v1/chat` - chat (supports MCP, stateful chats)\n- `GET /api/v1/models` - list available models\n- `POST /api/v1/models/load` - load a model\n- `POST /api/v1/models/unload` - unload a model\n- `POST /api/v1/models/download` - download a model\n- `GET /api/v1/models/download/status` - download progress\n\n**Stateful chats:** when `store: true` (default), the response includes `response_id` like `resp_...`. Pass it as `previous_response_id` to continue without resending history:\n\n```bash\ncurl -X POST http://localhost:1234/api/v1/chat \\\n -H \"Content-Type: application/json\" \\\n -d '{\"model\": \"model-identifier\", \"input\": \"Show me a Python example.\", \"previous_response_id\": \"resp_abc123...\"}'\n```\n\n**MCP (only connect to servers you trust):**\n\n```bash\ncurl -X POST http://localhost:1234/api/v1/chat \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"model-identifier\",\n \"input\": \"What are trending models?\",\n \"context_length\": 8000,\n \"integrations\": [{\n \"type\": \"ephemeral_mcp\",\n \"server_label\": \"huggingface\",\n \"server_url\": \"https://huggingface.co/mcp\",\n \"allowed_tools\": [\"model_search\"]\n }]\n }'\n```\n\nResponse contains `output[]`, `stats` (tokens/sec, TTFT), and `response_id` when stored."}}