LmStudio API KEY ? #7337

Closed
opened 2026-02-16 18:06:53 -05:00 by yindo · 5 comments
Owner

Originally created by @erdalbektas on GitHub (Jan 23, 2026).

Originally assigned to: @thdxr on GitHub.

Description

I want to run local llms via the LMStudio and connect the running model to OpenCode, to use it offline. Opencode has a connect to LMStudio menu, but asks for API key. Instead, LM Studio has an endpoint, that sends and receives & sends calls in OpenAI standard.

Or at least, this part needs a "API Base URL" or a "Custom API Endpoint" otherwise.

Image

Plugins

No response

OpenCode version

1.1.34

Steps to reproduce

  1. add models
  2. lmstudio

Screenshot and/or share link

No response

Operating System

macOS 15.7.3

Terminal

No response

Originally created by @erdalbektas on GitHub (Jan 23, 2026). Originally assigned to: @thdxr on GitHub. ### Description I want to run local llms via the LMStudio and connect the running model to OpenCode, to use it offline. Opencode has a connect to LMStudio menu, but asks for API key. Instead, LM Studio has an endpoint, that sends and receives & sends calls in OpenAI standard. Or at least, this part needs a "API Base URL" or a "Custom API Endpoint" otherwise. <img width="624" height="323" alt="Image" src="https://github.com/user-attachments/assets/fdd4cf9a-0fcb-4868-ba61-ccf88c42def4" /> ### Plugins _No response_ ### OpenCode version 1.1.34 ### Steps to reproduce 1. add models 2. lmstudio ### Screenshot and/or share link _No response_ ### Operating System macOS 15.7.3 ### Terminal _No response_
yindo added the bug label 2026-02-16 18:06:53 -05:00
yindo closed this issue 2026-02-16 18:06:53 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 23, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #4255: OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array (LM Studio integration issues with local models)
  • #7486: Only return tool_call parameters but cannot run the tool with local LLM (related LM Studio configuration issues)
  • #3270: LM Studio "failed to send message" error (LM Studio connection/configuration issues)
  • #6649: Weird error with tool calling on local model (local model tool calling problems)
  • #4255: OpenCode hangs with LM Studio (related to local model configuration)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 23, 2026): This issue might be a duplicate of existing issues. Please check: - #4255: OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array (LM Studio integration issues with local models) - #7486: Only return tool_call parameters but cannot run the tool with local LLM (related LM Studio configuration issues) - #3270: LM Studio "failed to send message" error (LM Studio connection/configuration issues) - #6649: Weird error with tool calling on local model (local model tool calling problems) - #4255: OpenCode hangs with LM Studio (related to local model configuration) Feel free to ignore if none of these address your specific case.
Author
Owner

@erdalbektas commented on GitHub (Jan 23, 2026):

Nope, not really. Local models can't be connected in this case.

This issue might be a duplicate of existing issues. Please check:

Feel free to ignore if none of these address your specific case.

@erdalbektas commented on GitHub (Jan 23, 2026): Nope, not really. Local models can't be connected in this case. > This issue might be a duplicate of existing issues. Please check: > > * [OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array #4255](https://github.com/anomalyco/opencode/issues/4255): OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array (LM Studio integration issues with local models) > * [Only return tool_call parameters but can not run the tool with local LLM #7486](https://github.com/anomalyco/opencode/issues/7486): Only return tool_call parameters but cannot run the tool with local LLM (related LM Studio configuration issues) > * [LM Studio "failed to send message" error #3270](https://github.com/anomalyco/opencode/issues/3270): LM Studio "failed to send message" error (LM Studio connection/configuration issues) > * [Weird error with toolcalling on local model #6649](https://github.com/anomalyco/opencode/issues/6649): Weird error with tool calling on local model (local model tool calling problems) > * [OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array #4255](https://github.com/anomalyco/opencode/issues/4255): OpenCode hangs with LM Studio (related to local model configuration) > > Feel free to ignore if none of these address your specific case.
Author
Owner

@erdalbektas commented on GitHub (Jan 23, 2026):

Ok, if anyone experiences such, here is the solution;

'/connect' function did not work for me, so I had to do this, suggested by AI;

Step 1: Locate your Configuration File

OpenCode stores its configuration in a JSON file.

Depending on your OS, you can find it here:

macOS / Linux: ~/.config/opencode/opencode.json
Windows: %USERPROFILE%.config\opencode\opencode.json (usually C:\Users\YourName.config\opencode\opencode.json)

Step 2: Manually Add LM Studio

Open that opencode.json file in a text editor (like Notepad, VS Code, or Nano) and paste the following configuration inside the "provider" block.

Note: If the file is empty or doesn't exist, you can create it with this full content:

code
JSON
"
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"lmstudio": {
"npm": "@ai-sdk/openai-compatible",
"name": "LM Studio (Local)",
"options": {
"baseURL": "http://127.0.0.1:1234/v1",
"apiKey": "not-needed"
}
}
}
}
"

Step 3: Verify LM Studio Settings

In LM Studio, ensure the Local Server is running.

Check that the CORS setting in LM Studio is "On" (this is usually found in the server side-panel).

Ensure your URL ends in /v1.

OpenCode requires this to communicate with the OpenAI-compatible endpoint LM Studio provides.

Step 4: Use the Model in OpenCode

Restart OpenCode.

If you are in the terminal (TUI), run the command: /models

You should now see LM Studio (Local) as a provider.

Select your model (e.g., qwen3-8b from your screenshot).

I believe there should be a simpler way, but it. is how it is. Just working with no problem.

@erdalbektas commented on GitHub (Jan 23, 2026): Ok, if anyone experiences such, here is the solution; '/connect' function did not work for me, so I had to do this, suggested by AI; **Step 1: Locate your Configuration File** OpenCode stores its configuration in a JSON file. Depending on your OS, you can find it here: macOS / Linux: ~/.config/opencode/opencode.json Windows: %USERPROFILE%\.config\opencode\opencode.json (usually C:\Users\YourName\.config\opencode\opencode.json) **Step 2: Manually Add LM Studio** Open that opencode.json file in a text editor (like Notepad, VS Code, or Nano) and paste the following configuration inside the "provider" block. Note: If the file is empty or doesn't exist, you can create it with this full content: code JSON " { "$schema": "https://opencode.ai/config.json", "provider": { "lmstudio": { "npm": "@ai-sdk/openai-compatible", "name": "LM Studio (Local)", "options": { "baseURL": "http://127.0.0.1:1234/v1", "apiKey": "not-needed" } } } } " **Step 3: Verify LM Studio Settings** In LM Studio, ensure the Local Server is running. Check that the CORS setting in LM Studio is "On" (this is usually found in the server side-panel). Ensure your URL ends in /v1. OpenCode requires this to communicate with the OpenAI-compatible endpoint LM Studio provides. **Step 4: Use the Model in OpenCode** Restart OpenCode. If you are in the terminal (TUI), run the command: /models You should now see LM Studio (Local) as a provider. Select your model (e.g., qwen3-8b from your screenshot). I believe there should be a simpler way, but it. is how it is. Just working with no problem.
Author
Owner

@gyan-kukufm commented on GitHub (Feb 10, 2026):

Hi @erdalbektas ,

I am still facing issue connecting opencode with local LMStudio provider. Is there anyone who can confirm whether this setup works or not?
I am using latest version of opencode which i installed just yesterday.

@gyan-kukufm commented on GitHub (Feb 10, 2026): Hi @erdalbektas , I am still facing issue connecting opencode with local LMStudio provider. Is there anyone who can confirm whether this setup works or not? I am using latest version of opencode which i installed just yesterday.
Author
Owner

@erdalbektas commented on GitHub (Feb 10, 2026):

Hi @gyan-kukufm,

Works just fine for me.

Anomaly will make this a selection among other providers in the later versions, I hope. That would make things significantly easier in local model utilization.

@erdalbektas commented on GitHub (Feb 10, 2026): Hi @gyan-kukufm, Works just fine for me. Anomaly will make this a selection among other providers in the later versions, I hope. That would make things significantly easier in local model utilization.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7337