Image generation API · xAI

Grok Imagine API

Call Grok Imagine by xAI from your own code with one GluonArt API key. OpenAI-compatible requests, 25 credits per image, paid from a credit balance with no subscription.

Grok Imagine API example

Copy, set GLUONART_API_KEY, run.

Generate · curl
curl https://api.gluonart.com/v1/images/generations \
  -H "Authorization: Bearer $GLUONART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "A lighthouse on a cliff at dawn, soft mist",
    "aspect_ratio": "16:9"
  }'
Generate · Python (OpenAI SDK)
import base64
from openai import OpenAI

client = OpenAI(base_url="https://api.gluonart.com/v1", api_key=GLUONART_API_KEY)

result = client.images.generate(
    model="grok-imagine-image",
    prompt="A lighthouse on a cliff at dawn, soft mist",
    extra_body={"aspect_ratio": "16:9"},
)
with open("image.png", "wb") as file:
    file.write(base64.b64decode(result.data[0].b64_json))
Edit with reference images · curl
curl https://api.gluonart.com/v1/images/edits \
  -H "Authorization: Bearer $GLUONART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "Turn this into a watercolor painting",
    "images": [{ "image_url": "data:image/png;base64,iVBORw0KGgo..." }]
  }'

Parameters and price

Live values from the GluonArt catalogue. 1,000 credits = $1.

Model id
grok-imagine-image
Price
25 credits ($0.025) per image
Endpoint
POST /v1/images/generations and /v1/images/edits
Aspect ratios
1:1, 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, 21:9, 5:2
Reference images
Up to 1 per request
Response
OpenAI images format, base64 (b64_json)

Questions

How much does the Grok Imagine API cost?

25 credits ($0.025) per image. You pay from a prepaid credit balance (1,000 credits = $1), with no subscription and no monthly minimum. Credits never expire.

Can I use the OpenAI SDK with Grok Imagine?

Yes. Set the base URL to https://api.gluonart.com/v1, use your GluonArt API key, and pass "grok-imagine-image" as the model. Images come back in OpenAI's images format, base64-encoded.

Do I need a separate account with xAI?

No. One GluonArt API key and one credit balance cover Grok Imagine and every other image and video model on the API.

Can I try Grok Imagine before writing code?

Yes. The GluonArt studio runs the same model at the same price, so you can test prompts there and then call it from your app.

Other image model APIs

All models and prices: GluonArt API for developers.

Start building with Grok Imagine

Create a key in your dashboard and start calling the API. You pay only for what you generate.

Get an API key