# Kling Image Generation

OpenAI compatible: `POST /v1/images/generations`. Native paths: `/v1/images/generations`, `/v1/images/omni-image`.

---

## 1. Submit Image Generation Task Examples (POST)

* **HTTP Method**: `POST`
* **Request Path**: `https://www.tokenpad.ai/v1/images/generations`
* **Auth Header**: `Authorization: Bearer sk-your_token`

### A. Classic Text-to-Image (with Aspect Ratio & Negative Prompt)

You can control generation results by specifying aspect ratio, resolution, and negative prompts.

```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-v3-omni",
    "prompt": "Bustling city street on a rainy night with neon lights reflecting off wet pavement, realistic sci-fi style, cinematic low-light look, 4K resolution",
    "negative_prompt": "low quality, blurry, broken anatomy, distorted, ugly",
    "ratio": "16:9",
    "resolution": "1k",
    "n": 1,
    "response_format": "url"
  }'
```

### B. Image-to-Image & Multi-Subject Reference (Image-to-Image / Subject Image)

Pass `image` / `image_urls` for image-to-image or subject reference (1 image for image-to-image, multiple for subject reference).
```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-v3-omni",
    "prompt": "Redraw the cartoon character design from image 1 and blend it into the background while keeping the pose consistent",
    "image_urls": [
      "https://example.com/assets/cartoon_char.png",
      "https://example.com/assets/background_scene.png"
    ],
    "ratio": "3:4",
    "n": 1
  }'
```

---

## 2. Complete Parameter Dictionary

| Parameter | Type | Required | Default | Description & Constraints |
| :--- | :--- | :--- | :--- | :--- |
| `model` | `string` | **Yes** | - | Image generation model, e.g., `kling-v3-omni`. |
| `prompt` | `string` | **Yes** | - | Image description prompt, up to 2,000 characters. |
| `negative_prompt` | `string` | No | - | Negative prompt. |
| `ratio` / `aspect_ratio` | `string` | No | `"1:1"` | Aspect ratio. Options: `"1:1"`, `"16:9"`, `"9:16"`, `"4:3"`, `"3:4"`. |
| `resolution` / `size` | `string` | No | `"1k"` | Target resolution, e.g., `"1k"`. |
| `image` | `string / array` | No | - | Reference image URL (string or array). |
| `image_urls` | `array` | No | - | Array of reference image URLs. |
| `n` | `integer` | No | `1` | Number of images to generate, typically `1`–`4`. |
| `watermark` | `boolean` | No | `false` | Whether to add a watermark. |
| `response_format` | `string` | No | `"url"` | `"url"` or `"b64_json"`. |

---

## 3. Response Example (200 OK)

```json
{
  "created": 1719441600,
  "data": [
    {
      "url": "https://example.com/output/img_kling_city.png"
    }
  ]
}
```



### 5. Common Error Codes & Troubleshooting

HTTP codes, error body format, and troubleshooting are **maintained in one dedicated page** (not duplicated under each example).

👉 **[Gateway Error Codes & Troubleshooting](/docs/errors/error-codes)**

**Quick reference**:

| Code | Meaning |
| :---: | :--- |
| **400** | Invalid parameters / content moderation or copyright block |
| **402** | Insufficient account balance (**not** 429) |
| **429** | RPS/RPM limits or in-flight task cap (low balance) |
| **403** | Token / IP / model permission (balance → 402; content filter → 400) |
| **200 + `status: failed`** | Async video/long-task business failure on poll |

HTTP status matches call log `status_code` for traceability by `log_id`.

> **Maintenance**: update the `error-codes` article only; this appendix links to it.
