Text to image

Grok Imagine Image

xAI Grok Imagine: text to image; speed mode returns two images, quality mode favours precision.

xai/grok-imagine-image
Price
$0.024
per image

Charged when the job is queued, returned if the generation fails.

Example output

Try it

More settings
Cost
≈ $0.024

The result will appear here. The playground uses the same API as the code below and charges the cost to your balance.

Request parameters

Fields of the JSON request body. The model takes no other fields: a request with them gets a 400 error.

  • promptstringrequired

    Text prompt describing the desired image.

  • enable_protrue / falseoptional

    Controls the request processing strategy.

    Default:
    false
    Price:
    Changes the price.
  • aspect_ratiostringoptional

    Required.

    Default:
    1:1
    Values:
    2:3, 3:2, 1:1, 16:9, 9:16

Use it through the API

Create a key in your account. Details are in the documentation.

curl

curl -X POST https://getmegabrain.com/api/gateway/v1/queue/xai/grok-imagine-image \
  -H "Authorization: Bearer $MEGABRAIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a ceramic coffee mug on a sunlit oak table, product photo"}'

# Then poll status_url and fetch the result from response_url:
curl https://getmegabrain.com/api/gateway/v1/queue/requests/$REQUEST_ID -H "Authorization: Bearer $MEGABRAIN_API_KEY"

Python

import os, time, requests

BASE = "https://getmegabrain.com/api/gateway/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MEGABRAIN_API_KEY']}"}

job = requests.post(f"{BASE}/queue/xai/grok-imagine-image", headers=HEADERS, json={
  "prompt": "a ceramic coffee mug on a sunlit oak table, product photo"
}).json()

while requests.get(job["status_url"], headers=HEADERS).json()["status"] not in ("COMPLETED", "FAILED"):
    time.sleep(2)

print(requests.get(job["response_url"], headers=HEADERS).json())

JavaScript

const BASE = 'https://getmegabrain.com/api/gateway/v1';
const headers = {
  Authorization: `Bearer ${process.env.MEGABRAIN_API_KEY}`,
  'Content-Type': 'application/json',
};

const job = await fetch(`${BASE}/queue/xai/grok-imagine-image`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    "prompt": "a ceramic coffee mug on a sunlit oak table, product photo"
  }),
}).then(r => r.json());

let status = job.status;
while (status !== 'COMPLETED' && status !== 'FAILED') {
  await new Promise(r => setTimeout(r, 2000));
  ({ status } = await fetch(job.status_url, { headers }).then(r => r.json()));
}
console.log(await fetch(job.response_url, { headers }).then(r => r.json()));

Questions

How much does Grok Imagine Image cost through the API?

$0.024 per image, charged from a prepaid US-dollar balance. A job the provider fails is refunded in full. There is no subscription.

How do I use Grok Imagine Image through the API?

Submit a job with POST https://getmegabrain.com/api/gateway/v1/queue/xai/grok-imagine-image and your MegaBrain API key, poll its status_url until it is COMPLETED, then fetch the result from response_url. The same key and balance work for text models.

Can I try Grok Imagine Image without writing code?

Yes: once you sign in, the playground on the model page runs Grok Imagine Image in the browser, paid from the same balance as the API.