Skip to main content
API Reference for xai/grok-imagine-image, served by Comfy Router from xAI.

Quick start

Create a key in your Comfy workspace and export it as COMFY_API_KEY. The Python and TypeScript snippets use the Comfy SDKs (pip install comfy-sdk, npm install @comfyorg/sdk); the cURL snippet is the same call over raw HTTP. Model ID: xai/grok-imagine-image Endpoint: POST https://api.comfy.org/v2/models/xai/grok-imagine-image

Schema

Input

string
default:"\"auto\""
Aspect ratio of the generated image. Defaults to auto for automatically selecting the best ratio for the prompt.Possible values: 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1, auto
string
default:"\"grok-imagine-image\""
Model to be used. Supported: grok-imagine-image (default), grok-imagine-image-pro, grok-imagine-image-quality, grok-imagine-image-2.0. Deprecated -beta ids are aliased to their GA model.
integer
default:"1"
Number of images to be generatedRange: 1 to 10
string
required
Prompt for image generation
string
Quality of the output image. For grok-imagine-image-2.0 this selects the price tier (low/medium; medium is the default); other models currently ignore it.Possible values: low, medium, high
string
default:"\"1k\""
Resolution of the generated image. Defaults to 1k.Possible values: 1k, 2k
string
default:"\"url\""
Response format to return the image in. Can be url or b64_json. Comfy Router (POST /v2/models/xai/{model}) coerces this to url on the outbound request because it serves image results as re-hosted URLs either way; this /proxy/ route honours it as written.Possible values: url, b64_json
string
Size of the image (not supported)
string
Style of the image (not supported)
string
A unique identifier representing your end-user, which can help xAI to monitor and detect abuse
Generated from the schema Router serves at GET /v2/models/xai/grok-imagine-image/openapi.json, the same document it validates a call against before the request reaches the provider.

Output

string
If the request was blocked by input moderation, contains the block reason
object[]
A list of generated image objects
string
A base64-encoded string representation of the generated image in jpeg encoding (if response_format is b64_json)
string
The MIME type of the generated image (e.g. image/png, image/jpeg, image/webp).
string
A url to the generated image (if response_format is url)
object
Usage information for the image generation request
integer
Accurate cost of this request in USD ticks (10,000,000,000 ticks = 1 USD)

Examples

Input

Output

Before you ship

The SDKs create an Idempotency-Key and reuse it for automatic retries. For manual retries, reuse the original key. Router can hold the connection for up to 10 minutes. When a request fails, Router sends an X-Comfy-Error-Type response header explaining why. A 422 means Router rejected the input before calling the provider. Download generated assets promptly because result URLs can expire.

Headers

Authentication, idempotency, request IDs, error buckets, retry pacing, spend limits.

Using the Router API

Model discovery, validation errors, retries, and billing.

Limitations

What Router does not do today, and what to use instead.