Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Grok Imagine Image 2.0

Model id: x-ai/grok-imagine-image-2.0. Grok Imagine Image 2.0 is the second generation of the xAI image model, for image generation and editing.

This documentation is valid for the following list of our models:

  • x-ai/grok-imagine-image-2.0

Model Overview

Grok Imagine Image 2.0 is the second generation of the xAI image model, for image generation and editing. It follows detailed instructions closely, renders small text and typography sharply, and edits from up to 5 reference images. Choose low or medium quality at 1K, 1.5K or 2K resolution.

Setup your API Key

If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.

API Schemas

post
Body
modelstring · enumRequiredPossible values:
promptstringRequired

The text prompt describing the content, style, or composition of the image to be generated.

nnumber · min: 1 · max: 10Optional

The number of images to generate.

Default: 1
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
aspect_ratiostring · enumOptional

The aspect ratio of the generated image.

Default: autoPossible values:
resolutionstring · enumOptional

The resolution of the output image. A higher resolution costs more.

Default: 1kPossible values:
qualitystring · enumOptional

The quality of the image that will be generated. medium renders more detail and costs more than low at the same resolution.

Default: lowPossible values:
Responses
200

Successful response.

application/json
post/v1/images/generations
curl --request POST \
  --url 'https://api.aimlapi.com/v1/images/generations' \
  --header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{"model": "x-ai/grok-imagine-image-2.0", "prompt": "Describe what you want the model to generate."}'
200

Successful response.

{
  "data": [
    {
      "url": "https://cdn.aimlapi.com/generations/hedgehog/1749730923700-29fe35d2-4aef-4bc5-a911-6c39884d16a8.png",
      "b64_json": null
    }
  ],
  "meta": {
    "usage": {
      "credits_used": 120000,
      "usd_spent": 0.06
    }
  }
}
post
Body
modelstring · enumRequiredPossible values:
promptstringRequired

The text prompt describing the content, style, or composition of the image to be generated.

imageany ofRequired

The image(s) to edit: one PNG, JPEG or WebP file, or an array of up to 5. Refer to several images in the prompt as <IMAGE_0>, <IMAGE_1>, … in upload order.

or
ninteger · min: 1 · max: 10Optional

The number of images to generate.

Default: 1
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
aspect_ratiostring · enumOptional

The aspect ratio of the edited image. When omitted, the output keeps the aspect ratio of the first input image.

Possible values:
resolutionstring · enumOptional

The resolution of the output image. A higher resolution costs more.

Default: 1kPossible values:
qualitystring · enumOptional

The quality of the image that will be generated. medium renders more detail and costs more than low at the same resolution.

Default: lowPossible values:
Responses
200

Successful response.

application/json
post/v1/images/edits
curl --request POST \
  --url 'https://api.aimlapi.com/v1/images/edits' \
  --header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{"model": "x-ai/grok-imagine-image-2.0", "prompt": "Describe what you want the model to generate.", "image": "<image>"}'
200

Successful response.

{
  "data": [
    {
      "url": "https://cdn.aimlapi.com/generations/hedgehog/1749730923700-29fe35d2-4aef-4bc5-a911-6c39884d16a8.png",
      "b64_json": null
    }
  ],
  "meta": {
    "usage": {
      "credits_used": 120000,
      "usd_spent": 0.06
    }
  }
}

Quick Example

Let's generate an image of the specified size using a simple prompt.

Response

We obtained the following 2816x1536 image by running this code example:

Last updated

Was this helpful?