You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
model discovery fails for LM Studio when using API keys. #51570
I noticed /models errors in LM Studio because the API key isn't being sent, even though it is set up with the /connect provider method and works for inference in opencode, so it sends the api key properly
I tried adding it to the config manually and adding "apiKey": "{env:LMS_API_KEY}", similar to what the docs suggest for Ollama but it doesn't work so I take it apiKey isnt supported for custom providers?
What I expect:
Just using /connect and adding LM Studio with an API key should work like any other providers. Currently its half broken because of this model discovery issue.
Opencode seems to assume these providers should be unauthenticated URLs which is no longer true.
2026-09-27 10:30:44 [DEBUG]
Received request: GET to /api/v1/models
2026-09-27 10:30:44 [ERROR]
[LM STUDIO SERVER] {
"error": {
"type": "invalid_request",
"code": "invalid_api_key",
"message": "An LM Studio API token is required to make requests to this server, but none was provided using the Authorization header using the 'Bearer' scheme (i.e., 'Authorization: Bearer $LM_API_TOKEN'). Learn more at: https://lmstudio.ai/docs/developer/core/authentication."
}
}
Plugins
None
OpenCode version
2.0.18
LM Studio version
Version 0.4.25+1 (0.4.25+1)
Steps to reproduce
/connect
LM Studio
add api key
notice /api/v1/models error in LM Studio because Opencode discovery didnt send api key.
opencode adds three random default models that arent even available.
Thanks for adding your OpenCode version, operating system, and reproduction steps. Please also add the LM Studio version you’re using so the setup can be reproduced.
FWIW I was able to get this to work by hardcoding the API key into the config for the lmstudio provider.
Opencode seems to have a background probe constantly running against lmstudio even if you dont configure it as a provider and it of course fails if youre using authentication with LM Studio.
I could NOT get the environment variable to work with {env:ENV_NAME} or just {EVN_NAME}
"lmstudio": {
"name": "LM Studio",
"settings": {
"baseURL": "http://127.0.0.1:1234/v1",
"apiKey": "hardcode your actual key here"
}
},
Activity
github-actions commentedon Sep 27, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be related to existing LM Studio model-discovery reports. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Sep 27, 2026
Thanks for adding your OpenCode version, operating system, and reproduction steps. Please also add the LM Studio version you’re using so the setup can be reproduced.
github-actions commentedon Sep 27, 2026
Thanks for updating the issue with the reproduction steps and system details!
joepetrakovich commentedon Sep 27, 2026
FWIW I was able to get this to work by hardcoding the API key into the config for the
lmstudioprovider.Opencode seems to have a background probe constantly running against lmstudio even if you dont configure it as a provider and it of course fails if youre using authentication with LM Studio.
I could NOT get the environment variable to work with {env:ENV_NAME} or just {EVN_NAME}