Kling - Long Image Generation API Reference
Generate long images for e-commerce product detail pages or web page designs with Kling. Learn how to create asynchronous tasks, set parameters, and query results.
Supported model: kling/kling-v4-long-image-generation. Each task generates one complete long image. The content modules in an e-commerce product detail page are not returned as separate images.
Create a long image generation task
Request endpoint
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generationPrerequisites
-
Search for Kling models in the Alibaba Cloud Model Studio console and follow the on-screen instructions to activate the model service.
-
Obtain an API key for the Beijing region on the API Key Management page. The following curl examples use Bash. First, set the API key as an environment variable:
export DASHSCOPE_API_KEY="YOUR_API_KEY" -
Obtain your workspace ID on the Workspace Management page and use it to replace
{WorkspaceId}in the request endpoint. -
Prepare reference images that meet the specifications below. You can use HTTP/HTTPS URLs or Base64-encoded data. Product images are required for e-commerce product detail pages. Reference images are optional for web page designs. The request examples below include reference image URLs, which you can replace with your own.
Long image generation is asynchronous and typically takes 2–5 minutes. After submitting a task, save output.task_id and then query the task results.
Request headers
Content-TypestringRequiredThe request content type. Set this header to application/json.
AuthorizationstringRequiredAuthenticates the request with a Model Studio API key. Use the format Bearer <API Key>.
X-DashScope-AsyncstringRequiredEnables asynchronous processing. Set this header to enable. If this header is missing, the API returns the error current user api does not support synchronous calls.
Request body
modelstringRequiredThe model ID. Set this field to kling/kling-v4-long-image-generation.
inputobjectRequiredThe input content.
NoteLong image generation does not support the input.element_list subject list. Passing this parameter returns InvalidParameter. For web page design, specify a subject reference image with image and image_type=subject in content.
parametersobjectRequiredThe long image generation parameters.
Request examples
E-commerce product detail page
This example uses one product image of a ceramic rabbit figurine to generate a complete long image with approximately 11–18 content modules.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "kling/kling-v4-long-image-generation",
"input": {
"messages": [
{
"role": "user",
"content": [
{"text": "Create an e-commerce product detail page for the product in <<<image_1>>>, showcasing its appearance, feature details, and use cases"},
{"image": "https://wanx.alicdn.com/material/20250318/description_edit_with_mask_3.jpeg"}
]
}
]
},
"parameters": {
"skill": "ecommerce",
"length": "long",
"resolution": "1k",
"watermark": false
}
}'
Web page design
This example uses a city photo as the style reference and a ceramic rabbit product image as the subject reference. You can also omit reference images and generate a long image of a web page design using only a prompt.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "kling/kling-v4-long-image-generation",
"input": {
"messages": [
{
"role": "user",
"content": [
{"text": "Design the homepage of a ceramic figurine brand website using the architectural lines and cool colors in <<<image_1>>>, with <<<image_2>>> as the product reference"},
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260310/rdsgaa/image+%2815%29.png", "image_type": "style"},
{"image": "https://wanx.alicdn.com/material/20250318/description_edit_with_mask_3.jpeg", "image_type": "subject"}
]
}
]
},
"parameters": {
"skill": "webpage",
"resolution": "1k"
}
}'
Response parameters
outputobjectThe task information.
request_idstringThe unique request identifier used for request tracing and troubleshooting.
codestringThe error code returned when the request fails.
messagestringThe error description returned when the request fails.
Response examples
Successful submission
Save output.task_id for subsequent queries.
{
"output": {
"task_status": "PENDING",
"task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
},
"request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
Failed submission
The following example illustrates a parameter validation error. An e-commerce product detail page requires 1–3 product reference images.
{
"request_id": "a4d78a5f-655f-9639-8437-xxxxxx",
"code": "InvalidParameter",
"message": "ecommerce long image requires 1 to 3 reference images"
}
Query task results
Request endpoint
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}Replace {WorkspaceId} with your actual workspace ID and {task_id} with the output.task_id returned when you submitted the task.
Note
- We recommend querying the task status every 5 seconds.
PENDINGandRUNNINGmean the task is not yet complete.SUCCEEDEDmeans the task succeeded, andFAILEDmeans it failed. - The task ID remains valid for queries for 24 hours. After it expires, the API returns
UNKNOWN. - The query API has a default RPS limit of 20. For batch queries, cancellation, and callback configuration for asynchronous tasks, see Manage asynchronous tasks and Asynchronous task event notifications.
Request headers
AuthorizationstringRequiredAuthenticates the request with a Model Studio API key. Use the format Bearer <API Key>.
Path parameters
task_idstringRequiredThe task ID returned when you submitted the task.
Request example
curl --request GET 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response parameters
outputobjectThe task status and generation results.
usageobjectUsage statistics for successful generation results.
request_idstringThe unique request identifier used for request tracing and troubleshooting.
codestringThe error code returned when the request fails.
messagestringThe error description returned when the request fails.
Response examples
Task succeeded
The following illustrates a successful response for an e-commerce product detail page using three reference images, 2k resolution, and long length. The generated URL, dimensions, and timestamps depend on the actual response.
{
"output": {
"task_id": "2c502d25-12a9-4517-8972-xxxxxx",
"task_status": "SUCCEEDED",
"submit_time": "2026-12-03 10:00:00.000",
"scheduled_time": "2026-12-03 10:00:01.000",
"end_time": "2026-12-03 10:03:00.000",
"finished": true,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://YOUR_RESULT_HOST/long-image.png",
"type": "image"
}
]
}
}
]
},
"usage": {
"size": "2048*47565",
"image_count": 1,
"SR": "2k",
"input_image_count": 3,
"skill": "ecommerce",
"length": "long",
"credits_consumed": 222.4
},
"request_id": "95146d89-9d70-481a-8c16-xxxxxx"
}
Task failed
The following illustrates a failed task. The failure details are returned in output.code and output.message.
{
"output": {
"task_id": "2c502d25-12a9-4517-8972-xxxxxx",
"task_status": "FAILED",
"code": "DataInspectionFailed",
"message": "Output data may contain inappropriate content."
},
"request_id": "95146d89-9d70-481a-8c16-xxxxxx"
}
Query request failed
The following example illustrates a failed query request. Use code and message to troubleshoot the error. A request error does not indicate the task result; check output.task_status to determine whether the task failed.
{
"code": "InvalidApiKey",
"message": "No API-key provided.",
"request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}
Error codes
If the model call fails and returns an error message, see Error codes for resolution.