ApiframeDocs
Image GenerationGrok

Grok Image 2

xAI's Imagine Image 2.0. Instruction-following generation and editing with quality control and output up to 2K.

POST /v2/images/generatemodel: "grok-image"

Grok Image 2 is xAI's Imagine Image 2.0. It follows detailed instructions, plans typography and layout for dense visuals, and supports image editing. Pick 1k or 2k output and trade speed for fidelity with quality.

Omit the image parameter for text-to-image generation, or provide it to edit an existing image. aspect_ratio is ignored when editing.

For the cheaper, faster Grok model, see Grok Image Fast.

See Image Generation overview for common request fields, response format, and error codes.

Model-specific parameters

ParameterTypeDescription
grokImageParams.imagestringInput image URL for editing (optional; omit for text-to-image)
grokImageParams.aspect_ratiostringAspect ratio (ignored when editing). Values: "auto", "1:1" (default), "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "2:1", "1:2", "19.5:9", "9:19.5", "20:9", "9:20"
grokImageParams.resolutionstringOutput resolution. Values: "1k", "2k" (default "2k")
grokImageParams.qualitystringGeneration quality. Values: "low", "medium" (default "medium")

Credit cost

5 credits per generation.

Example result

Once the job is COMPLETED, the result object on GET /v2/jobs/:id looks like:

{
  "images": [
    "https://cdn2.apiframe.ai/images/a1b2c3d4-e5f6-7890-abcd-ef1234567890-1.png"
  ]
}

See Result format for field details.

Code examples

curl -X POST https://api.apiframe.ai/v2/images/generate \
  -H "X-API-Key: afk_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A concert poster for a synthwave band, bold retro typography, sharp small print",
    "model": "grok-image",
    "grokImageParams": {
      "aspect_ratio": "2:3",
      "resolution": "2k",
      "quality": "medium"
    }
  }'
import requests

response = requests.post(
    "https://api.apiframe.ai/v2/images/generate",
    headers={
        "X-API-Key": "afk_your_api_key_here",
        "Content-Type": "application/json",
    },
    json={
        "prompt": "A concert poster for a synthwave band, bold retro typography, sharp small print",
        "model": "grok-image",
        "grokImageParams": {
            "aspect_ratio": "2:3",
            "resolution": "2k",
            "quality": "medium",
        },
    },
)
print(response.json())
const response = await fetch("https://api.apiframe.ai/v2/images/generate", {
  method: "POST",
  headers: {
    "X-API-Key": "afk_your_api_key_here",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    prompt: "A concert poster for a synthwave band, bold retro typography, sharp small print",
    model: "grok-image",
    grokImageParams: { aspect_ratio: "2:3", resolution: "2k", quality: "medium" },
  }),
});
console.log(await response.json());

Try it

POST/v2/images/generateTry it

On this page