Skip to content
xAI logo

Grok Imagine Image 2.0

Text-to-Image • xAI

View as MarkdownAgent setup
  • Third-party

xAI's Grok Imagine Image 2.0 is a precise image generation and editing model for creative work, with strong instruction following, typography, layout, and reference-image preservation.

Model Info
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

const response = await env.AI.run(
  'xai/grok-imagine-image-2.0',
  { prompt: 'A concert poster for a synthwave band, bold retro typography, sharp small print' },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "xai/grok-imagine-image-2.0",
  "input": {
    "prompt": "A concert poster for a synthwave band, bold retro typography, sharp small print"
  }
}'
Simple Generation
{
  "state": "Completed",
  "result": {
    "image": "https://examples.aig.cloudflare.com/xai/grok-imagine-image-2.0/simple-generation.jpg"
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

Examples

Portrait 2K — High-resolution image with a controlled aspect ratio
const response = await env.AI.run(
  'xai/grok-imagine-image-2.0',
  {
    aspect_ratio: '3:4',
    prompt:
      'A detailed botanical illustration of exotic tropical flowers with fine line work and watercolor textures',
    quality: 'medium',
    resolution: '2k',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "xai/grok-imagine-image-2.0",
  "input": {
    "aspect_ratio": "3:4",
    "prompt": "A detailed botanical illustration of exotic tropical flowers with fine line work and watercolor textures",
    "quality": "medium",
    "resolution": "2k"
  }
}'
Portrait 2K
{
  "state": "Completed",
  "result": {
    "image": "https://examples.aig.cloudflare.com/xai/grok-imagine-image-2.0/portrait-2k.png"
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}
Low Quality Draft — Fast low-quality draft for iteration
const response = await env.AI.run(
  'xai/grok-imagine-image-2.0',
  {
    aspect_ratio: '1:1',
    prompt: 'A quiet Japanese garden in morning mist with a stone lantern and koi pond',
    quality: 'low',
    resolution: '1k',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "xai/grok-imagine-image-2.0",
  "input": {
    "aspect_ratio": "1:1",
    "prompt": "A quiet Japanese garden in morning mist with a stone lantern and koi pond",
    "quality": "low",
    "resolution": "1k"
  }
}'
Low Quality Draft
{
  "state": "Completed",
  "result": {
    "image": "https://examples.aig.cloudflare.com/xai/grok-imagine-image-2.0/low-quality-draft.jpg"
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

Parameters

prompt
stringrequired
aspect_ratio
stringenum: 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1, auto
quality
stringenum: low, medium
resolution
stringenum: 1k, 2k
response_format
stringenum: url, b64_json
user
string
image
stringGenerated image. Either a base64 data URI (`data:image/png;base64,...`) or an `https://` URL, depending on the upstream `response_format`.

API Schemas (Raw)

Input
Output

Was this helpful?