feat: add HTTP authentication support for LM Studio API endpoints#13
Open
HarelMil wants to merge 3 commits intoagustif:mainfrom
Open
feat: add HTTP authentication support for LM Studio API endpoints#13HarelMil wants to merge 3 commits intoagustif:mainfrom
HarelMil wants to merge 3 commits intoagustif:mainfrom
Conversation
- Reads authentication credentials from ~/.local/share/opencode/auth.json - Uses Bearer token authentication for all LM Studio API requests - Maintains backward compatibility (no header when auth is not configured) - Applies authentication to health check, model discovery, and fetch endpoints - Adds tests to verify authorization header behavior - Fixes 401 Unauthorized errors when LM Studio server requires API key
…ge parsing to identify malformed API and missing header
fix: autoFixAvailable set to false instead of true. Added error messa…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds HTTP authentication support to the opencode-lmstudio plugin, resolving 401 Unauthorized errors when the LM Studio server requires an API key. Might be related to issue #9.
The plugin now reads authentication credentials from
~/.local/share/opencode/auth.jsonand uses Bearer token authentication for all LM Studio API requests.Changes
New Files
src/utils/http.ts- HTTP headers utility that readsauth.jsonand returns appropriate headers including Authorization when credentials existModified Files
src/utils/lmstudio-api.ts- All API endpoint calls now usegetHeaders()to include authentication:checkLMStudioHealth()- Health check endpointdiscoverLMStudioModels()- Model discovery endpointfetchModelsDirect()- Fetch loaded models endpointsrc/utils/index.ts- Updated error messages and refactored error handlingtest/plugin.test.ts- Added tests to verify authorization header behaviorpackage-lock.json- Automatically updated version to the current released version (was0.2.0)Technical Details
Authentication Format: Bearer token authentication used for all HTTP requests
Configuration Location:
~/.local/share/opencode/auth.json{ "lmstudio": { "type": "api", "key": "your-api-key-here" } }Backward Compatibility:
auth.jsonis missing or misconfiguredTesting
All 17 existing tests pass, plus 1 new test specifically for authorization header verification:
TypeScript type checking passes with no errors.
Impact
Security