lmstudio-ai / lmstudio-ai/lmstudio-python

Improve behaviour when API host is given as a full URL

Open
#157 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
875
Forks
166
PR merge metrics
No merged PRs in 30d

Description

I have LM Studio 0.3.24 (GUI) running on another Windows 11 computer on my local network. It works just fine when I send OpenAI requests, but it fails when I use this library.

Here are some tests results:
```
Sending OpenAI request to `http://192.168.3.220:1234/v1`...
SUCCESS
----------------------------------------
Sending LM Studio request to `http://192.168.3.220:1234`...
LM Studio is not reachable at http://192.168.3.220:1234. Is LM Studio running?
FAILED
----------------------------------------
Sending LM Studio request to `http://192.168.3.220:1234/llm`...
LM Studio is not reachable at http://192.168.3.220:1234/llm. Is LM Studio running?
FAILED
----------------------------------------
Sending LM Studio request to `ws://192.168.3.220:1234`...
LM Studio is not reachable at ws://192.168.3.220:1234. Is LM Studio running?
FAILED
----------------------------------------
Sending LM Studio request to `ws://192.168.3.220:1234/llm`...
LM Studio is not reachable at ws://192.168.3.220:1234/llm. Is LM Studio running?
FAILED
----------------------------------------
Current Python version: 3.13.7

----------------------------------------
Pip show output:

Name: lmstudio
Version: 1.5.0
Summary: LM Studio Python SDK
Home-page: https://github.com/lmstudio-ai/lmstudio-sdk-python
Author:
Author-email: LM Studio
License-Expression: MIT
Location: /home/vlad/Documents/Apps/lmstudio_test/venv/lib/python3.13/site-packages
Requires: anyio, httpx, httpx-ws, msgspec, typing-extensions
Required-by:
----------------------------------------
```

Code that gives the output above

```python
import lmstudio as lms
from openai import OpenAI
import subprocess
import sys
import platform

OPENAI_BASE_URL = "http://192.168.3.220:1234/v1"
HTTP_URL = "http://192.168.3.220:1234"
HTTP_URL_WITH_LLM_PATH = "http://192.168.3.220:1234/llm"
WS_URL = "ws://192.168.3.220:1234"
WS_URL_WITH_LLM_PATH = "ws://192.168.3.220:1234/llm"

def main():
try:
print(f"Sending OpenAI request to `{OPENAI_BASE_URL}`...")
OpenAI(base_url=OPENAI_BASE_URL, api_key="dummy").models.list()
print("SUCCESS")
except Exception as e:
print(e)
print("FAILED")
print('-' * 40)

try:
print(f"Sending LM Studio request to `{HTTP_URL}`...")
lms.configure_default_client(HTTP_URL)
lms.list_downloaded_models()
print("SUCCESS")
except Exception as e:
print(e)
print("FAILED")
finally:
lms.sync_api._reset_default_client()
print('-' * 40)

try:
print(f"Sending LM Studio request to `{HTTP_URL_WITH_LLM_PATH}`...")
lms.configure_default_client(HTTP_URL_WITH_LLM_PATH)
lms.list_downloaded_models()
print("SUCCESS")
except Exception as e:
print(e)
print("FAILED")
finally:
lms.sync_api._reset_default_client()
print('-' * 40)

try:
print(f"Sending LM Studio request to `{WS_URL}`...")
lms.configure_default_client(WS_URL)
lms.list_downloaded_models()
print("SUCCESS")
except Exception as e:
print(e)
print("FAILED")
finally:
lms.sync_api._reset_default_client()
print('-' * 40)

try:
print(f"Sending LM Studio request to `{WS_URL_WITH_LLM_PATH}`...")
lms.configure_default_client(WS_URL_WITH_LLM_PATH)
lms.list_downloaded_models()
print("SUCCESS")
except Exception as e:
print(e)
print("FAILED")
finally:
lms.sync_api._reset_default_client()
print('-' * 40)

print(f"Current Python version: {platform.python_version()}\n")
print('-' * 40)

print("Pip show output:\n")
subprocess.run([sys.executable, "-m", "pip", "show", "lmstudio"])
print('-' * 40)

if __name__ == "__main__":
main()
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with configure_default_client and trace how the supplied host is parsed before lms.list_downloaded_models runs. Reproduce the examples using HTTP and WebSocket URLs, including paths, and consider the issue complete when full URL inputs connect consistently or produce the intended normalized behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.