Skip to content

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

http
POST /v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

For image editing / image-to-image requests, use:

http
POST /v1/images/edits
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-data

Supported Models

ModelDescription
grok-imagine-imageStandard image generation model for most text-to-image use cases
grok-imagine-image-proHigher-quality image generation model for richer detail, texture, and consistency
grok-imagine-image-editImage 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

ParameterTypeRequiredDescription
modelstringYesgrok-imagine-image or grok-imagine-image-pro
promptstringYesImage generation prompt
nintegerNoNumber of images to generate. Defaults to 1; valid range is 1 to 10
sizestringNoOutput size. Defaults to 1024x1024
response_formatstringNourl or b64_json. Defaults to url

Image Edit Parameters

/v1/images/edits uses multipart/form-data and requires at least one reference image.

ParameterTypeRequiredDescription
modelstringYesRecommended value: grok-imagine-image-edit
imagefileYesReference image file field. For multiple images, repeat the image field
promptstringYesImage editing prompt
nintegerNoNumber of images to generate. Defaults to 1
sizestringNoOutput size. Defaults to 1024x1024
response_formatstringNourl 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:

sizeRatio
1024x10241:1
1280x72016:9
720x12809:16
1792x10243:2
1024x17922:3

If you are not sure which ratio to use, start with 1024x1024 or 720x1280.

Request Example

bash
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:

bash
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:

bash
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:

json
{
  "created": 1770000000,
  "data": [
    {
      "url": "https://example.com/generated-image.png",
      "revised_prompt": "A clean product photo..."
    }
  ]
}

When response_format is b64_json:

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

python
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)
python
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)
js
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);
js
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-image as the default image model.
  • Use grok-imagine-image-pro for product images, ads, and detail-sensitive work.
  • Use grok-imagine-image-edit with /v1/images/edits and upload the reference image as the image file 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.