From 0c8a9fccebe831bc9dc15f2ca9048d34de67a64e Mon Sep 17 00:00:00 2001 From: LUCAS M MORGAN Date: Tue, 5 May 2026 22:40:52 -0500 Subject: [PATCH] Add configurable LM Studio user agent --- lmstudio_nodes.py | 21 ++++++++++++++++++++- pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lmstudio_nodes.py b/lmstudio_nodes.py index bf954d1..6ee6ad7 100644 --- a/lmstudio_nodes.py +++ b/lmstudio_nodes.py @@ -14,6 +14,11 @@ from PIL import Image DEFAULT_BASE_URL = "http://127.0.0.1:1234/v1" DEFAULT_MODEL = "gemma-4-e4b-uncensored-hauhaucs-aggressive" +DEFAULT_USER_AGENT = ( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/120.0.0.0 Safari/537.36" +) def _normalize_base_url(base_url): @@ -154,6 +159,13 @@ class EnviralLmstudioUnified: {"default": 0.7, "min": 0.0, "max": 2.0, "step": 0.05}, ), "timeout_seconds": ("INT", {"default": 300, "min": 10, "max": 3600}), + "user_agent": ( + "STRING", + { + "default": DEFAULT_USER_AGENT, + "tooltip": "HTTP User-Agent sent to LM Studio. Useful when Cloudflare blocks Python's default urllib signature.", + }, + ), "debug": ("BOOLEAN", {"default": False}), }, } @@ -177,6 +189,7 @@ class EnviralLmstudioUnified: max_tokens=1000, temperature=0.7, timeout_seconds=300, + user_agent=DEFAULT_USER_AGENT, debug=False, ): m = hashlib.sha256() @@ -191,6 +204,7 @@ class EnviralLmstudioUnified: max_tokens, temperature, timeout_seconds, + user_agent, debug, ): m.update(str(value).encode("utf-8")) @@ -214,6 +228,7 @@ class EnviralLmstudioUnified: max_tokens=1000, temperature=0.7, timeout_seconds=300, + user_agent=DEFAULT_USER_AGENT, debug=False, ): prompt = str(prompt or "") @@ -254,7 +269,11 @@ class EnviralLmstudioUnified: url = _chat_completions_url(base_url) token = _read_api_key(api_key, api_key_env_var) - headers = {"Content-Type": "application/json"} + headers = { + "Accept": "application/json", + "Content-Type": "application/json", + "User-Agent": str(user_agent or DEFAULT_USER_AGENT), + } if token: headers["Authorization"] = f"Bearer {token}" diff --git a/pyproject.toml b/pyproject.toml index d717d71..969ddf8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "enviral-design-node-pack" -version = "0.1.2" +version = "0.1.3" description = "Small, dependency-light ComfyUI utility nodes from Enviral Design." readme = "README.md" requires-python = ">=3.10"