Nodes/Enviral Design Node Pack/LM Studio Unified (URL + API Key)
ComfyUI Node

LM Studio Unified (URL + API Key)

Ask a local LLM to look at your image — straight from the graph

By EnviralDesign·Created 4 months ago·Updated 21 days ago· 1
LM Studio Unified (URL + API Key)
  • image
  • generated_text
base_urlhttp://127.0.0.1:1234/v1
api_key
modelgemma-4-e4b-uncensored-hauhaucs-aggressive
promptDescribe this image in detail.
system_promptYou are a helpful AI assistant.
seed-1
api_key_env_varLMSTUDIO_API_KEY
max_tokens1000
temperature0.70
timeout_seconds300
max_images20
user_agentMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
debugfalse

So you've got a local LLM running in LM Studio and a ComfyUI graph full of images, and you'd like the two to talk. Maybe you want a caption for a generated image, a critique, a rewritten prompt, or a decision ("pick the best frame") that feeds back into the graph. The pieces all exist, but wiring a custom HTTP call into ComfyUI by hand is a small project of its own.

LM Studio Unified (URL + API Key) is that wiring, done for you. It calls LM Studio's OpenAI-compatible chat endpoint with text, an image, or both, and hands back the model's reply as a generated_text string.

How it works

Everything goes through LM Studio's /v1/chat/completions API. The node builds a chat message from your system_prompt and prompt, and if you connect an image, each frame of the batch is encoded to a JPEG data URL and sent as a separate image_url content part (capped by max_images). So vision-capable models actually see your image; text-only models can still use it as a pure text chat node.

It's intentionally dependency-free - plain urllib, no openai SDK, no pip installs. Request details go to the ComfyUI console when debug is on, and IS_CHANGED hashes all inputs so the node re-runs when anything changes and doesn't rerun when nothing does.

The inputs that matter

  • base_url - the endpoint. Defaults to http://127.0.0.1:1234/v1, the standard local LM Studio address. It also accepts https://host, /v1-style paths, or a full /v1/chat/completions URL, so it works against remote/Cloudflare-fronted routes too.
  • model - the model id from LM Studio's /v1/models list. Must match what you loaded in the app.
  • prompt / system_prompt - the user and system messages.
  • image (optional) - the IMAGE batch to send.
  • api_key / api_key_env_var - optional. A blank api_key falls back to the env var (default LMSTUDIO_API_KEY), which on Windows also checks User/Machine registry values.
  • seed, max_tokens, temperature, timeout_seconds, user_agent, debug - the rest of the knobs. user_agent matters for routes behind Cloudflare that block Python's default urllib signature; there's a browser-like one preloaded.

Output: generated_text, the model's reply as a STRING.

Install

Part of the Enviral Design Node Pack. ComfyUI Manager: search "Enviral Design Node Pack". Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/EnviralDesign/comfyUI-enviral-design-node-pack

then restart. No extra dependencies, and no LM Studio install required by the node itself - you just need an endpoint reachable.

Gotchas worth knowing

The single most common failure is a model id that doesn't match anything loaded in LM Studio - check the app's model list, not your memory of the filename. For local use, 127.0.0.1:1234 with no key is the zero-config path; if you've pointed it at a remote route, set the key (or env var) and make sure the server's CORS/auth accepts browser-like traffic. And remember the model you're asking must be vision-capable to describe images - a text-only model will politely ignore the image parts. Debug mode is your friend here: it prints exactly what's being sent.

CategoryEnviralDesign/llm

Inputs (14)

NameTypeDefaultDescription
base_urlSTRINGhttp://127.0.0.1:1234/v1LM Studio OpenAI-compatible base URL. Accepts https://host, https://host/v1, or full /v1/chat/completions URL.
api_keySTRINGOptional LM Studio API key. Sent as Authorization: Bearer <key> when provided.
modelSTRINGgemma-4-e4b-uncensored-hauhaucs-aggressiveModel id from LM Studio /v1/models.
promptSTRINGDescribe this image in detail.User prompt. Can be used with an image input or by itself.
system_promptSTRINGYou are a helpful AI assistant.
seedINT-1-1–18446744073709550000
imageoptIMAGE
api_key_env_varoptSTRINGLMSTUDIO_API_KEYOptional environment variable to read the API key from when api_key is blank.
max_tokensoptINT10001–32768
temperatureoptFLOAT0.700–2
timeout_secondsoptINT30010–3600
max_imagesoptINT201–200Maximum number of images from the input IMAGE batch to send as separate image_url parts.
user_agentoptSTRINGMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36HTTP User-Agent sent to LM Studio. Useful when Cloudflare blocks Python's default urllib signature.
debugoptBOOLEANfalse

Outputs (1)

NameTypeDescription
generated_textSTRING