ComfyUI Node

Grok Image API

XAI's image model, both generation and edit

By Aryan185·Created about a year ago·Updated about a month ago· 14
Grok Image API
  • image_1
  • image_2
  • image_3
  • image_4
  • image_5
  • image
prompt
modelgrok-imagine-image
aspect_ratio1:1
resolution1k
n1
seed0
api_key

xAI's Grok image model is the one people remember for being the least restrictive mainstream generator - "Spicy Mode" and all, per the community history - and this node puts both its generation and edit endpoints behind a ComfyUI node. It's a direct REST call to xAI's API, no SDK wrapper, so it's thin and honest: prompt in, image out, billed per image on your xAI account.

Honest framing before you get excited: the API is a different surface from the X app. The relaxed filter reputation comes mostly from the consumer "Spicy Mode" product; via the grok-imagine API you're still subject to xAI's content policies and they can tighten them without notice. Don't build a workflow assuming the API is lawless.

How it works

The node decides the endpoint from how many images you attach. Zero images → POST to the generations endpoint with prompt, aspect ratio, resolution, and count. One image → the edits endpoint with a single reference (and it prints a note that aspect_ratio is ignored, since single-image edits follow the input's aspect). Two or more images → the edits endpoint with a multi-image array, where aspect ratio does apply. Results come back as image URLs or base64, which the node fetches/decodes into a single batched IMAGE.

The inputs that matter

  • prompt - required, and the node throws a clear error if it's empty.
  • model - grok-imagine-image (the current model) or grok-imagine-image-beta (the older beta tag). Default is the stable one.
  • aspect_ratio - a long list: auto, 1:1, 2:3, 3:2, 3:4, 4:3, 9:16, 16:9, and the phone-tall 9:19.5 / 9:20 / 20:9 family. The tooltip is worth reading: it applies to generation and multi-image edits, and is ignored for single-image edits (output follows the input).
  • resolution - 1k or 2k. 2k is the quality jump and the cost jump.
  • n - 1–10 images per call.
  • seed - here's the fun one: the tooltip says plainly it's "used to trigger re-runs in ComfyUI; not sent to the API." So it does not give you reproducible results - it just makes ComfyUI notice a change. If you need a true reproduction, save what you got.
  • api_key - an xAI API key (console.x.ai), pasted in or referenced as a .env variable name (XAI_API_KEY).

Optional image_1..image_5 - plug in references to flip the node into edit mode, from single-image edit to multi-image edit.

The output

image - a single batched IMAGE output (all n results in one batch). Wire to preview/save.

Installing it

Standard pack install, it's one of ~20 nodes in Aryan185/ComfyUI-ExternalAPI-Helpers:

cd ComfyUI/custom_nodes
git clone https://github.com/Aryan185/ComfyUI-ExternalAPI-Helpers.git
cd ComfyUI-ExternalAPI-Helpers
pip install -r requirements.txt

Restart ComfyUI; look under image/generation. No special dependency beyond what ComfyUI already has (requests). Grab an xAI API key, paste it in the field or set XAI_API_KEY in .env (copy .env.example - this pack's example file includes XAI_API_KEY, even though the README's list of keys forgets to mention xAI).

Where people get burned

The seed-reproducibility thing trips everyone once - you change nothing, re-run, and get a different image because the seed genuinely isn't sent to the API. Also, this node isn't covered in the pack README's feature list at all (it's in the code and the acknowledgements, but not the guide), so a lot of people don't find it - search "Grok Image API" in the node menu, don't go hunting by the README. And remember the API filter story above: don't treat the X-app's reputation as a promise about the API endpoint.

If you want xAI image generation and editing inside ComfyUI without writing the REST calls yourself, this is the node. If you need guaranteed reproducibility, look elsewhere.

Categoryimage/generation

Inputs (12)

NameTypeDefaultDescription
promptSTRING
modelCOMBOgrok-imagine-image2 options: grok-imagine-image, grok-imagine-image-beta
aspect_ratioCOMBO1:1Applies to generation and multi-image edits. Ignored for single-image edits (output follows input aspect ratio).
resolutionCOMBO1k2 options: 1k, 2k
nINT11–10Number of images to generate or edited variations to produce
seedINT00–2147483647Used to trigger re-runs in ComfyUI; not sent to the API
api_keySTRINGDirectly put xAI API key or .env variable name (XAI_API_KEY)
image_1optIMAGE
image_2optIMAGE
image_3optIMAGE
image_4optIMAGE
image_5optIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE