File size: 1,933 Bytes
b27bfb3 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "lmstudio-0075", "name": "vision"}
{"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": "Does LM Studio support vision (image input) models locally? Show how to send an image with the OpenAI-compatible chat completions API using base64. Include code examples."}}
{"type": "message", "message": {"role": "assistant", "content": "**Yes - with a vision-capable model loaded** (e.g. LLaVA, Qwen-VL - check the Models tab for VL variants). Text-only models will error on image input.\n\n```python\nimport base64\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"http://localhost:1234/v1\", api_key=\"lm-studio\")\n\nwith open(\"photo.jpg\", \"rb\") as f:\n image_b64 = base64.b64encode(f.read()).decode(\"utf-8\")\n\nresponse = client.chat.completions.create(\n model=\"model-identifier-of-loaded-vision-model\",\n messages=[\n {\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Describe this image.\"},\n {\n \"type\": \"image_url\",\n \"image_url\": {\"url\": f\"data:image/jpeg;base64,{image_b64}\"},\n },\n ],\n }\n ],\n max_tokens=500,\n)\nprint(response.choices[0].message.content)\n```\n\n**Limits:**\n- Single images only; no video (send frames individually)\n- Images are resized to the model's native resolution\n- Larger images consume more context tokens"}}
|