Grok Imagine Image
Grok Imagine Image uses the OpenAI-compatible Images API. Use it for text-to-image generation, posters, product images, and creative visual assets.
Endpoint
POST /v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonFor image editing / image-to-image requests, use:
POST /v1/images/edits
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-dataSupported Models
| Model | Description |
|---|---|
grok-imagine-image | Standard image generation model for most text-to-image use cases |
grok-imagine-image-pro | Higher-quality image generation model for richer detail, texture, and consistency |
grok-imagine-image-edit | Image editing / image-to-image model for reference-image edits, redraws, and style changes |
Actual availability depends on account permissions and platform configuration. Use grok-imagine-image by default, switch to grok-imagine-image-pro when quality matters more, and use grok-imagine-image-edit for reference-image editing.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | grok-imagine-image or grok-imagine-image-pro |
prompt | string | Yes | Image generation prompt |
n | integer | No | Number of images to generate. Defaults to 1; valid range is 1 to 10 |
size | string | No | Output size. Defaults to 1024x1024 |
response_format | string | No | url or b64_json. Defaults to url |
Image Edit Parameters
/v1/images/edits uses multipart/form-data and requires at least one reference image.
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Recommended value: grok-imagine-image-edit |
image | file | Yes | Reference image file field. For multiple images, repeat the image field |
prompt | string | Yes | Image editing prompt |
n | integer | No | Number of images to generate. Defaults to 1 |
size | string | No | Output size. Defaults to 1024x1024 |
response_format | string | No | url or b64_json. Defaults to url |
For client compatibility, the edit endpoint also accepts grok-imagine-image, grok-imagine-image-pro, and grok-imagine-image-lite as model values. Prefer sending grok-imagine-image-edit explicitly.
Supported Sizes
size uses the WIDTHxHEIGHT format. Common values:
size | Ratio |
|---|---|
1024x1024 | 1:1 |
1280x720 | 16:9 |
720x1280 | 9:16 |
1792x1024 | 3:2 |
1024x1792 | 2:3 |
If you are not sure which ratio to use, start with 1024x1024 or 720x1280.
Request Example
curl -X POST https://cubicspaces.cloud/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-imagine-image",
"prompt": "A clean product photo of a transparent glass spaceship on a white studio background, soft lighting, high detail",
"size": "1024x1024",
"n": 1,
"response_format": "url"
}'Higher-quality model example:
curl -X POST https://cubicspaces.cloud/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-imagine-image-pro",
"prompt": "A premium watch product advertisement, black marble surface, dramatic rim light, realistic reflections, luxury editorial style",
"size": "1792x1024",
"n": 1,
"response_format": "b64_json"
}'Image editing / image-to-image example:
curl -X POST https://cubicspaces.cloud/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=grok-imagine-image-edit" \
-F "image=@reference.png" \
-F "prompt=Keep the main subject, change the background to a bright modern studio, realistic lighting" \
-F "size=1024x1024" \
-F "response_format=url"Response Format
When response_format is url:
{
"created": 1770000000,
"data": [
{
"url": "https://example.com/generated-image.png",
"revised_prompt": "A clean product photo..."
}
]
}When response_format is b64_json:
{
"created": 1770000000,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"revised_prompt": "A premium watch product advertisement..."
}
]
}Read image results from data[].url or data[].b64_json.
SDK Examples
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1",
)
result = client.images.generate(
model="grok-imagine-image",
prompt="A clean product photo of a tiny glass spaceship on a white background",
size="1024x1024",
n=1,
response_format="url",
)
print(result.data[0].url)from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1",
)
result = client.images.edit(
model="grok-imagine-image-edit",
image=open("reference.png", "rb"),
prompt="Keep the main subject, change the background to a bright modern studio",
size="1024x1024",
response_format="url",
)
print(result.data[0].url)import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://cubicspaces.cloud/v1"
});
const result = await client.images.generate({
model: "grok-imagine-image",
prompt: "A clean product photo of a tiny glass spaceship on a white background",
size: "1024x1024",
n: 1,
response_format: "url"
});
console.log(result.data[0].url);import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://cubicspaces.cloud/v1"
});
const result = await client.images.edit({
model: "grok-imagine-image-edit",
image: fs.createReadStream("reference.png"),
prompt: "Keep the main subject, change the background to a bright modern studio",
size: "1024x1024",
response_format: "url"
});
console.log(result.data[0].url);Notes
- Use
grok-imagine-imageas the default image model. - Use
grok-imagine-image-profor product images, ads, and detail-sensitive work. - Use
grok-imagine-image-editwith/v1/images/editsand upload the reference image as theimagefile field. - Image generation is non-streaming. Wait for the full response before reading the result.
- If content moderation or upstream errors occur, adjust the prompt and retry.
- Actual model availability and concurrency depend on account permissions and platform configuration.