从配置文件获取数据
Type your API key once, use it everywhere
- value
Every AI node in this pack asks for an api_key, and pasting the same long key into a dozen nodes is exactly the kind of repetition ComfyUI was built to eliminate. This node is the pack's answer: it reads a key-value from the pack's config.json file and outputs it as a STRING, which you then wire into every node's api_key (or OSS_ACCESS_KEY, or whatever) input. Change the key once in the file, and every node in every workflow updates. That's the pattern the README recommends as "方式二" (method two) for entering your API key - you should probably be using it.
The mechanics are plain: on load, the node parses ./custom_nodes/ComfyUI-My-Nodes/config.json and builds its key dropdown from whatever keys exist in the file. Pick a key, and the value output returns the corresponding string. The default config.json ships with api_key, base_url, OSS_ACCESS_KEY, OSS_SECRET_KEY, and bucket - but the README explicitly says you can add your own keys. It's a general-purpose settings store, not just an API-key reader.
The one input, key, is a dropdown that populates from the file at load time. If the file is missing or malformed, the dropdown shows [ERROR] Load config and the node outputs Configuration error detected - that's the diagnostic, and it's trying to tell you something specific.
Setup, from the README:
- Open
ComfyUI/custom_nodes/ComfyUI-My-Nodes/config.jsonin a text editor. - Replace
YourApiKeyinside the quotes with your real DashScope key (and fill in OSS keys if you use the OSS node). - Save, keep the JSON valid - English punctuation only, and don't lose the commas between entries.
- Restart ComfyUI, or refresh node definitions and toggle the node's output (the README's shortcut is
r).
Gotchas. The [ERROR] Load config dropdown is almost always a JSON problem: a Chinese full-width comma/colon (,:) instead of ASCII, a missing comma, or a trailing comma after the last entry. The README calls this out explicitly. One more subtlety: the dropdown only refreshes when the node loads, so editing the file while ComfyUI is running won't update the key list until you refresh. And a heads-up for the security-minded - this is a plaintext file on disk with your API key in it. It's how the pack works, but keep the file out of any repo you push and treat it like a credential, which is exactly what it is.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| key | COMBO | [ERROR] Load config | 1 options: [ERROR] Load config |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | STRING | — |