Overview
Grok Imagine 2 is xAI’s latest, second-generation image model — a full generational step up from the first release in both parameter control and editing: aspect ratio and resolution genuinely take effect, the 2K tier is available, a single call returns up to 10 images, and reference editing truly preserves the source image. APIYI offers two variants:grok-imagine-image (standard) and grok-imagine-image-quality (high quality). Both share the same endpoints and parameters — they differ only in output fidelity and price.
2. The product is named Grok Imagine 2, but the model names you call are grok-imagine-image and grok-imagine-image-quality — do not write grok-imagine-2-image, which returns 503 because no such model exists.Text-to-Image API
Image Editing API
Why Grok Imagine 2 on APIYI
OpenAI-compatible format
/v1/images/generations and /v1/images/edits endpoints. Request bodies and response fields match the OpenAI Images API, so the official OpenAI SDK works directly — zero migration effort.No concurrency caps
Flat pricing, predictable cost
Global access, no barriers
api.apiyi.com.Full model ecosystem
Professional support
Key Features
Two resolution tiers
1k at roughly 1 megapixel, 2k at 4.2-4.5 megapixels (2816x1584 at 16:9) — same price5 aspect ratios
1:1 / 16:9 / 9:16 / 4:3 / 3:4, with measured pixel dimensions matching exactlyUp to 10 per call
n accepts 1-10, returning multiple images in one request — ideal for batch selectionFast generation
True reference editing
Multi-image fusion
Two response formats
url direct links or b64_json raw base64, supported on both endpointsOpenAI SDK ready
client.images.generate() and client.images.edit() work out of the box — no manual HTTP plumbingPricing
- Resolution-independent:
1kand2kcost the same — 2K carries no surcharge. - Per image:
n=4bills as 4 images, regardless of prompt length. - Editing costs the same as text-to-image —
/v1/images/editscarries no premium. - The
usageblock cannot be used for reconciliation:prompt_tokensis always1000 x n, a placeholder. Use the Console billing records instead.
Group Setup
Grok Imagine 2 runs in theDefault Group (1.0x rate), matching the pricing table above. No Group switching is required.
Recommended Token billing model: Pay-as-you-go Priority. This family is billed per request, and both Pay-as-you-go Priority and Pay-per-request route correctly — choosing Pay-as-you-go Priority lets a single Token also cover token-billed models elsewhere on the platform.
Technical Specifications
Endpoints
Migrating from GPT-Image-2
If you already integrate GPT-Image-2, the endpoints and calling convention are identical (/v1/images/generations + /v1/images/edits, OpenAI SDK compatible) — but the parameter system is different, so simply swapping the model name will not work. Here is what must change.
Parameter mapping
The three easiest mistakes
Before and after
Key Parameters
aspect_ratio and resolution (output size)
Together these determine the actual output pixels. Measured values match the request exactly:
aspect_ratio (e.g. 5:7, 21:9) or resolution (e.g. 1K, 1024x1024) silently fall back to the default and still return an image. An invalid response_format likewise falls back to url. So when output does not match expectations, check your parameter spelling first.The one exception is resolution: "4k", which returns 503 model_service_unavailable. That means the tier is unsupported, not that the channel is down — switch back to 1k / 2k.n (images per call)
Accepts 1-10; the returned data array length equals n, and each image is billed. 0 is silently treated as 1; 11 or above returns 400.
Best Practices
Decide up front: generation or editing?
/v1/images/generations. Any reference image, even for a one-pixel tweak → /v1/images/edits. Picking the wrong endpoint produces no error, just an unexpected image.Set the client timeout to 360 seconds
Control composition with aspect_ratio, not the prompt
aspect_ratio: "16:9" is far more reliable than asking for a “landscape composition” in the prompt.Choose the resolution tier by bandwidth
Say «keep everything else unchanged» when editing
Refer to images explicitly when fusing
image[] upload order is what “image 1 / image 2 / image 3” means. Writing “put the subject from image 1 into the scene from image 2” is far more reliable than letting the model guess.Do not rely on seed for reproducibility
seed; the same prompt yields different results across calls. Persist the images you want to keep rather than expecting to regenerate them.Just go concurrent for batch work
Error Codes and Retries
400 and 415 are deterministic — retrying is pointless, so alert instead. Only 429 and network-layer timeouts are worth retrying, with exponential backoff and at most 3 attempts.Note that 400 invalid_request covers both “bad parameter” and “content blocked”, and the response body cannot distinguish them. A practical heuristic is latency: moderation blocks return in about 5-6 seconds — faster than a successful generation (~9s) — because the block happens before generation starts.FAQ
Why does sending JSON to /v1/images/edits return 400, when the vendor docs show JSON?
Why does sending JSON to /v1/images/edits return 400, when the vendor docs show JSON?
multipart/form-data, while the upstream vendor documentation describes a JSON body with a public image URL. The two differ — follow this site’s documentation.The correct form is a file upload:Why do resolution / aspect_ratio have no effect on the editing endpoint?
Why do resolution / aspect_ratio have no effect on the editing endpoint?
resolution or aspect_ratio here raises no error but does nothing.To change the output size, crop or resize the reference image before uploading.Why is there no revised_prompt in the response?
Why is there no revised_prompt in the response?
revised_prompt, nor fields like respect_moderation or model. Each data[] entry contains either url or b64_json depending on response_format — never both.Do not assume these fields exist when parsing responses.Can I reconcile billing using the token counts in usage?
Can I reconcile billing using the token counts in usage?
usage.prompt_tokens is always 1000 x n regardless of actual prompt length — it is a placeholder.This family is billed per request at a flat rate per image. Use the APIYI Console billing records for actual charges.Why is 1K a JPEG while 2K is a PNG? The sizes differ a lot
Why is 1K a JPEG while 2K is a PNG? The sizes differ a lot
resolution: 1k returns JPEG (~220-300 KB) and resolution: 2k returns lossless PNG (~5-6 MB), roughly a 20x difference.The URL extension, the HTTP Content-Type and the actual bytes are consistent with each other, so you can branch safely on Content-Type.For bandwidth-sensitive scenarios (mobile, bulk transfer) prefer 1k — both tiers cost the same, so the decision is purely about quality.resolution: 4k returns 503 — is the channel down?
resolution: 4k returns 503 — is the channel down?
4k is not a supported tier for this family, and the gateway returns 503 model_service_unavailable. The code looks like an outage but is really a parameter problem, so retrying will not help — switch back to 1k or 2k.Only 1k and 2k are supported.Why do invalid parameters produce a wrong image instead of an error?
Why do invalid parameters produce a wrong image instead of an error?
aspect_ratio (e.g. 5:7), resolution (e.g. 1K, 1024x1024) and response_format (e.g. base64) all silently fall back to defaults and still return an image rather than a 400.So when the output does not match expectations, check the parameter spelling first — in particular, resolution values are lowercase 1k / 2k.How many images can one call produce?
How many images can one call produce?
n accepts 1-10, and the returned data array length equals n. Each image is billed.0 is silently treated as 1; 11 or above returns 400 invalid_request.Is seed-based reproducibility supported?
Is seed-based reproducibility supported?
seed raises no error but has no effect — the same prompt with the same seed returns different images across calls.Persist any image you need to reuse rather than trying to regenerate it.Can I call this with the official OpenAI SDK?
Can I call this with the official OpenAI SDK?
base_url at https://api.apiyi.com/v1:aspect_ratio and resolution are not standard OpenAI SDK fields, so pass them via extra_body.Are there concurrency limits? Will batch generation get throttled?
Are there concurrency limits? Will batch generation get throttled?
timeout: image APIs are synchronous, so set the client timeout to 360 seconds to avoid cutting off requests that are still processing normally — and still being billed.How does content moderation work, and how do I detect a block?
How does content moderation work, and how do I detect a block?
400 invalid_request using exactly the same error code and message as a parameter error, so the response body cannot distinguish them.A practical heuristic is latency: moderation blocks return in about 5-6 seconds (the block precedes generation), while a successful image takes about 9 seconds. Moderation outcomes also carry some randomness, so borderline content may not behave identically across retries — do not draw conclusions from a single attempt.If parameters are verified correct and 400s persist, the prompt most likely triggered moderation; revise the wording.Can I generate images through /v1/chat/completions?
Can I generate images through /v1/chat/completions?
content is a markdown image link:/v1/images/generations and /v1/images/edits) — richer parameters, a more stable response shape, and consistent with this documentation.Related Documentation
- Grok Imagine 2 Text-to-Image API - endpoint reference with Playground
- Grok Imagine 2 Image Editing API - reference editing and multi-image fusion
- Grok Model Guide - xAI text models
- Image API Best Practices - timeouts, disconnects, compression
- API Manual
- Recharge Promotions