DMXAPI 設定 API Key
Setting your key without a restart, and the one way it leaks
- REPORT
Every other node in this pack needs your API key. This one is how you set it without quitting ComfyUI.
The problem it solves is specific: the pack reads its .env exactly once, when the module first loads. Edit that file and nothing changes until you restart, which is annoying when you're three nodes deep in a workflow and your key just expired. So the author put a key field on the canvas.
What it does
It writes DMXAPI_KEY=<your key> into the .env file sitting next to dmxapi_common.py - i.e. ComfyUI/custom_nodes/ComfyUI-DMXAPI/.env - creating or replacing that variable. Then it sets os.environ["DMXAPI_KEY"] in the running ComfyUI process, so the change takes effect immediately, no restart. Every other DMXAPI node resolves its key at call time from that environment variable, so they all pick it up on the next queue.
There's no DMXAPI call here at all. It doesn't validate the key, doesn't check your balance, doesn't tell you the key is wrong. It writes a line to a file and a value to a dict and hands you a REPORT string. It's an output node, so you can run it standalone.
The input, and why it's disguised
One required input: api_key. A frontend script masks the on-canvas field into a password-style box and clears it once the node runs, so nobody reading over your shoulder sees it in plaintext.
That masking is not protection. Read the author's own tooltip: the value is a normal ComfyUI widget value, so it goes into the workflow JSON when you save, and by default it also gets embedded in the metadata of every image your workflow outputs. ComfyUI's Save Image node writes the full prompt and workflow graph into the PNG unless you've turned that off globally - the KB calls this out as an under-discussed default, because posting a file publicly hands over exactly the contents of your graph. So: a DMXAPI SetAPIKey node with a real key in it, saved to disk, is a key sitting in a text file and possibly in a PNG you posted to Civitai.
Don't share workflows or output images that were made with a key typed into this node. Don't save the workflow between typing and running either. If you only ever want the key set, use the safer route:
ComfyUI Settings → DMXAPI → API Key → DMXAPI_KEY. Same .env, same precedence, same immediate effect, no restart - but the value is stored in ComfyUI's user settings file rather than in your workflow. The pack's README recommends this one and I agree; reach for the node only when you want key-setting to be a step inside an automated workflow.
The other caveats
Only DMXAPI_KEY. The model-specific fallbacks - OPENAI_API_KEY, AGNES_API_KEY, MINIMAX_API_KEY - still have to be typed into .env by hand. Useful to know if you're trying to keep one key per model family.
An existing OS environment variable wins. Precedence is node field → DMXAPI_KEY → module-specific variable, and a system environment variable outranks everything in .env. If you've ever exported DMXAPI_KEY in a shell profile, this node's write will look like it worked and then silently stop mattering after the next restart. Fix it at the OS level, or unset the variable first.
Empty is an error. The node refuses blank input on purpose - it's not a "clear the key" button. Edit .env directly if you want to blank it.
The mask also means you can't re-read what you saved. Once the field clears, it's gone from the UI. That's by design, but it does mean you can't verify the key that's currently in .env from the node; open the file.
Installing the pack
This node ships with ComfyUI-DMXAPI:
cd ComfyUI/custom_nodes
git clone https://github.com/mch000534/ComfyUI-DMXAPI
/path/to/ComfyUI/.venv/bin/python -m pip install -r ComfyUI-DMXAPI/requirements.txt
ComfyUI Manager also has it: search DMXAPI. Restart once to get the nodes, then never again for key changes.
And the standing context, because it applies to every node in this pack: an API wrapper holds a credential and makes outbound calls as its day job, which is exactly the profile a malicious one would wear. This category has already been weaponized once in the ComfyUI_LLMVISION incident. The habit that costs nothing: know where your key lives, and don't share files that carry it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | 寫入 .env 的 DMXAPI_KEY。畫面上會被前端遮蔽成密碼欄位,但仍會存進 workflow JSON/輸出圖片 metadata;請勿分享含有真實 Key 的 workflow 檔或圖片。 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| REPORT | STRING | — |