Skip to content

Attempting to use LM Studio with OpenCode - TypeError [ERR_INVALID_URL]: "undefined/chat/completions" cannot be parsed as URL. #195

Closed

Description

@teslanaut

I am using OpenCode on an M4 Mac on OS Sequoia. I have LM Studio setup with to serve "unsloth/Magistral-Small-2506-GGUF" as the model. When trying to /init, I get the error mentioned above:

TypeError [ERR_INVALID_URL]: "undefined/chat/completions" cannot be parsed as URL.

I believe LM Studio is expecting /v1/chat/completions or /v1/completions but I'm unsure how to work around this for OpenCode.

Below are the the .toml files I created for the opencode.json, model & provider.

#.opencode.json

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"lmstudio": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://localhost:1234/v1"
"apiKey": "12345"
},
"models": {
"magistral-small-2506": {}
}
}
}
}

#magistral-small-2506.toml -

name = "magistral-small-2506"
attachment = true
reasoning = true
temperature = true

[cost]
input = 3.00
output = 15.00
cache_read = 3.75
cache_write = 0.30

[limit]
context = 200_000
output = 50_000

#provider.toml:

name = "lmstudio"
env = ["12345"]
url = ["http://localhost:1234/v1"]
npm = "@ai-sdk/openai-compatible"

Activity

  1. thdxr commented on Jun 19, 2025

    @thdxr
    Member

    hey we just reworked how config works - can you refer to readme and try again? should be simpler and all in one file now

  2. self-assigned this
    on Jun 19, 2025
  3. teslanaut commented on Jun 19, 2025

    @teslanaut
    Author

    hey we just reworked how config works - can you refer to readme and try again? should be simpler and all in one file now

    Seems to work now. Here is what my config.json looks like. Thank you for your help:

    {
    "$schema": "https://opencode.ai/config.json",
    "provider": {
    "lmstudio": {
    "npm": "@ai-sdk/openai-compatible",
    "options": {
    "baseURL": "http://localhost:1234/v1"
    },
    "models": {
    "lmstudio/unsloth/magistral-small-2506": {}
    }
    }
    },
    "model": "lmstudio/unsloth/magistral-small-2506"
    }

    Image
  4. testacode commented on Jun 20, 2025

    @testacode

    Nice! It would be neat to be able to add a full list of all of the locally downloaded models from lm studio into the config automagically.

  5. teslanaut commented on Jun 20, 2025

    @teslanaut
    Author

    Nice! It would be neat to be able to add a full list of all of the locally downloaded models from lm studio into the config automagically.

    Agreed! If it could just populate the models list with /v1/models, that would make things so much easier. And also have intelligent model switching where you can allocate certain models for certain tasks. Line one for web research, one for Architect, one for coding, and so on.

  6. DimmKirr commented on Aug 13, 2025

    @DimmKirr

    Pasting beautified json just in case someone needs it for visual parsing

    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "lmstudio": {
          "npm": "@ai-sdk/openai-compatible",
          "options": {
            "baseURL": "http://localhost:1234/v1"
          },
          "models": {
            "lmstudio/unsloth/magistral-small-2506": {}
          }
        }
      },
      "model": "lmstudio/unsloth/magistral-small-2506"
    }
  7. TRusselo commented on Dec 20, 2025

    @TRusselo

    Im getting the same error trying to connect to LiteLLM v 0.174 released 4 hours ago

    Image
    {
      "provider": {
        "liteLLM": {
          "name": "liteLLM",
          "npm": "@ai-sdk/openai-compatible",
          "models": {
            "chatgpt-4o-latest": {
              "name": "ChatGPT 4o Latest"
            },
            "claude-3-5-haiku-latest": {
              "name": "Claude 3.5 Haiku Latest"
            },
            "claude-3-5-sonnet-latest": {
              "name": "Claude 3.5 Sonnet Latest"
            },
            "claude-3-7-sonnet-latest": {
              "name": "Claude 3.7 Sonnet Latest"
            },
            "claude-haiku-4-5": {
              "name": "Claude Haiku 4.5"
            },
            "claude-sonnet-4-5": {
              "name": "Claude Sonnet 4.5"
            },
            "gemini/gemini-2.0-flash": {
              "name": "Gemini 2.0 Flash"
            },
            "gemini/gemini-2.0-pro-exp-": {
              "name": "Gemini 2.0 Pro Exp"
            },
            "gemini/gemini-2.5-flash": {
              "name": "Gemini 2.5 Flash"
            },
            "gemini/gemini-2.5-pro": {
              "name": "Gemini 2.5 Pro"
            },
            "gemini/gemma-3-27b-it": {
              "name": "Gemma 3 27b IT"
            },
            "gpt-3.5-turbo": {
              "name": "GPT 3.5 Turbo"
            },
            "gpt-4.1": {
              "name": "GPT 4.1"
            },
            "gpt-4.1-mini": {
              "name": "GPT 4.1 Mini"
            },
            "gpt-5-codex": {
              "name": "GPT 5 Codex"
            },
            "gpt-5.1": {
              "name": "GPT 5.1"
            },
            "gpt-5.2": {
              "name": "GPT 5.2"
            },
            "gpt-image-1": {
              "name": "GPT Image 1"
            },
            "o4-mini": {
              "name": "o4 Mini"
            },
            "o4-mini-deep-research": {
              "name": "o4 Mini Deep Research"
            },
          "options": {
            "baseURL": "http://192.168.1.12:4005/v1",
            "api-key": "sk-xxxxxxxxxxxxxxxxxx"
          }
          }
        }
      },
      "$schema": "https://opencode.ai/config.json"
    }
    
    
    
    Image

    note litellm is in a docker its internal port is 4000 but outside docker its 4005, docker does the mapping. this is not the faliure.

    or should I open a fresh ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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