Skip to content

model discovery fails for LM Studio when using API keys. #51570

Open

Description

@joepetrakovich

Description

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.

Screenshot and/or share link

No response

Operating System

Mac Golden Gate 27

Terminal

ghostty

Activity

  1. github-actions commented on Sep 27, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Add system details needed to reproduce the issue: OpenCode version, operating system, and LM Studio version. These details are currently missing.

    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:

    • #18011: LM Studio model discovery shows an incomplete model list, including a report that it happens when using an API key.
    • #30896: LM Studio models cannot be detected.

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on Sep 27, 2026

    @github-actions
    Contributor

    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.

  3. github-actions commented on Sep 27, 2026

    @github-actions
    Contributor

    Thanks for updating the issue with the reproduction steps and system details!

  4. joepetrakovich commented on Sep 27, 2026

    @joepetrakovich
    Author

    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"
          }
        },
    
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