Grok Image API
Grok image generation inside your ComfyUI graph — API key required, no GPU needed
- images
- config_options
- proxy_options
- IMAGE
- STRING
Want xAI's Grok to be the model at the end of your ComfyUI prompt instead of something you tab over to X for? That's the entire job of Grok Image API (YCYY_Grok_Image_API). It's an API wrapper, not a local model: you type a prompt into a ComfyUI text box, the node sends it to xAI's cloud, and a finished image tensor lands back in your graph ready to feed an upscaler or a mask node. No model download, no VRAM, no diffusion checkpoint to babysit.
It ships in the ycyy/ComfyUI-YCYY-API pack ("Freely call APIs in ComfyUI", which wraps Gemini, OpenAI, Ollama and ModelScope the same way). Reaching for it makes sense in two situations: you want Grok's particular look (famously strong on photorealistic people and the least restrictive of the big closed image services) and it has no open weights, so the API is the only door; or you have a workflow but not the GPU for it. The catch is standard for cloud nodes - per-image cost, prompts leaving your machine, and a content filter you can't strip.
How it works
Under the hood it's a thin HTTP client. Your key and endpoint live in the pack's config.json under a grok-image section (default base_url is https://api.x.ai/v1). The node posts an OpenAI-style request to <base_url>/images/generations - or /images/edits when you feed it reference images - and decodes the returned b64_json into a normal ComfyUI IMAGE tensor. You can point it at any OpenAI-compatible third-party interface, and it even strips a pasted /images/generations suffix if you include one by accident.
The inputs that matter
Most of these you can leave alone. The ones you'll actually touch:
- prompt (multiline) - what Grok renders or edits toward.
- images (optional) - feed one or more IMAGE tensors to switch from generate to edit mode. Grok takes up to 3 reference images, but only 1 if the model name contains "pro"; extras get silently dropped.
- model - a combo. It loads from your
config.jsonmodel list if present, otherwise defaults togrok-imagine-image-2.0,grok-imagine-image-quality,grok-imagine-image-pro,grok-imagine-image.
Everything else is taste: aspect_ratio (auto matches your input image in edit mode, else 1:1), resolution (1K or 2K), number_of_images (1–10, returned as a batch), and seed. Two subtle traps: quality (default/medium/low) is only honored by the 2.0 model - set it to default on the others or it just isn't sent - and seed has a "control after generate" toggle, so it rerolls every run unless you click the dice to lock it.
Outputs
Two of them. IMAGE is the result tensor - wire it anywhere you'd wire a local sampler's output. STRING is a JSON blob with the model, usage, and any revised_prompts, and it's where you should look when something went wrong (more below). The pack ships a Preview API Result node to render that string on the canvas.
Installing it
Clone the pack into your custom nodes, then copy the example config:
cd ComfyUI/custom_nodes
git clone https://github.com/ycyy/ComfyUI-YCYY-API
cd ComfyUI-YCYY-API
cp config.json.example config.json
Edit config.json, put your xAI key in the grok-image section, restart ComfyUI, and you'll find the node under YCYY/API/image. (You can also grab the pack through ComfyUI Manager by searching "ComfyUI-YCYY-API".) No extra pip install needed - the code only uses requests, torch and PIL, which a working ComfyUI already has. Getting an xAI key is the one real prerequisite.
Where people get burned
The biggest gotcha is baked into the design: this node mostly doesn't raise on a bad API call. If xAI returns an error, a non-200 status, or unparseable JSON, you get a black 512×512 placeholder out of the IMAGE port and the real explanation as JSON on the STRING output. Run the workflow, see black, and you'll assume it's broken - it's not, it's politely failing. Always peek at that STRING output (or route it into Preview API Result) to see status_code and the server's message.
Config problems do throw visibly: if you never created config.json, or your grok-image section is missing its api_key, the node fails with a clear error before it ever calls the network. And remember the content-policy reality: Grok is permissive for a closed service, but the API still refuses things the X app's "Spicy Mode" gets away with, and no node setting changes that.
One more thing: the node accepts the pack's Config Options and Proxy Options inputs, which override config.json per-workflow - handy for sharing a workflow without hardcoding a key, or routing through a proxy where xAI isn't reachable.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | The text prompt used to generate or edit the image | |
| api_name | COMBO | default | Select Grok API channel |
| model | COMBO | grok-imagine-image-2.0 | Grok image model |
| aspect_ratio | COMBO | auto | Aspect ratio of the output image. 'auto' matches input image in edit mode or generates 1:1. |
| resolution | COMBO | 1K | Resolution of the output image (1K or 2K). |
| quality | COMBO | medium | Quality level, supported only by the grok-imagine-image-2.0 model. |
| number_of_images | INT | 11–10 | Number of images to generate (1 to 10). |
| seed | INT | 00–18446744073709550000 | Random seed for generation. |
| imagesopt | IMAGE | Optional image(s) for image-to-image editing. Grok supports up to 3 reference images (1 for pro model). | |
| config_optionsopt | * | Optional configuration override from YCYY API Config Options | |
| proxy_optionsopt | * | Optional proxy configuration override from YCYY API Proxy Options |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| STRING | STRING | — |