Home › SpaceXSI API lesson 3: Imagine API images

SpaceXSI API lesson 3: Imagine API images

Last checked

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

  1. Call client.images.generate(model="grok-imagine-image-2.0", prompt="…") with the OpenAI SDK pointed at https://api.x.ai/v1.
  2. Read the image URL from response.data[0].url and download it straight away: URLs are temporary.
  3. Ask for base64 output instead if you want to embed the image directly.
  4. Set n (1 to 10) to get several versions in one request, and set the aspect ratio for where the image will be used.
  5. Use the editing guide to change an existing image, or the video guides for image-to-video.

Try it: examples

Good to know

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.

Report an error on this page