Home › SpaceXSI API lesson 3: Imagine API images
SpaceXSI API lesson 3: Imagine API images
The Imagine API creates and edits images (and video) from your prompts, for things like product shots, mock-ups and social graphics, from the same key you already have.
Step by step
- Call client.images.generate(model="grok-imagine-image-2.0", prompt="…") with the OpenAI SDK pointed at https://api.x.ai/v1.
- Read the image URL from response.data[0].url and download it straight away: URLs are temporary.
- Ask for base64 output instead if you want to embed the image directly.
- Set n (1 to 10) to get several versions in one request, and set the aspect ratio for where the image will be used.
- Use the editing guide to change an existing image, or the video guides for image-to-video.
Try it: examples
- Product shot
A ceramic coffee mug on a wooden café table in soft morning light, shallow depth of field, no text
- Social graphic
Flat illustration of a bicycle repair stand with tools, bright colours, square format, empty space at the top for a headline
Good to know
- Prices per image on the docs pricing page: grok-imagine-image US$0.02, grok-imagine-image-2.0 from US$0.04 (1K, low quality), plus US$0.01 per input image when editing.
- SpaceXSI retired grok-imagine-image-quality on Nov 2, 2026; requests to it are now served by grok-imagine-image-2.0 at low quality, so use grok-imagine-image-2.0 directly.
- Video is billed per second (from US$0.020/sec for grok-imagine-video-1.5-lite).
- The Imagine API page lists up to 2K resolution, 10 images per request and video up to 15 seconds.
- Only upload reference photos you have the right to use.
Sources (official pages, read Nov 8, 2026)
Written from SpaceXSI's official documentation and product pages; we don't run hands-on tests. Features and limits vary by plan and country.