grok-imagine-image and grok-imagine-image-quality for text-to-image generation, 1K/2K output, batches of up to 10 images, and natural-language editing with reference images. Current LaoZhang API per-image pricing is $0.02 for the standard model and $0.045 for the quality model. Confirm the available token group, current price, and recorded charge in the console.
This guide uses “Grok Imagine 2” as the product label for the current Grok Imagine image generation. The request model IDs do not contain
2: use grok-imagine-image or grok-imagine-image-quality.Create an API key
Create a token and confirm its model group, balance, and billing mode
Read the launch announcement
Check the publication date, scope, pricing, and current status
Choose a model
LaoZhang API currently bills by the number of generated images, so
n=4 is four image charges. 1K and 2K currently have the same LaoZhang price. xAI list pricing and LaoZhang API pricing are separate billing contracts; use the console and latest announcement for current LaoZhang rates.Current integration scope
n=10 means up to ten generated output images in one request. It is not a ten-reference input limit; reference counts are model- and route-specific.Prerequisites
1
Create and protect an API key
Create a key in Token Management. Never expose it in browser code, a public repository, or logs.
2
Confirm model and price
Check the model pricing page for the target token group and current rate. A new announcement does not retroactively change earlier charges.
3
Run a one-image acceptance test
Use the production token, prompt, and parameters to generate one image. Check the HTTP status,
data array, actual dimensions, downloaded file, and call log before increasing n or concurrency.Text-to-image quick start
Use the OpenAI-compatible Images endpoint:data. When requesting url, download the file promptly instead of treating a temporary URL as permanent storage.
Python SDK
Reference-image editing
Use/v1/images/edits whenever the task depends on an existing subject, composition, palette, or style. The current LaoZhang compatibility route accepts multipart/form-data file uploads. Do not place a reference-image field in /v1/images/generations and treat HTTP 200 alone as proof that editing occurred.
image[] repeatedly. Upload order maps to “image 1 / image 2 / image 3 / image 4” in the prompt. LaoZhang currently provides these model-specific ranges:
This is the currently runnable four-reference form for the standard model:
Parameters
Use the following table to validate orientation and resolution class. Read the actual output dimensions in production rather than hard-coding inferred pixel sizes:
Migrating from another Images API
Do not replace only the model name if the existing code usessize: "1536x1024" or quality: "high". The current Grok Imagine route uses aspect_ratio plus resolution for the canvas and separate model IDs for standard and quality output.
Production acceptance and errors
- Generate one 1K
1:1image with each model to verify token group, price, and response parsing. - Test the target ratio and 2K next; read actual dimensions and retain the original response.
- Use distinct, non-sensitive references and confirm that every subject and identifying feature appears in the entity. HTTP 200 alone does not prove multi-image use.
- Do not retry an over-limit reference request: reduce Quality to two references or Standard to four.
resolution=4kcan currently return HTTP 503, but this is an unsupported parameter rather than a transient outage; use1kor2k.- Apply jittered exponential backoff to
429and network errors. Correct other400,401, or403request/account problems before retrying. - After a client timeout, check the call log before resubmitting to avoid duplicate charges.
Frequently asked questions
What are the Grok Imagine 2 model IDs?
Usegrok-imagine-image or grok-imagine-image-quality. Do not add 2; grok-imagine-2-image is not a model ID documented on this page.
Which model should I choose?
Start withgrok-imagine-image at $0.02/image for routine assets and batch drafts. Compare the same prompt, ratio, and resolution on grok-imagine-image-quality at $0.045/image when final detail or reference editing matters.
Do 1K and 2K cost the same?
Yes under the current LaoZhang launch pricing. Both resolution classes use the same per-image rate for the selected model. Recheck the console before a large batch because pricing can change.Why does this page list only five aspect ratios?
They are the currently documented LaoZhang gateway commitment, not the complete xAI upstream capability list. xAI documents more ratios, but values outside this page require verification in the current token group.How many reference images can I use?
It depends on the model:grok-imagine-image supports 1–4 references, while grok-imagine-image-quality supports 1–2. Use the standard model for three- or four-reference composition. For mask inpainting or more precise control, evaluate GPT-Image-2.
How should I store the result?
Downloadurl responses promptly into your own object storage. Use b64_json for direct embedding or offline persistence. Do not assume temporary URLs remain available indefinitely.
Sources and related documentation
- xAI multi-image editing — upstream multi-image workflow and input ordering
- xAI Grok Imagine Image model — standard-model image input
- xAI image generation documentation — upstream ratios, resolutions, batching, and response formats
- xAI models and pricing — upstream model IDs and list pricing, not LaoZhang API retail pricing
- LaoZhang Images API reference — common Images API request and response structure
- LaoZhang image generation guide — cross-model selection
- LaoZhang model pricing — current group, retail rate, and billing source of truth