Skip to content

Vision model image support inconsistent between JS SDK and REST API #968

Description

@tobiasbueschel

Which version of LM Studio?
Version 0.3.24

Which operating system?
macOS 26.0 Beta (25A5351b)

What is the bug?
Vision models work correctly when using the LM Studio JavaScript SDK but fail when accessing the same model through the REST API (/v1/chat/completions) or via AI SDK (@ai-sdk/openai-compatible). The same model (gemma-3-27b-it vision variant) processes images successfully through the SDK's client.files.prepareImage() method but returns "Bad Request" errors when attempting to send base64-encoded images through the REST API.

Screenshots
N/A

Logs
When using AI SDK with OpenAI-compatible format:

Direct API call failed: 400 Bad Request

To Reproduce
Steps to reproduce the behavior:

  1. Install AI SDK dependencies:
    npm install @ai-sdk/openai-compatible ai zod
  2. Load a vision-capable model in LM Studio (e.g., gemma-3-27b-it vision variant)
  3. Attempt to use the model with AI SDK:
    import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
    import { generateObject } from "ai";
    import { z } from "zod";
    
    const lmstudio = createOpenAICompatible({ 
      name: "lmstudio", 
      baseURL: "http://localhost:1234/v1" 
    });
    
    const imageBase64 = fs.readFileSync("image.png").toString("base64");
    
    const schema = z.object({
      description: z.string()
    });
    
    const { object } = await generateObject({
      model: lmstudio("gemma-3-27b-it"),
      schema,
      messages: [{
        role: "user",
        content: [
          { type: "text", text: "Describe this image" },
          {
            type: "image_url",
            image_url: { 
              url: `data:image/png;base64,${imageBase64}`
            }
          }
        ]
      }]
    });
  4. Observe "Bad Request" error
  5. Use the same model with LM Studio JS SDK:
    import LMStudioClient from "@lmstudio/sdk";
    
    const client = new LMStudioClient();
    const imageHandle = await client.files.prepareImage("image.png");
    const model = await client.llm.model("gemma-3-27b-it");
    const response = await model.respond([
      { role: "user", content: "Describe this image", images: [imageHandle] }
    ]);
  6. Observe successful response

Expected behavior
The REST API should accept base64-encoded images in the OpenAI-compatible format (as used by AI SDK) and process them the same way the native JS SDK does.

Additional context
This inconsistency prevents the use of vision models with third-party libraries that rely on the OpenAI-compatible REST API (like Vercel's AI SDK). The JS SDK's prepareImage() method appears to handle images differently than what's possible through the REST API, creating a feature gap between the two interfaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions