Kling Image 4.0 Image Generation
Generate or edit a single image with Kling Image 4.0 at 2K, 4K, or 8K
Note for users in mainland China: Please use https://toapis.cn as the API endpoint (Base URL). Replace https://toapis.com with https://toapis.cn in the examples in this document.
Use kling-image-4.0 to create an image from text, or edit and combine content from up to 10 reference images. Each asynchronous request produces one image at 2K, 4K, or 8K.
Authorizations
AuthorizationstringheaderrequiredAll endpoints require Bearer Token authentication
Get your API Key from the API Key Management Page
Add to request header:
Authorization: Bearer YOUR_API_KEYBody
Send an application/json request with the following fields at the top level.
modelstringbodyrequireddefault: kling-image-4.0Set this to kling-image-4.0.
promptstringbodyrequiredDescribe the image to generate or the changes to make to the reference images. Supply non-blank text.
resolutionstringbodydefault: 2KOutput resolution tier. Accepts 2K, 4K, or 8K, regardless of case.
aspect_ratiostringbodydefault: autoOutput aspect ratio. With auto, the model chooses the ratio. Supported fixed ratios are 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9.
sizestringbodyAlias for aspect_ratio with the same allowed values. If you send both fields, their values must match.
nintegerbodydefault: 1Number of images to generate. This is fixed at 1. Omit this field or set it to the integer 1.
image_urlsstring[]bodyUp to 10 reference images. Use @image_1, @image_2, and so on in the prompt to describe each image's role in array order. Each entry must be an HTTP or HTTPS image URL the service can reach. For local files, use the Upload Image API to get a URL.
Use JPG, JPEG, or PNG files up to 30 MB each. Both dimensions must be at least 300 pixels, with an aspect ratio between 2:5 and 5:2.
reference_imagesstring[]bodyAlias for image_urls. Send either field.
callback_urlstringbodyOptional callback URL for the finished task. With a configured Token task webhook, the URL must use the same scheme, host, and port as the default URL. Omit this field to use the Token's enabled default.
Parameter limitations
This endpoint produces a single standard image. Leave out the native Kling fields contents, options, settings, result_type, and series_amount.
Query the task
Use the returned id and the same API key to query the image task. Keep polling while the status is queued or in_progress. On completed, read the image URL from result.data[0].url. On failed, check error.
curl "https://toapis.com/v1/images/generations/TASK_ID" \
-H "Authorization: Bearer $TOAPIS_API_KEY"Billing
Billing is per request. The rate depends on the account's pricing region and the resolution tier. Aspect ratio and reference count do not affect the rate. See actual cost and task usage.
Response
idstringUnique task identifier for status queries
objectstringObject type, always generation.task
modelstringModel name used
statusstringqueued when the request is accepted.
progressintegerTask progress percentage (0-100)
created_atintegerTask creation timestamp (Unix timestamp)
metadataobjectTask metadata
result.data[].urlstringURL of the single image in a completed task.
Set the TOAPIS_API_KEY environment variable before running these examples. Replace the example.com reference placeholders with accessible image URLs.
requestExample
curl --request POST \
--url https://toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "kling-image-4.0",
"prompt": "A red and white lighthouse on a rocky coast. Morning sidelight catches the spray as the sea fog lifts.",
"resolution": "2K",
"aspect_ratio": "16:9"
}'curl --request POST \
--url https://toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "kling-image-4.0",
"prompt": "Place the desk lamp from @image_1 in the study shown in @image_2. Keep the lamp shape and finish, and match the light and shadows in the room.",
"resolution": "4K",
"aspect_ratio": "4:3",
"image_urls": [
"https://example.com/lamp.png",
"https://example.com/study.jpg"
]
}'responseExample
{
"id": "tsk_img_example",
"object": "generation.task",
"model": "kling-image-4.0",
"status": "queued",
"progress": 0,
"created_at": 1794960000,
"metadata": {}
}{
"id": "tsk_img_example",
"object": "generation.task",
"model": "kling-image-4.0",
"status": "completed",
"progress": 100,
"created_at": 1794960000,
"result": {
"type": "image",
"data": [
{
"url": "https://example.com/generated/kling-image-4.0.png"
}
]
}
}