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

Open
opened 2026-02-16 17:25:20 -05:00 by yindo · 6 comments
Owner

Originally created by @teslanaut on GitHub (Jun 18, 2025).

Originally assigned to: @thdxr on GitHub.

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"

Originally created by @teslanaut on GitHub (Jun 18, 2025). Originally assigned to: @thdxr on GitHub. 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"
Author
Owner

@thdxr commented on GitHub (Jun 18, 2025):

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

@thdxr commented on GitHub (Jun 18, 2025): hey we just reworked how config works - can you refer to readme and try again? should be simpler and all in one file now
Author
Owner

@teslanaut commented on GitHub (Jun 19, 2025):

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
@teslanaut commented on GitHub (Jun 19, 2025): > 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" } <img width="805" alt="Image" src="https://github.com/user-attachments/assets/abcee36a-cd3e-4ef6-8ff8-6c643be83959" />
Author
Owner

@testacode commented on GitHub (Jun 19, 2025):

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.

@testacode commented on GitHub (Jun 19, 2025): 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.
Author
Owner

@teslanaut commented on GitHub (Jun 20, 2025):

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.

@teslanaut commented on GitHub (Jun 20, 2025): > 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.
Author
Owner

@DimmKirr commented on GitHub (Aug 13, 2025):

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"
}
@DimmKirr commented on GitHub (Aug 13, 2025): Pasting beautified json just in case someone needs it for visual parsing ```json { "$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" } ```
Author
Owner

@TRusselo commented on GitHub (Dec 20, 2025):

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?

@TRusselo commented on GitHub (Dec 20, 2025): Im getting the same error trying to connect to LiteLLM v 0.174 released 4 hours ago <img width="915" height="174" alt="Image" src="https://github.com/user-attachments/assets/cb66231c-a77d-4cd4-bcc6-9e6fa44635a5" /> ``` { "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" } ``` <img width="1598" height="1263" alt="Image" src="https://github.com/user-attachments/assets/6bab655f-b74b-40b4-9a52-7cc0eaddfd87" /> 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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#131