Grok Image Gen (PMS)
Cloud images from xAI, with a built-in anti-crash net
- image_ref
- imagen
- url_o_error
This is xAI's image model, grok-imagine-image-quality, called from the ComfyUI canvas as a plain REST request. If you're here because you want Grok's particular look - the model is architecturally different from local diffusion (an autoregressive mixture-of-experts predicting image tokens, which is why it renders faces and text as well as it does) - this is the node. You type a prompt, optionally feed it a reference image for edits, and get a tensor back.
The honest framing before you wire anything: the pack is free, the API is not. Every image costs xAI credits, and you need an XAI_API_KEY. On the release thread the community put it bluntly - "your workflow is free and open source, Grok is not" - so budget accordingly. The flip side: Grok's moderation is among the lightest of the big closed image models, which is exactly why some people reach for it.
How it works
The node POSTs to https://api.x.ai/v1/images/generations with response_format: b64_json and decodes the returned base64 straight into a ComfyUI IMAGE tensor. With image_ref connected, it switches to the /images/edits endpoint for image-to-image - you can restyle or modify an existing image instead of generating from scratch.
The one genuinely thoughtful touch: this node has the pack's "anti-crash" system. If xAI blocks your prompt, you hit a rate limit, or the key is bad, it doesn't kill your workflow - it returns a solid red 512×512 tensor with the error text riding along in the string output. The graph keeps running; you see red and know what happened. Annoying when it happens mid-batch, but a lot friendlier than a hard exception.
The inputs that matter
- prompt - the image description. Multiline, and worth being specific: Grok follows long structured prompts well.
- aspect_ratio - 1:1, 2:3, or 3:2. Modest list compared to the Gemini nodes.
- n - 1 to 4 images per call. Batch of 4 means 4x the credits; the output tensor will have that many frames.
- image_ref - optional IMAGE for the edits endpoint.
- api_key - leave empty, use
.env.
Outputs
imagen - the IMAGE tensor (batch if n > 1) - and url_o_error, a STRING that's a real image URL on success or the error message on failure. Wire imagen to Preview/Save and check the string when something looks off.
Installing it
ComfyUI Manager → search "COMFYUI_PROMPTMODELS" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/cdanielp/COMFYUI_PROMPTMODELS
Then create a .env in the pack folder with XAI_API_KEY=xai-... and restart. ComfyUI >= 0.26.0, Python >= 3.10, dependencies are requests and Pillow only.
The traps
Same key warning as every node in this pack: don't paste XAI_API_KEY into the api_key widget - it lands in your workflow JSON and in PNG metadata when you save. .env or an environment variable, field left blank.
And keep the red-tensor behavior in mind: a red output image is not a bug, it's the safety net doing its job. Read the url_o_error output for the actual cause - usually a blocked prompt or an exhausted key - rather than tearing the node apart.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | A futuristic city in cyberpunk style | — |
| aspect_ratio | COMBO | 1:1 | 3 options: 1:1, 2:3, 3:2 |
| n | INT | 11–4 | Numero de imagenes a generar (1-4). |
| image_refopt | IMAGE | Imagen de referencia para edicion (image-to-image). | |
| api_keyopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| imagen | IMAGE | — |
| url_o_error | STRING | — |