Nodes/comfyui-PD_comfy-api-node/PD-grok-text to image
ComfyUI Node

PD-grok-text to image

The api_key field is a Comfy key, not an xAI key

By 7BEII·Created 12 months ago·Updated 22 days ago· 2
PD-grok-text to image
    • image
    • show_price
    ◄api_key►
    ◄prompt►
    ◄modelgrok-imagine-image-2.0►
    ◄aspect_ratio1:1►
    ◄resolution1K►
    ◄qualitymedium►
    ◄number_of_images1►
    ◄seed0►

    What it is

    PD-grok-text to image (class PDGrokImageAPIKey) puts xAI's Grok Imagine image model in your graph as a plain text-to-image node. Text in, images out - no image input at all, which is worth stating up front because the same pack also ships a Grok edit node and the two look nearly identical on the canvas.

    Why bother: Grok is the least restrictive mainstream image service out there - where Google and OpenAI refuse, it mostly doesn't, which is its whole reputation. It's also cheap (the node's own table works out to two to eight cents an image) and fast, which is why it earns a slot as the one step in your workflow you can't run at home. There are no weights to download; calling it is the only door.

    The gotcha you hit in the first thirty seconds: the required api_key field's own placeholder reads "Your ComfyUI API Key", and it means it. This node POSTs to https://api.comfy.org/proxy/xai/v1/images/generations with an X-API-KEY header - Comfy's proxy, Comfy's credits. An xAI console key will bounce. If you wanted to bill xAI directly at xAI's rates, this is the wrong pack: it mirrors Comfy's official Grok node rather than escaping it.

    How it works

    It builds a JSON body - model, prompt, aspect_ratio, n, seed, response_format: url, a lowercased resolution, and quality only when the model is one that accepts it - and fires one POST with a 600-second ceiling. The wait is interruptible: the node polls the request every 0.2 seconds and bails properly when you hit cancel, showing elapsed seconds in the status line. Results come back as URLs, get downloaded with a 120-second limit each, and are concatenated into a single IMAGE batch.

    Inputs and outputs

    Required: api_key, prompt, model, aspect_ratio, resolution, quality, number_of_images, seed.

    model is four choices: grok-imagine-image-2.0 (the default, and the only one that honours quality), grok-imagine-image-quality, grok-imagine-image-pro, and grok-imagine-image. quality is a trap of a name - your options are medium and low, so the dial only goes down, and if you picked any model other than grok-imagine-image-2.0 the node silently drops the value from the request.

    aspect_ratio gives you 13 options with 1:1 as the default, including the tall and wide phone shapes (9:19.5, 19.5:9, 9:20, 20:9) that are genuinely handy for wallpaper-ish or story-format output. resolution is 1K or 2K; on the two models where it changes the price, 2K costs about two cents more per image. number_of_images goes 1–10 and comes back as one batch, so SaveImage will write them all with its batch numbering. seed does get sent in the request body - unlike the Gemini node in this pack, whose seed widget goes nowhere - but treat it as a nudge rather than a promise; it's a closed model.

    Outputs are image (IMAGE) and show_price (STRING). show_price is the sleeper feature: it reads actual usage out of the response (the cost_in_usd_ticks field or the X-Comfy-Credits-Used header) and prints real USD, RMB, and credits used. When the response doesn't say, it falls back to the node's own estimate table - around $0.06 an image for the default model at 1K/medium, $0.05 for the quality model, $0.07 for pro, $0.02 for the base one.

    Install

    ComfyUI Manager → search comfyui-PD_comfy-api-node, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/comfyui-PD_comfy-api-node.git
    pip install -r comfyui-PD_comfy-api-node/requirements.txt
    

    Restart and you'll find it in PD_Tools/Image_Generation. You're getting around twenty nodes, not one - Gemini image models, GPT Image, Krea 2, Seedream, Grok video, an Aliyun face swap, plus Auth Token variants of the lot. The pip line installs two Alibaba Cloud SDKs for that face-swap node only; nothing here needs them, so you can skip it. Unlike the Gemini node in this pack, this one wraps no ComfyUI core classes, so it loads on basically any recent build. Key from comfy.org/api-keys.

    Common issues

    Black image, no error, no exception. This node doesn't raise on failure. An empty key, an empty prompt, a non-200 from the API, a 600-second timeout, and a dropped connection all return empty_image() plus an error string on the show_price output. If you left that output unconnected - the default when you drag the node in - you get a black frame and no explanation at all. Wire it into a text-display node, or watch the status line and console.

    A black image costs nothing. With a blank key the node returns the placeholder before touching the network, so a black result doesn't mean you were billed.

    Ten images, one fails to download, you get none. There's no partial-return path; the node only returns images it actually decoded.

    Refusals come from xAI, not the node. Moderation lives on the service side, behind the proxy. Nothing in a custom node can loosen it - no weights, nothing to patch.

    Your key ends up in the workflow file. api_key is a plain string widget, so it's stored in the workflow JSON and, with it, in the metadata of any PNG you save and share. Treat the workflow file as a secret.

    CategoryPD_Tools/Image_Generation

    Inputs (8)

    NameTypeDefaultDescription
    api_keySTRING—
    promptSTRING—
    modelCOMBOgrok-imagine-image-2.04 options: grok-imagine-image-2.0, grok-imagine-image-quality, grok-imagine-image-pro, grok-imagine-image
    aspect_ratioCOMBO1:113 options: 1:1, 2:3, 3:2, 3:4, 4:3, 9:16, +7
    resolutionCOMBO1K2 options: 1K, 2K
    qualityCOMBOmedium2 options: medium, low
    number_of_imagesINT11–10—
    seedINT00–2147483647—

    Outputs (2)

    NameTypeDescription
    imageIMAGE—
    show_priceSTRING—