grok-imagine-image-2.0 for new Grok Imagine integrations: generate images from text, or edit with one to three reference images. Billing counts each successfully returned image, so a request that returns several images is billed for each one.
What grok-imagine-image-2.0 supports
Choose a Grok Imagine model
The earlier models have their own prices: $0.025 per image for
grok-imagine-image and $0.045 per image for grok-imagine-image-quality. Like 2.0, they are billed per successfully returned image.
Existing workloads don’t need to migrate right away. Before switching, compare one image from each model using the same prompt, ratio, and resolution.
Before you call the API
1
Create and protect an API key
Create a key in the
default group in Token management and set Billing mode (计费模式) to Usage first (按量优先, recommended) or Per-call (按次计费). A Usage first key can call both per-call and usage-based models; a Per-call key calls only per-call models.Keep the key in a server-side environment variable, never in browser code, a public repository, or logs.2
Confirm model access and price
In Models and pricing, check that the key can use
grok-imagine-image-2.0 and review the current price.3
Set up your environment
Export the key and install the OpenAI Python SDK, which the Python examples use:
4
Start with one image
Use
n=1 first. Save the output, inspect its content and dimensions, and check the call record before you increase resolution, output count, or concurrency.Generate an image
This request creates one 2K, 16:9 image atmedium quality and writes the response to grok-generation.json:
data:
Save the result
The URL is temporary, so download the image right away. Save this script assave_images.py. It writes every image in a response to disk, whether the response contains url or b64_json, and picks the file extension from the image data:
save_images.py
Saved grok-lighthouse-1.jpg. Open the file and check the subject, text, and composition. To receive the image bytes in the response instead of a URL, set response_format to b64_json; the same script handles both.
Generate with the Python SDK
The OpenAI Python SDK doesn’t expose every Grok image option as a named parameter, so passaspect_ratio, resolution, and quality in extra_body. This example requests Base64 output and saves the decoded image:
Aspect ratio, resolution, and quality
grok-imagine-image-2.0 accepts these 15 fixed aspect ratios:
Omit
aspect_ratio to let the model choose, or pass a value when the layout must be predictable.
resolution="1k"is faster and suits drafts, thumbnails, and batch candidates.resolution="2k"produces larger files with longer latency, for final assets and cropping.quality="low"favors speed;quality="medium"favors detail.- Don’t send
quality="high"orresolution="4k".
quality to low or medium explicitly rather than relying on auto, so latency and output quality stay predictable.
Edit one reference image
Editing requires a file upload. Put a localproduct-photo.png in the current directory, then run:
Edit with two or three references
Repeat theimage[] field for each reference. This request supplies the subject, the scene, and the style as three separate files:
aspect_ratio=3:2, expect a landscape result such as 1248×832. Count the files before you send the request, because a fourth reference makes the whole request fail.
Edit with the Python SDK
The OpenAI SDK works for single-image edits. This example returns a URL and downloads the image immediately:Parameters
Pricing and billing
Billing counts the images a request actually returns:
LaoZhang API charges the same price for
1k and 2k and for low and medium. LaoZhang API prices are set separately from xAI list pricing, so don’t compare them directly.
Check the console before a large batch, and treat call records as the final billing source.
Error handling
Retry valid requests that hit 429, network errors, or clearly temporary 5xx errors with jittered exponential backoff. After a client timeout, check the call record before you resubmit, so you don’t generate and pay for the same image twice.
Before you go to production
- Generate one
1k,lowimage with the production key. - Save the result and check its real format and dimensions.
- Test the exact resolution, quality, aspect ratio, and
nvalues you plan to use. - For edits, use distinct, non-sensitive references and confirm that each one affects the output.
- Enforce the three-reference limit in your client.
- Set a timeout of at least 60 seconds for
1klowrequests and 120–180 seconds formediumor2k. - Reconcile success rate, latency, output count, and call records before raising concurrency.
Frequently asked questions
What is the exact model ID?
Usegrok-imagine-image-2.0, including the final .0. grok-imagine-image and grok-imagine-image-quality are separate, earlier models.
Am I billed per image? Do resolution and quality change the price?
Per successfully returned image.1k, 2k, low, and medium currently share one per-image price; see Pricing and billing for examples. Latency differs by tier, so plan timeouts accordingly.
A request that fails with an error and returns no image isn’t billed per image. A client timeout isn’t the same as a failure, though: the server may have finished and charged for the image, so check the call record before you resend. Call records are the final billing source.
Can I edit with xAI’s JSON format or send four or five references?
No to both. Editing accepts only multipart file uploads, with up to three references, as the table at the top of this page shows. xAI’s JSON image objects return HTTP 400. xAI’s documentation says the OpenAI SDK’simages.edit() doesn’t work for Grok editing; that applies to xAI’s own JSON-only API.
On LaoZhang API, images.edit() works for single-image edits, as shown in Edit with the Python SDK. For several references, start with the cURL image[] form.
What aspect ratio does an edit return?
According to xAI, an edit withoutaspect_ratio follows the first reference image’s aspect ratio. To fix the frame, add aspect_ratio to the edit request; the three-reference example uses aspect_ratio=3:2 and returns a 1248×832 image.
Can I keep editing the previous result?
Yes. Download the previous result, upload it as theimage, and describe only this round’s change in the prompt, such as “Keep everything the same and add a gold border.” Each round is a new edit request, billed for the images it returns.
How should I store generated images?
Download URL results promptly into your own storage; xAI also describes the returned URLs as temporary. Useb64_json when the image must arrive inside the API response.
Sources and related documentation
- Grok Imagine Image 2.0 launch announcement: availability and the three-reference editing scope
- xAI Grok Imagine Image 2.0 model: official model ID and upstream pricing by resolution and quality
- xAI image generation: official ratios, resolution, quality, batching, and response formats
- xAI image editing: the upstream JSON editing format, which differs from LaoZhang API’s multipart interface
- xAI multi-image editing: the upstream five-image capability; LaoZhang API accepts up to three
- Images API reference: shared request and response structure
- Choose an image generation API: compare Grok Imagine with other image models
- Models and pricing in the console: models, groups, prices, and call records for your account