Kling Image 4.0
Generate 2K and 4K stills and related image series with Kling Image 4.0 on reAPI. See request parameters, examples, task results, and billing.
Generate 2K or 4K stills from a prompt and optional reference images, then retrieve the task's results. See the Kling Image 4.0 pricing table for current rates.
Quick example
These requests make one square 2K image and return a task ID.
curl https://reapi.ai/api/v1/images/generations \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "kling-image-4-0",
"contents": [{"type": "prompt", "text": "An amber glass teapot on blue slate in soft side light."}],
"settings": {"resolution": "2k", "aspect_ratio": "1:1"}
}'import requests
response = requests.post(
"https://reapi.ai/api/v1/images/generations",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "kling-image-4-0",
"contents": [{"type": "prompt", "text": "An amber glass teapot on blue slate in soft side light."}],
"settings": {"resolution": "2k", "aspect_ratio": "1:1"},
},
timeout=30,
)
response.raise_for_status()
print(response.json()["id"])const response = await fetch("https://reapi.ai/api/v1/images/generations", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_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 soft side light." }],
settings: { resolution: "2k", aspect_ratio: "1:1" },
}),
});
if (!response.ok) throw new Error(await response.text());
console.log((await response.json()).id);package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
)
func main() {
body := `{"model":"kling-image-4-0","contents":[{"type":"prompt","text":"An amber glass teapot on blue slate in soft side light."}],"settings":{"resolution":"2k","aspect_ratio":"1:1"}}`
req, err := http.NewRequest("POST", "https://reapi.ai/api/v1/images/generations", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Timeout: 30 * time.Second}
response, err := client.Do(req)
if err != nil {
panic(err)
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
message, _ := io.ReadAll(response.Body)
panic(string(message))
}
var task struct{ ID string }
if err := json.NewDecoder(response.Body).Decode(&task); err != nil {
panic(err)
}
fmt.Println(task.ID)
}Endpoint
Send JSON to POST https://reapi.ai/api/v1/images/generations with Authorization: Bearer YOUR_API_KEY and Content-Type: application/json. The response is JSON.
Parameters
| Field | Type | Requirement and default |
|---|---|---|
model | string | Required. Set to kling-image-4-0. |
contents | array | Required. Include one prompt and up to ten reference images. |
contents[].type | string | Required. Use prompt for the text or refer_image for a reference. |
contents[].text | string | Required for prompt. Up to 50,000 English characters or 21,000 non-English characters. Mixed text uses the sum of the two fractions of those limits. |
contents[].url | string | Required for refer_image. A reachable HTTP(S) URL to a JPEG or PNG. Each side must be at least 300 pixels and the ratio must be from 2:5 to 5:2. Maximum 30 MB per image, or 20 MB for a series of five or more. |
contents[].id | string | Optional unique reference name. Mention it in the prompt as @name. Positional references such as @Image1 also work. |
settings.result_type | string | Optional. single by default, or series. |
settings.n | integer | Optional. 1–9 independent images, default 1. Applies in single mode. |
settings.series_amount | integer or string | Optional. 2–10 images in a series, default 4. Single mode ignores this field and accepts 2–10 or auto when provided. |
settings.resolution | string | Optional. 2k by default, or 4k. |
settings.aspect_ratio | string | Optional. auto by default, or 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9. |
options.watermark_info.enabled | boolean | Optional. The supported value is false. |
webhook_url | string | Optional reAPI callback. See task webhooks. |
Single and series mode
Use single to return independent candidates. Use series for related stills with a shared brief. For a series of five or more images, mention every reference. The prompt can contain up to 20,000 characters after the reference names are converted to positions.
{
"model": "kling-image-4-0",
"contents": [
{"type": "refer_image", "url": "https://example.com/teapot.jpg", "id": "teapot"},
{"type": "prompt", "text": "A series of three studio photographs of @teapot on blue slate. Start with a front three-quarter view, then show the handle in profile, and finish on the glass rim with light passing through it."}
],
"settings": {
"result_type": "series",
"series_amount": 3,
"resolution": "2k",
"aspect_ratio": "3:2"
}
}Replace the example URL with your image before submitting.
Pricing and billing
The pricing table lists the two output rates and the cost of each input reference. Every reference, including the first, is charged once on a successful task.
- Estimate the total in USD as
requested output count × output rate + input reference count × reference rate. - The reserve is that total rounded to the billing quantum and then rounded up to whole credits. One credit is $0.001.
- On completion, the same formula uses the delivered output count. Rates are locked to the pricing snapshot at submission. The total is rounded once to the nearest two microdollars, then the difference from the reserve is returned to the wallet.
- A failed generation without delivered output releases its reserve.
Output
The POST response contains id, model, status, and created_at. Use the same API key to poll GET /api/v1/tasks/{id}. On completed, read the full list from output.image_urls. Copy images you need to retain to your own storage.
{
"id": "task_example",
"model": "kling-image-4-0",
"status": "completed",
"output": {"image_urls": ["https://example.com/image.png"]}
}Errors
See the reAPI error catalog for the full list.
| Code | What to check |
|---|---|
10001, 10003 | Provide a valid API key. |
20002, 20003 | Check required fields and use a supported resolution and image count. |
30001, 30002 | Check your balance or retry after pricing becomes available. |
40001 | Confirm the task ID and use the key from the account that submitted it. |
50001, 50002 | Wait for rate limits to clear or for in-flight tasks to finish. |
80006, 80007 | Review the task error for a policy rejection or invalid input. |
Tips
- For a series, put shared product details first and list the shots in order in a single prompt.
- Give each reference a job. Identify which image supplies the subject, background, or light.
- Start with one 2K output. Review the result's shape and product details before requesting a larger set.
- If a poll fails, look up the original task ID again before considering a fresh generation.