# Kling Image 4.0

Submit a JSON request to `POST /v1/images/generations` with the model ID `kling-image-4-0`. Save the returned task ID. The same endpoint accepts text-only briefs and reference-guided briefs.

## Quick example

This request makes one square 2K still. Store your API key in the `SEEDROUTER_API_KEY` environment variable.

```bash
curl https://api.seedrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "kling-image-4-0",
    "contents": [
      {"type": "prompt", "text": "Photograph an amber glass teapot on blue slate, lit through its handle by the morning sun."}
    ],
    "settings": {"resolution": "2k", "aspect_ratio": "1:1"}
  }'
```

```python
import os
import requests

response = requests.post(
    "https://api.seedrouter.ai/v1/images/generations",
    headers={"Authorization": "Bearer " + os.environ["SEEDROUTER_API_KEY"]},
    json={
        "model": "kling-image-4-0",
        "contents": [{"type": "prompt", "text": "An amber glass teapot on blue slate in morning light."}],
        "settings": {"resolution": "2k", "aspect_ratio": "1:1"},
    },
    timeout=60,
)
response.raise_for_status()
print(response.json()["id"])
```

```javascript
const response = await fetch("https://api.seedrouter.ai/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SEEDROUTER_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "kling-image-4-0",
    contents: [{ type: "prompt", text: "An amber glass teapot on blue slate in morning light." }],
    settings: { resolution: "2k", aspect_ratio: "1:1" },
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log((await response.json()).id);
```

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func main() {
    body := `{"model":"kling-image-4-0","contents":[{"type":"prompt","text":"An amber glass teapot on blue slate in morning light."}],"settings":{"resolution":"2k","aspect_ratio":"1:1"}}`
    req, err := http.NewRequest("POST", "https://api.seedrouter.ai/v1/images/generations", strings.NewReader(body))
    if err != nil { panic(err) }
    req.Header.Set("Authorization", "Bearer "+os.Getenv("SEEDROUTER_API_KEY"))
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{Timeout: 60 * time.Second}
    resp, err := client.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()
    result, err := io.ReadAll(resp.Body)
    if err != nil { panic(err) }
    if resp.StatusCode != http.StatusOK { panic(string(result)) }
    fmt.Println(string(result))
}
```

## Endpoint and headers

Send JSON to `POST https://api.seedrouter.ai/v1/images/generations` with `Content-Type: application/json` and `Authorization: Bearer YOUR_API_KEY`. Keep the key on your server.

## Parameters

| Field                            | Type              | Values and defaults                                                                                                                                                                                                                                                                                                              |
| -------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`                          | string, required  | `kling-image-4-0`                                                                                                                                                                                                                                                                                                                |
| `contents`                       | array, required   | One prompt and zero to ten reference images.                                                                                                                                                                                                                                                                                     |
| `contents[].type`                | string, required  | `prompt` or `refer_image`.                                                                                                                                                                                                                                                                                                       |
| `contents[].text`                | string            | Required for the prompt. English-only limit 50,000 characters, non-English limit 21,000. In mixed text, the two fractions of their respective limits must sum to at most one.                                                                                                                                                    |
| `contents[].url`                 | string            | Required for each reference. Use an accessible HTTP(S) URL for a JPEG or PNG up to 30 MB. Both sides must be at least 300 pixels and the width-to-height ratio must be between 2:5 and 5:2.                                                                                                                                      |
| `contents[].id`                  | string            | Optional unique name for a reference. Mention the name as `@name` in the prompt.                                                                                                                                                                                                                                                 |
| `settings.result_type`           | string            | `single` (default) for independent images, or `series` for related images.                                                                                                                                                                                                                                                       |
| `settings.n`                     | integer           | 1–9 independent images. Defaults to 1. Only used in single mode.                                                                                                                                                                                                                                                                 |
| `settings.series_amount`         | integer or string | In series mode, 2–10 images, default 4. For 5–10 images, mention every reference and keep the prompt within 20,000 characters after reference names are converted to positions. Each reference must be readable and at most 20 MB. In single mode this field is ignored and may be an integer from 2 to 10 or the string `auto`. |
| `settings.resolution`            | string            | `2k` (default) or `4k`.                                                                                                                                                                                                                                                                                                          |
| `settings.aspect_ratio`          | string            | `auto` (default), `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `3:2`, `2:3` or `21:9`.                                                                                                                                                                                                                                                   |
| `options.watermark_info.enabled` | boolean           | Optional. Only `false` is supported.                                                                                                                                                                                                                                                                                             |

## A series from a reference photograph

Replace the example URL with a public URL of your product photograph. This example requests three connected images. Keep each frame's instruction in the same prompt.

```json
{
  "model": "kling-image-4-0",
  "contents": [
    {"type": "refer_image", "url": "https://example.com/lamp.jpg", "id": "lamp"},
    {"type": "prompt", "text": "Three shots of @lamp in the same studio. Start with a wide view of the workbench, move to the brass shade, then finish on the warm reflection of the bulb in the desk."}
  ],
  "settings": {"result_type": "series", "series_amount": 3, "resolution": "4k", "aspect_ratio": "3:2"}
}
```

## Retrieve every image

Copy the `id` from the POST response into `TASK_ID`. Poll this endpoint with the same key until the task status is `completed` or `failed`.

```bash
curl "https://api.seedrouter.ai/v1/tasks/$TASK_ID" \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY"
```

On completion, read every URL in `output.data[].url`. A task can return multiple images. If a status check is interrupted, look up the original ID again. See the [task reference](https://seedrouter.ai/docs/api/tasks) for the lifecycle and the [error directory](https://seedrouter.ai/docs/api/errors) for error codes.

## Pricing

The total is the number of output images at the requested resolution multiplied by the live output rate, plus one reference-image charge per input image. Four 4K images with two references cost four 4K output charges and two reference charges. A failed request carries no charge. See the [current rates](https://seedrouter.ai/models/kling-image-4-0#pricing).

## Errors and tips

Invalid input returns a request error. Check for missing prompt text, duplicate reference IDs and unsupported resolution or series settings. If the initial call returned a task ID, query that ID before deciding whether another submission is necessary.

For a multi-reference brief, use a distinct name for each subject and tell the model which visual features each reference supplies. Place camera directions and the sequence of shots in the prompt. See the [Kling Image 4.0 playground](https://seedrouter.ai/models/kling-image-4-0#playground) and [OpenAPI schema](https://seedrouter.ai/docs/kling-image-4-0.openapi.json).
