# Grok Imagine Image

`grok-imagine-image` generates and edits images through SeedRouter's unified asynchronous image endpoint (`POST /v1/images/generations`) and task polling endpoint (`GET /v1/tasks/{task_id}`). Every delivered image is billed at one flat per-image rate regardless of whether you pick `1k` or `2k` or attach reference images.

> **Model positioning**: `grok-imagine-image` is xAI's standard flat-rate image generation and editing model across `1k` and `2k` resolutions with no extra reference-image surcharge. If you need explicit `quality` (`low` vs `medium`) or `1.5k` resolution, see [`grok-imagine-image-2.0`](https://seedrouter.ai/docs/grok-imagine-image-2-0).

## Quick reference

| Property            | Value                                                                                                                                                               |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Model ID            | `grok-imagine-image`                                                                                                                                                |
| Submit endpoint     | `POST https://api.seedrouter.ai/v1/images/generations`                                                                                                              |
| Poll endpoint       | `GET https://api.seedrouter.ai/v1/tasks/{task_id}`                                                                                                                  |
| Auth                | `Authorization: Bearer $SEEDROUTER_API_KEY`                                                                                                                         |
| Outputs per request | `n`: `1`–`10` (default `1`)                                                                                                                                         |
| Resolutions         | `1k` (default), `2k`                                                                                                                                                |
| Aspect ratios       | `auto` (default) + 15 explicit ratios                                                                                                                               |
| Reference images    | Optional `image_urls`: 1–5 public HTTP(S) URLs (JPEG, PNG, or WebP, ≤ 20 MiB each)                                                                                  |
| Pricing & OpenAPI   | Live rates at [`/models/grok-imagine-image`](https://seedrouter.ai/models/grok-imagine-image) · OpenAPI [`/docs/grok-imagine-image.openapi.json`](https://seedrouter.ai/docs/grok-imagine-image.openapi.json) |

## Request parameters

All requests—both text-to-image generation and image editing—go to `POST /v1/images/generations`. Unknown parameters (including `quality` and `response_format`) are rejected with HTTP `400`.

| Field          | Type       | Required | Default  | Rules                                                                                                                                                                                              |
| -------------- | ---------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`        | `string`   | Yes      | —        | Must be `"grok-imagine-image"`.                                                                                                                                                                    |
| `prompt`       | `string`   | Yes      | —        | 1–10,000 Unicode characters after trimming. For multi-image edits, reference inputs as `<IMAGE_0>`, `<IMAGE_1>`, etc.                                                                              |
| `n`            | `integer`  | No       | `1`      | `1`–`10`. Final billing settles on delivered images.                                                                                                                                               |
| `aspect_ratio` | `string`   | No       | `"auto"` | One of `auto`, `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`, `21:9`, `5:2`. Single-image edits preserve source framing when left on `auto`. |
| `resolution`   | `string`   | No       | `"1k"`   | `1k` or `2k`. (`1.5k` is exclusive to `grok-imagine-image-2.0`.)                                                                                                                                   |
| `image_urls`   | `string[]` | No       | —        | 1–5 public HTTP(S) image URLs (JPEG, PNG, or WebP, ≤ 20 MiB each). Base64 strings and `data:` URIs are rejected.                                                                                   |
| `user`         | `string`   | No       | —        | Optional end-user identifier for abuse monitoring (≤ 256 characters; API only).                                                                                                                    |

## Pricing & billing behavior

* **Flat per delivered image**: See live rates on [`/models/grok-imagine-image`](https://seedrouter.ai/models/grok-imagine-image) or `GET https://api.seedrouter.ai/v1/pricing`.
* **1K and 2K share one rate**, and attaching `image_urls` adds no per-reference surcharge.
* **Delivered-count settlement**: Multi-image batches settle only on the number of images actually delivered. Failed requests are not charged.

## Text-to-image examples

```bash
# 1. Submit task
curl -sS https://api.seedrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "Editorial studio still life of a matte ceramic espresso pour-over set on dark travertine stone, warm morning sidelight",
    "n": 2,
    "aspect_ratio": "4:3",
    "resolution": "2k"
  }'

# 2. Poll until status is "completed" or "failed"
curl -sS "https://api.seedrouter.ai/v1/tasks/${TASK_ID}" \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY"
```

```python
import os, time, requests

API_KEY = os.environ["SEEDROUTER_API_KEY"]
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}

submit = requests.post(
    "https://api.seedrouter.ai/v1/images/generations",
    headers=HEADERS,
    json={
        "model": "grok-imagine-image",
        "prompt": "Editorial studio still life of a matte ceramic espresso pour-over set on dark travertine stone, warm morning sidelight",
        "n": 2,
        "aspect_ratio": "4:3",
        "resolution": "2k",
    },
    timeout=30,
)
submit.raise_for_status()
task_id = submit.json()["id"]

while True:
    poll = requests.get(
        f"https://api.seedrouter.ai/v1/tasks/{task_id}",
        headers=HEADERS,
        timeout=30,
    )
    poll.raise_for_status()
    data = poll.json()
    if data["status"] in ("completed", "failed"):
        print(data)
        break
    time.sleep(2)
```

```javascript
const headers = {
  Authorization: `Bearer ${process.env.SEEDROUTER_API_KEY}`,
  'Content-Type': 'application/json',
};

const submitRes = await fetch('https://api.seedrouter.ai/v1/images/generations', {
  method: 'POST',
  headers,
  body: JSON.stringify({
    model: 'grok-imagine-image',
    prompt:
      'Editorial studio still life of a matte ceramic espresso pour-over set on dark travertine stone, warm morning sidelight',
    n: 2,
    aspect_ratio: '4:3',
    resolution: '2k',
  }),
});
const { id } = await submitRes.json();

while (true) {
  const pollRes = await fetch(`https://api.seedrouter.ai/v1/tasks/${id}`, { headers });
  const task = await pollRes.json();
  if (task.status === 'completed' || task.status === 'failed') {
    console.log(task);
    break;
  }
  await new Promise((r) => setTimeout(r, 2000));
}
```

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	apiKey := os.Getenv("SEEDROUTER_API_KEY")
	payload, _ := json.Marshal(map[string]any{
		"model":        "grok-imagine-image",
		"prompt":       "Editorial studio still life of a matte ceramic espresso pour-over set on dark travertine stone, warm morning sidelight",
		"n":            2,
		"aspect_ratio": "4:3",
		"resolution":   "2k",
	})
	req, _ := http.NewRequest("POST", "https://api.seedrouter.ai/v1/images/generations", bytes.NewReader(payload))
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	var accepted struct{ ID string `json:"id"` }
	_ = json.NewDecoder(resp.Body).Decode(&accepted)
	resp.Body.Close()

	for {
		pollReq, _ := http.NewRequest("GET", "https://api.seedrouter.ai/v1/tasks/"+accepted.ID, nil)
		pollReq.Header.Set("Authorization", "Bearer "+apiKey)
		pollResp, err := http.DefaultClient.Do(pollReq)
		if err != nil {
			panic(err)
		}
		var task map[string]any
		_ = json.NewDecoder(pollResp.Body).Decode(&task)
		pollResp.Body.Close()
		if task["status"] == "completed" || task["status"] == "failed" {
			fmt.Println(task)
			break
		}
		time.Sleep(2 * time.Second)
	}
}
```

## Image editing example

Attach 1–5 public HTTPS URLs in `image_urls` on the same `POST /v1/images/generations` endpoint:

```bash
curl -sS https://api.seedrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "Place the ceramic vessel from <IMAGE_0> onto the sunlit linen table in <IMAGE_1>, matching warm directional shadows",
    "image_urls": [
      "https://example.com/vessel.png",
      "https://example.com/table.jpg"
    ],
    "resolution": "2k"
  }'
```

## Task responses

Submission returns `200 OK` immediately:

```json
{
  "id": "task_01j...",
  "model": "grok-imagine-image",
  "status": "processing",
  "created_at": 1764140000
}
```

Completed tasks return permanent CDN URLs in `output.data`:

```json
{
  "id": "task_01j...",
  "model": "grok-imagine-image",
  "status": "completed",
  "created_at": 1764140000,
  "finished_at": 1764140014,
  "output": {
    "created": 1764140014,
    "data": [
      { "url": "https://static.seedrouter.ai/..." }
    ]
  }
}
```

See the [shared error directory](https://seedrouter.ai/docs/api/errors) for full HTTP and public `error.code` documentation.
