ZhipuaiApi_Txt
GLM-4 chat, translation, or CogView-3 text-to-image — one Swiss-army node
- text
- image
This is the pack's flagship cloud node - the one the whole thing is named after. ZhipuaiApi_Txt calls Zhipu AI's (Z.ai's) hosted API and does three genuinely different jobs depending on the model_name you pick: plain GLM-4 chat, dirt-cheap GLM-3-Turbo chat, or CogView-3 text-to-image, which returns an actual image tensor into your graph. It's the "ask an LLM to write/enhance/translate my prompt, right inside ComfyUI" node, and its string output wires straight into a CLIP text encode. That whole "LLM writes the prompt for the image model" pattern everyone does now? This was a 2024 way of doing it.
How it works
It skips Zhipu's official Python SDK entirely - the author found the SDK didn't play nice inside ComfyUI nodes, so this is a raw HTTP call. Your API key is signed into a short-lived JWT bearer token, then POSTed to https://open.bigmodel.cn/api/paas/v4/chat/completions (or the /images/generations endpoint for CogView-3). For chat, it prepends an instruction to your prompt based on the translation/language settings, then returns the model's reply. For CogView-3, it downloads the generated image URL and converts it to an IMAGE tensor.
The inputs that matter
- model_name - the big switch:
glm-4(best, ¥0.1/千tokens),glm-3-turbo(the author's recommendation for cheap - ¥0.005/千tokens), orcogview-3(image generation). - prompt - your text. Chinese, English, anything; the default is "30 words describe a girl walking on the Moon."
- max_tokens (default 1024) and temperature (default 0.95) - output length and randomness, standard stuff.
- translate_to - the killer feature:
english/chinese/russian/japanesemakes the node translate your prompt and return only the translation. Feed that into a CLIP text encode and you've got a built-in prompt translator for models that only understand English tags. - output_language -
englishororiginal_language, for chat-mode replies.
Outputs: text (STRING - the reply, or the image URL in CogView mode) and image (IMAGE - only populated when cogview-3 generates). When you use CogView-3, that image tensor goes straight to a preview or a Save Image.
Installing it (and the key)
cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_ChatGLM_API
Restart, then the cloud nodes need a key. Grab one at the Zhipu console (open.bigmodel.cn - new accounts get free starter tokens), then edit the pack's config.json:
{
"Zpai_API_KEY": "your key"
}
It lives at ComfyUI/custom_nodes/ComfyUI_ChatGLM_API/config.json, and the pack auto-creates it with a placeholder the first time it loads.
Common issues
- "API key is required" - config.json was never filled in, or the placeholder is still there.
- NSFW gets you banned. The README is blunt: Zhipu operates under Chinese law, filters explicit content, and uploading NSFW can get your account banned. Don't test this.
- Glacial first call - the README notes network auth can lag; requests time out if your connection to bigmodel.cn is slow.
- If
importfails for the whole pack,pip install PyJWT opencv-pythoncovers the two dependencies the requirements file forgot.
It's the most useful node of the six if you just want an LLM in your graph without hosting one - pick your model, paste a prompt, wire the string into your conditioning.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | 30 words describe a girl walking on the Moon. | — |
| model_name | COMBO | 3 options: glm-4, glm-3-turbo, cogview-3 | |
| max_tokens | INT | 1024128–8192 | — |
| temperature | FLOAT | 0.950.01–0.99 | — |
| output_language | COMBO | 2 options: english, original_language | |
| translate_to | COMBO | 5 options: none, english, chinese, russian, japanese |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| image | IMAGE | — |