{"openapi":"3.0.2","info":{"title":"xai/grok-imagine-image","description":"The request body Comfy Router accepts for the model \"xai/grok-imagine-image\", and the response body it returns. The INPUT schema is the same schema the server validates a call against before it reaches the provider, so what is published and what is enforced cannot differ. `x-comfy-router-input-modalities` records the media kinds the model is documented to accept; the request schema is shared across sibling models and may admit media kinds this model ignores. The OUTPUT schema describes the provider's native result document exactly as Router returns it: Router does not validate, narrow or re-envelope the response, so the output schema is descriptive rather than enforced, and Comfy owns no output shape of its own.","version":"4c934bf8c596"},"paths":{"/v2/models/xai/grok-imagine-image":{"post":{"operationId":"runRouterModel","summary":"Run xai/grok-imagine-image synchronously.","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/XAIImageGenerationRequest"},{"properties":{"image":{"allOf":[{"$ref":"#/components/schemas/XAIImageObject"}],"nullable":true},"images":{"description":"List of input images for multi-reference editing. Mutually exclusive with image. When multiple images are provided, refer to them as \u003cIMAGE_0\u003e, \u003cIMAGE_1\u003e, etc. in the prompt.","items":{"$ref":"#/components/schemas/XAIImageObject"},"nullable":true,"type":"array"},"mask":{"allOf":[{"$ref":"#/components/schemas/XAIImageObject"}],"nullable":true}},"type":"object"}],"description":"Request body for an xAI Grok Imagine image call on Comfy Router. OMIT `image` and `images` for text-to-image generation; INCLUDE `image` (one source image) or `images` (several, referred to as \u003cIMAGE_0\u003e, \u003cIMAGE_1\u003e, ... in the prompt), optionally with `mask`, to edit. `image` and `images` are mutually exclusive, and `mask` is refused without one of them. Image editing may not be enabled in every environment yet; where it is not, a body carrying any of the three fields is refused before anything is billed. `model` is filled from the request path.","example":{"n":1,"prompt":"A single red maple leaf on a plain white background."}}}}},"responses":{"200":{"description":"OK - the model's native JSON output, returned unchanged; the schema describes the provider's terminal result document as Router returns it.","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/XAIImageGenerationResponse"}],"description":"Comfy Router output schema for the xAI Grok Imagine image models: the `POST /v1/images/generations` document xAI returns, forwarded unchanged EXCEPT for the re-hosted `data[]` entries described below - every other field is xAI's own. This family is DIRECT-RETURN — `routerresult/classification.go` records `{provider: xai, endpoint: /v1/images/generations}` as `ReturnModeDirect` with no poll route — so the body a caller receives is the finished generation on the original call rather than a task handle.\nThe generated images are in `data`, and on THIS surface an entry is addressed by its `url`. Router coerces the outbound `response_format` to `url` for this family and re-hosts every image it can fetch onto Comfy storage, replacing xAI's URL with a signed Comfy one and clearing `b64_json`, so a request that asked for `b64_json` is answered exactly as a `url` request is. `mime_type` names the encoding. The `/proxy/` image routes coerce `response_format` to `url` the same way, so they do not preserve a `b64_json` request either.\nDurability is per entry, not per response: an image whose re-host fails keeps xAI's own answer — under the coerced `response_format` that is xAI's short-lived URL — rather than a Comfy one, and the rest of the response is unaffected. So one `data` array can mix durable Comfy URLs with expiring partner ones, and a caller that stores or replays this document should not assume every URL in it outlives the call. Such a response IS the answer to the call that produced it, returned and charged exactly as a fully re-hosted one is — but it is replayable only BRIEFLY. A prompt retry carrying the same `Idempotency-Key` — within a few minutes of the original, which is where a connection dropped mid-call puts an SDK's automatic re-send — is answered from the record exactly as any other replay is, because the partner's own link is still alive that soon. A retry after that is answered `409 invalid_input` rather than handed a document whose links may already have expired. The key is consumed either way, so no retry ever re-runs or re-charges; once the replay window has passed, use a new key to run the generation again. A response whose every entry re-hosted cleanly replays normally for the full 24 hours, because a Comfy signed URL is minted with the same lifetime the record is kept for.\n`block_reason` and `usage` are populated WITHOUT any `data` when xAI's input moderation refuses the request, so a caller must key completion off the generated asset rather than off a `200` alone. Key it off an ENTRY of `data` carrying a `url` or a `b64_json`, not off `data` itself: a present-but-asset-less entry is still a billed call that produced nothing, and the container test cannot tell the two apart. That is what the nightly SDK case for this family asserts — the leaves `data[].url` and `data[].b64_json` rather than the `data` container (`testing/e2e/router_sdk/cases.d/xai_image.json`).","example":{"data":[{"mime_type":"image/jpeg","url":"https://example.invalid/xai/grok-imagine-image/generated.jpg"},{"mime_type":"image/jpeg","url":"https://example.invalid/xai/grok-imagine-image/generated-2.jpg"}],"usage":{"cost_in_usd_ticks":200000000}}}}}}}}}},"components":{"schemas":{"XAIGeneratedImage":{"description":"A generated image from xAI","properties":{"b64_json":{"description":"A base64-encoded string representation of the generated image in jpeg encoding (if response_format is b64_json)","type":"string"},"mime_type":{"description":"The MIME type of the generated image (e.g. image/png, image/jpeg, image/webp).","type":"string"},"url":{"description":"A url to the generated image (if response_format is url)","type":"string"}},"type":"object"},"XAIImageGenerationRequest":{"description":"Request body for xAI Grok Imagine image generation","properties":{"aspect_ratio":{"default":"auto","description":"Aspect ratio of the generated image. Defaults to auto for automatically selecting the best ratio for the prompt.","enum":["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"],"type":"string"},"model":{"default":"grok-imagine-image","description":"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.","nullable":true,"type":"string"},"n":{"default":1,"description":"Number of images to be generated","maximum":10,"minimum":1,"type":"integer"},"prompt":{"description":"Prompt for image generation","type":"string"},"quality":{"description":"Quality of the output image. For grok-imagine-image-2.0 this selects the price tier: low, medium, or auto (xAI's default when omitted; auto serves low for generation and medium for edits). Other models ignore it.","enum":["low","medium","high","auto"],"type":"string"},"resolution":{"default":"1k","description":"Resolution of the generated image. Defaults to 1k.","enum":["1k","2k"],"type":"string"},"response_format":{"default":"url","description":"Response format to return the image in. Can be url or b64_json. Comfy coerces this to `url` on the outbound request — on the Comfy Router dispatch (`POST /v2/models/xai/{model}`) and on this `/proxy/` route too — because image results are served as re-hosted URLs either way. A value IN the enum is therefore accepted and ignored; send `url` or `b64_json` or omit the field, and the answer is the same. A value OUTSIDE the enum — excluding the UNSET spellings each surface recognises, described next — is REJECTED rather than coerced on BOTH surfaces, and only the shape of the refusal differs: this `/proxy/` route answers a `400` at ingress, and the `POST /v2/models/xai/{model}` Router dispatch answers the per-field `422` it owes the enum published here, before any partner call is made. The two surfaces differ on what counts as UNSET. On this `/proxy/` route an omitted field, an explicit `null` and `\"\"` all mean unset and are coerced like any accepted value. The Router dispatch enforces the enum exactly as published, so `null` and `\"\"` are non-members there like any other: OMIT the field to leave it unset on that surface.","enum":["url","b64_json"],"type":"string"},"size":{"description":"Size of the image (not supported)","type":"string"},"style":{"description":"Style of the image (not supported)","type":"string"},"user":{"description":"A unique identifier representing your end-user, which can help xAI to monitor and detect abuse","type":"string"}},"required":["prompt"],"type":"object"},"XAIImageGenerationResponse":{"description":"Response from xAI image generation or editing","properties":{"block_reason":{"description":"If the request was blocked by input moderation, contains the block reason","type":"string"},"data":{"description":"A list of generated image objects","items":{"$ref":"#/components/schemas/XAIGeneratedImage"},"type":"array"},"usage":{"$ref":"#/components/schemas/XAIImageUsage"}},"type":"object"},"XAIImageObject":{"description":"Input image object for xAI endpoints","properties":{"type":{"description":"Type of the image input","enum":["image_url"],"type":"string"},"url":{"description":"URL of the input image (public URL or base64-encoded data URI)","type":"string"}},"required":["url"],"type":"object"},"XAIImageUsage":{"description":"Usage information for the image generation request","properties":{"cost_in_usd_ticks":{"description":"Accurate cost of this request in USD ticks (10,000,000,000 ticks = 1 USD)","type":"integer"}},"type":"object"}},"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}},"x-comfy-router-model-id":"xai/grok-imagine-image","x-comfy-input-schema-authored":true,"x-comfy-output-schema-authored":true,"x-comfy-router-input-modalities":["image","text"],"x-comfy-router-output-modalities":["image"]}
