Grok Imagine images
Generate and edit images with Grok Imagine: parameters, responses, and caveats.
| Item | Value |
|---|---|
| Base URL | https://api.hop-base.com/v1 |
| Generate an image | POST /v1/images/generations |
| Edit an image | POST /v1/images/edits |
| Group | Grok Suite |
Grok Imagine image generation is synchronous only: one request returns a temporary download link for the image.
Available models
| Model | Model ID | Tiers | Official price |
|---|---|---|---|
| Grok Imagine Image | grok-imagine-image | 1k / 2k | $0.02/ image |
| Grok Imagine Image 2.0 | grok-imagine-image-2.0 | 1k / 2k | $0.04from/ image |
| Grok Imagine Image Quality | grok-imagine-image-quality | 1k / 2k | $0.05from/ image |
The three models take exactly the same request parameters; only the rates differ.
Request parameters
Generations
| Parameter | Required | Type and limits | Default | Description |
|---|---|---|---|---|
model | Required | string, one of the three IDs above | — | Use the ID GET /v1/models returns |
prompt | Required | string, non-empty | — | Content, composition, style, or edit |
resolution | Optional | 1k / 2k | 1k | Pixel tier and billing tier |
quality | Optional | low / medium / auto | auto | Grok's own parameter |
aspect_ratio | Optional | 16 values, see the size table | auto (1:1) | Sets the shape |
n | Optional | integer 1–10 | 1 | Billed per image actually returned |
mask | Not supported | — | — | Rejected with 400 |
quality, aspect_ratio, and n are checked by the model, not the gateway. grok-imagine-image-quality is a model ID, not a value of the quality field.
size is a GPT Image parameter and Grok image generation does not use it: shape comes from aspect_ratio and the pixel tier from resolution. Migrating from GPT Image: drop size, and map quality onto one of the three values above.
Edits
On top of the generation parameters, /v1/images/edits takes reference images in image:
| Parameter | Required | Type and limits | Default | Description |
|---|---|---|---|---|
image | Required | 1–2 images, URL or Data URL | — | A third image is rejected |
imagecan be a URL string, a string array, or{ "url": ... }.- Each image is a public HTTP(S) URL or a full Data URL (
data:image/png;base64,…). - Bare base64,
asset://, andfile_idare not accepted. - Uploading a local file with the OpenAI SDK works too, as a multipart
imageor repeatedimage[]files.
curl https://api.hop-base.com/v1/images/edits \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "Replace the background with a seaside at dusk, keep the subject",
"image": ["https://example.com/source.png"],
"aspect_ratio": "3:2",
"resolution": "1k"
}'Aspect ratio and actual output size
aspect_ratio sets the shape and resolution sets the pixel budget: about 1 megapixel at 1k and about 4 megapixels at 2k. The table shows measured output sizes for grok-imagine-image at resolution: 1k:
aspect_ratio | Measured output (1k) | Ratio |
|---|---|---|
1:1 | 1024×1024 | 1.0000 |
16:9 | 1280×720 | 1.7778 |
9:16 | 720×1280 | 0.5625 |
4:3 | 1152×864 | 1.3333 |
3:4 | 864×1152 | 0.7500 |
3:2 | 1248×832 | 1.5000 |
2:3 | 832×1248 | 0.6667 |
2:1 | 1408×704 | 2.0000 |
1:2 | 704×1408 | 0.5000 |
21:9 | 1568×672 | 2.3333 |
19.5:9 | 1248×576 | 2.1667 |
5:2 | 1600×640 | 2.5000 |
auto / omitted | 1024×1024 | 1.0000 |
9:19.5, 20:9, and 9:20 are also valid values; their measured sizes are simply not listed above. resolution: 2k keeps the same shape and raises the pixel budget — 16:9 becomes 2816×1584 and 1:1 becomes 2048×2048.
Response
| Field | Type | Description |
|---|---|---|
data | array | Generated images, one per image returned |
data[].url | string | Temporary download link for the image |
usage.cost_in_usd_ticks | integer | Official metering value, not your charge |
Example response (placeholder URL; other metadata omitted):
{
"data": [
{
"url": "https://example.com/generated-image.png"
}
]
}Download and store the image as soon as you receive it. The response carries no token usage; an empty response means no image was generated, so an empty data array is not a success.
Examples
curl https://api.hop-base.com/v1/images/generations \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "An orange cat asleep on a sunlit windowsill, magazine photo",
"aspect_ratio": "16:9",
"resolution": "2k",
"n": 1
}'aspect_ratio and resolution are not built-in OpenAI SDK parameters, so Python passes them in extra_body.
Caveats
- Synchronous only: there is no streaming, and do not send
Prefer: respond-async. - Image
resolutionis1kor2konly — no 4K tier, and the video values480p/720p/1080pdo not apply. - The returned URL is temporary, so download the image right away.
- Edits take at most 2 reference images; this is HopBase's image-edit limit and does not apply to video.
- Images and video are two separate groups and keys do not cross over; for video see Grok Imagine video.
A multipart edit keeps only model, prompt, image, n, resolution, aspect_ratio, and quality; other form fields are dropped.
The xAI editing documentation sets no per-file byte or input-pixel maximum. Do not infer one from output resolution or apply GPT Image's 25 MiB / 4 MiB rules.
Use reasonably compressed images; the official media validation still applies.
Common errors
| Error | Fix |
|---|---|
resolution must be 1k or 2k | Use 1k or 2k |
this model does not support the mask parameter | Remove mask |
this model supports at most 2 input images on /v1/images/edits | Send 2 reference images or fewer |
prompt must not be empty | Send a non-empty prompt |
/v1/images/edits requires at least one image | Send 1–2 images in image |
image must be a data URL or an http(s) URL | Wrap bare base64 in a full Data URL |
image object is missing the url field | Write the object as { "url": ... } |
image models do not support Chat Completions, please use the Images API | Call /v1/images/generations instead |
400 with content-moderated in the message | Rephrase the prompt; not billed |
Out-of-range n, quality, or aspect_ratio values are rejected by the model with its own message. When an image request fails, check the HTTP status and error.
Billing
Charges are per image returned, by resolution tier, never by pixel dimensions; each reference image on /v1/images/edits is charged separately, and moderated requests are not billed. grok-imagine-image also accepts 2k and bills it at the 1k rate.
The usage.cost_in_usd_ticks field in the response is not your charge; reconcile against the Usage page in the console. Per-tier rates are on the model cards above, and your own rate is the one in the Model Plaza.
Next steps
- Image overview: compare image series and shared rules
- GPT Image, Gemini image, Seedream: other image series
- Grok Imagine video: submit and poll Grok video tasks
- API reference: Create image, Edit image
- Troubleshooting: diagnose failed requests by symptom