# Grok Imagine Image Generation

> Image Generation

Initiate an image generation request. The request body contains the model, prompt, and optional generation parameters. The response returns a list of image URLs.
Supported models: `grok-imagine-image`, `grok-imagine-image-quality`

## Endpoint

`POST https://api.modelverse.cn/v1/images/generations`

## Request Body

## Responses

- **200** — Image generation response.
- **400** — 
- **default** — 

## OpenAPI Definition

```json
{
  "openapi": "3.1.0",
  "x-language": "en-US",
  "info": {
    "title": "Grok Imagine API Documentation",
    "version": "1.0.0",
    "description": "This is the API documentation for `grok-imagine-image` and `grok-imagine-image-quality` models on ModelVerse, explaining how to initiate image generation requests, fill in parameters, read results, and handle errors.\nThe API endpoint is `POST /v1/images/generations`.\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse API endpoint for Grok Imagine models."
    }
  ],
  "tags": [
    {
      "name": "GrokImagine",
      "description": "OpenAI-compatible image generation APIs for Grok Imagine models."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/images/generations": {
      "post": {
        "tags": [
          "GrokImagine"
        ],
        "operationId": "createGrokImagineImageGeneration",
        "summary": "Grok Imagine Image Generation",
        "description": "Initiate an image generation request. The request body contains the model, prompt, and optional generation parameters. The response returns a list of image URLs.\nSupported models: `grok-imagine-image`, `grok-imagine-image-quality`\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GrokImagineGenerateRequest"
              },
              "examples": {
                "grokImagineImage": {
                  "summary": "Generate image using grok-imagine-image",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "A joyful kindergarten scene for Children's Day",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2
                  }
                },
                "grokImagineImageQuality": {
                  "summary": "Generate high-quality image using grok-imagine-image-quality",
                  "value": {
                    "model": "grok-imagine-image-quality",
                    "prompt": "A joyful kindergarten scene for Children's Day",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2
                  }
                },
                "grokImagineImageB64Json": {
                  "summary": "Generate image using grok-imagine-image and return Base64 format",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "A joyful kindergarten scene for Children's Day",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2,
                    "response_format": "b64_json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image generation response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrokImagineImageResponse"
                },
                "examples": {
                  "imageUrls": {
                    "summary": "Return list of image URLs",
                    "value": {
                      "created": 1782875947,
                      "data": [
                        {
                          "url": "https://xxxxx/xxxx.png"
                        },
                        {
                          "url": "https://xxxxx/xxxx.png"
                        }
                      ]
                    }
                  },
                  "imageB64Json": {
                    "summary": "Return Base64 encoded image data",
                    "value": {
                      "created": 1782875947,
                      "data": [
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        },
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/images/edits": {
      "post": {
        "tags": [
          "GrokImagine"
        ],
        "operationId": "createGrokImagineImageEdit",
        "summary": "Grok Imagine Image Editing",
        "description": "Initiate an image editing request. Supports single image editing or multi-image style transfer.\n- Single image editing: Use the `image` parameter to pass an image URL\n- Multi-image editing: Use the `images` parameter to pass an array of image URLs (e.g., for style transfer)\nSupported models: `grok-imagine-image`, `grok-imagine-image-quality`\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GrokImagineEditRequest"
              },
              "examples": {
                "singleImageEdit": {
                  "summary": "Single image editing",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "Render this as a pencil sketch with detailed shading",
                    "image": "https://xxxxx/xxxx.png",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 1
                  }
                },
                "multiImageEdit": {
                  "summary": "Multi-image style transfer",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "Apply the style from the first image to the content of the second image",
                    "images": [
                      "https://xxxxx/xxxx.png",
                      "https://xxxxx/xxxx.jpg"
                    ],
                    "size": "1k",
                    "aspect_ratio": "4:3",
                    "n": 2
                  }
                },
                "singleImageEditB64Json": {
                  "summary": "Single image editing and return Base64 format",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "Render this as a pencil sketch with detailed shading",
                    "image": "https://xxxxx/xxxx.png",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 1,
                    "response_format": "b64_json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image editing response.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrokImagineImageResponse"
                },
                "examples": {
                  "editedImageUrls": {
                    "summary": "Return list of edited image URLs",
                    "value": {
                      "created": 1782877070,
                      "data": [
                        {
                          "url": "https://xxxxx/xxxx.jpeg"
                        },
                        {
                          "url": "https://xxxxx/xxxx.jpeg"
                        }
                      ]
                    }
                  },
                  "editedImageB64Json": {
                    "summary": "Return Base64 encoded edited image data",
                    "value": {
                      "created": 1782877070,
                      "data": [
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        },
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "API key authentication in the format `Bearer {API_KEY}`"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request parameters or image generation failed.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "invalidRequest": {
                "summary": "Invalid request parameters",
                "value": {
                  "error": {
                    "message": "Invalid request parameters",
                    "type": "invalid_request_error",
                    "param": "model",
                    "code": "param_error"
                  }
                }
              }
            }
          }
        }
      },
      "Error": {
        "description": "Error response.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "requestError": {
                "summary": "Request error",
                "value": {
                  "error": {
                    "message": "error_message",
                    "type": "error_type",
                    "param": "request_id",
                    "code": "error_code"
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "GrokImagineGenerateRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "grok-imagine-image",
              "grok-imagine-image-quality"
            ],
            "description": "Model name. Supports the following two models:\n- `grok-imagine-image`: Standard image generation model\n- `grok-imagine-image-quality`: High-quality image generation model\n"
          },
          "prompt": {
            "type": "string",
            "description": "Text prompt describing the image to generate."
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 1,
            "description": "Number of images to generate."
          },
          "size": {
            "type": "string",
            "enum": [
              "1k",
              "2k"
            ],
            "default": "1k",
            "description": "Size specification for the generated image."
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "1:1",
              "3:4",
              "4:3",
              "9:16",
              "16:9",
              "2:3",
              "3:2",
              "9:19.5",
              "19.5:9",
              "9:20",
              "20:9",
              "1:2",
              "2:1",
              "auto"
            ],
            "default": "4:3",
            "description": "Aspect ratio for the generated image."
          },
          "response_format": {
            "type": "string",
            "enum": [
              "b64_json"
            ],
            "default": "",
            "description": "Response format:\n- `b64_json`: Return Base64 encoded image data\n"
          }
        }
      },
      "GrokImagineImageResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "created",
          "data"
        ],
        "properties": {
          "created": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp (in seconds) when the request was created."
          },
          "data": {
            "type": "array",
            "description": "List of generated image results.",
            "items": {
              "$ref": "#/components/schemas/GrokImagineImageData"
            }
          }
        }
      },
      "GrokImagineImageData": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL of the generated image. Returned when `response_format` is `url`."
          },
          "b64_json": {
            "type": "string",
            "description": "Base64 encoded image data. Returned when `response_format` is `b64_json`."
          },
          "mime_type": {
            "type": "string",
            "description": "MIME type of the image (e.g., `image/jpeg`, `image/png`). Returned when `response_format` is `b64_json`."
          }
        }
      },
      "GrokImagineEditRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "grok-imagine-image",
              "grok-imagine-image-quality"
            ],
            "description": "Model name. Supports the following two models:\n- `grok-imagine-image`: Standard image generation model\n- `grok-imagine-image-quality`: High-quality image generation model\n"
          },
          "prompt": {
            "type": "string",
            "description": "Text prompt describing the editing operation."
          },
          "image": {
            "type": "string",
            "format": "uri",
            "description": "URL of a single image. Used for single image editing, mutually exclusive with the `images` parameter."
          },
          "images": {
            "type": "array",
            "description": "Array of image URLs. Used for multi-image style transfer scenarios, mutually exclusive with the `image` parameter.",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 1,
            "description": "Number of images to generate."
          },
          "size": {
            "type": "string",
            "enum": [
              "1k",
              "2k"
            ],
            "default": "1k",
            "description": "Size specification for the generated image."
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "1:1",
              "3:4",
              "4:3",
              "9:16",
              "16:9",
              "2:3",
              "3:2",
              "9:19.5",
              "19.5:9",
              "9:20",
              "20:9",
              "1:2",
              "2:1",
              "auto"
            ],
            "default": "4:3",
            "description": "Aspect ratio for the generated image."
          },
          "response_format": {
            "type": "string",
            "enum": [
              "b64_json"
            ],
            "default": "",
            "description": "Response format:\n- `b64_json`: Return Base64 encoded image data\n"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorObject"
          }
        }
      },
      "ErrorObject": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "message",
          "type"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message."
          },
          "type": {
            "type": "string",
            "description": "Error type."
          },
          "param": {
            "type": [
              "string",
              "null"
            ],
            "description": "Request parameter or request ID related to the error."
          },
          "code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Machine-readable error code."
          }
        }
      }
    }
  }
}
```
