Skip to main content

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

POSThttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation

Prerequisites

  1. Search for Kling models in the Alibaba Cloud Model Studio console and follow the on-screen instructions to activate the model service.
  2. 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"
    
  3. Obtain your workspace ID on the Workspace Management page and use it to replace {WorkspaceId} in the request endpoint.
  4. 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-TypestringRequired
The request content type. Set this header to application/json.
AuthorizationstringRequired
Authenticates the request with a Model Studio API key. Use the format Bearer <API Key>.
X-DashScope-AsyncstringRequired
Enables 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

modelstringRequired
The model ID. Set this field to kling/kling-v4-long-image-generation.
inputobjectRequired
The input content.

Properties

messagesarrayRequired
The message array. Only single-turn input is supported. The array must contain exactly one message object.

Message object properties

rolestringOptional
The message role. Set this field to user.
contentarrayRequired
The message content, including one non-empty text entry and any reference images required for the scenario.

Content object properties

textstringRequired
The prompt that describes the content, style, and layout of the long image. The content array must contain exactly one non-empty text entry.
  • English-only input: no more than 166,000 characters.
  • Non-English-only input: no more than 71,000 characters.
  • Mixed input: English character count ÷ 166,000 + non-English character count ÷ 71,000 ≤ 1.
Use <<<image_1>>> and <<<image_2>>> to reference images. The numbers correspond to the order in which the reference images appear in the content array.
imagestringConditionally required
The reference image, provided as an HTTP/HTTPS URL or Base64-encoded data.
  • skill=ecommerce: you must provide 1–3 product reference images.
  • skill=webpage: reference images are optional. You can provide up to 1 style reference image and 1 subject reference image. Use image_type to distinguish them.
Image specifications:
  • Formats: JPG, JPEG, PNG.
  • File size: no more than 30 MB.
  • Width and height: both must be at least 300 pixels.
  • Aspect ratio: 2:5–5:2.
image_typestringConditionally required
Used only for web page design. When skill=webpage and reference images are provided, each reference image must specify this field:
  • style: use the visual style and layout of the reference image.
  • subject: preserve the subject elements in the reference image and design around them.
You can provide at most one reference image of each type. Do not pass this field for e-commerce product detail pages.
Long 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.
parametersobjectRequired
The long image generation parameters.

Properties

skillstringRequired
The long image generation scenario:
  • ecommerce: generate an e-commerce product detail page.
  • webpage: generate a long image of a web page design.
lengthstringOptional
The length of the e-commerce product detail page. This parameter takes effect only when skill=ecommerce:
  • short: approximately 2–5 content modules.
  • medium: the default value, approximately 6–10 content modules.
  • long: approximately 11–18 content modules.
Each content module forms a functional section of the long image. The result is still one complete long image. This parameter has no effect on web page design.
resolutionstringOptional
The resolution level of the output long image:
  • 1k: the default value.
  • 2k.
watermarkbooleanOptional
Whether to generate an additional watermarked image:
  • false: the default value. Do not generate an additional watermarked image.
  • true: generate an additional watermarked image.
nintegerOptional
Long image generation always outputs one image. Set this parameter to 1 or omit it.
The model determines the dimensions of the long image based on its content. The parameters.aspect_ratio and parameters.result_type parameters have no effect.

Request examples

  • E-commerce product detail page
  • Web page design
This example uses one product image of a ceramic rabbit figurine to generate a complete long image with approximately 11–18 content modules.
Request
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
    }
  }'

Response parameters

outputobject
The task information.

Properties

task_statusstring
The task status. After successful submission, the status is PENDING, which means the task is queued.
task_idstring
The task ID used to query the task status and results. The ID remains valid for queries for 24 hours.
request_idstring
The unique request identifier used for request tracing and troubleshooting.
codestring
The error code returned when the request fails.
messagestring
The error description returned when the request fails.

Response examples

  • Successful submission
  • Failed submission
Save output.task_id for subsequent queries.
Response
{
  "output": {
    "task_status": "PENDING",
    "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
  },
  "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Query task results

Request endpoint

GEThttps://{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.
  • We recommend querying the task status every 5 seconds. PENDING and RUNNING mean the task is not yet complete. SUCCEEDED means the task succeeded, and FAILED means 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

AuthorizationstringRequired
Authenticates the request with a Model Studio API key. Use the format Bearer <API Key>.

Path parameters

task_idstringRequired
The task ID returned when you submitted the task.

Request example

Request
curl --request GET 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}' \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY"

Response parameters

outputobject
The task status and generation results.

Properties

task_idstring
The task ID.
task_statusstring
The task status:
  • PENDING: queued.
  • RUNNING: processing.
  • SUCCEEDED: completed successfully.
  • FAILED: failed.
  • CANCELED: canceled.
  • UNKNOWN: the task does not exist or its status is unknown.
submit_timestring
The time when the task was submitted.
scheduled_timestring
The time when the task started running.
end_timestring
The time when the task ended.
finishedboolean
Whether the task is complete.
codestring
The error code returned when task execution fails.
messagestring
The error description returned when task execution fails.
choicesarray
The model output. The array contains one result object.

Result object properties

finish_reasonstring
The reason generation stopped. The value is stop when generation completes normally.
messageobject
The message returned by the model.

Properties

rolestring
The message role. The value is always assistant.
contentarray
The generated long image content.

Content object properties

imagestring
The URL of the generated long image. Images are generated in PNG format by default. The URL is valid for 30 days. Download and save the image promptly.
watermark_imagestring
The URL of the watermarked long image. This field is returned only when watermarking is enabled and the corresponding resource is generated. Otherwise, the field is absent.
typestring
The output content type. The value is always image.
usageobject
Usage statistics for successful generation results.

Properties

sizestring
The long image dimensions in the format width*height. The model determines the dimensions based on the content.
image_countinteger
The number of successfully generated images. The value is 1 when long image generation succeeds.
SRstring
The resolution level of the generated long image. Valid values are 1k and 2k.
input_image_countinteger
The number of input reference images. The value is 0 when no reference images are provided for web page design.
skillstring
The long image generation scenario:
  • ecommerce: e-commerce product detail page.
  • webpage: web page design.
lengthstring
The length of the e-commerce product detail page. Returned only when skill=ecommerce:
  • short: short.
  • medium: medium.
  • long: long.
credits_consumednumber
Credits consumed by the task, with up to three decimal places. Credits use the same definition as on the Kling AI website.Example value: 222.4.
request_idstring
The unique request identifier used for request tracing and troubleshooting.
codestring
The error code returned when the request fails.
messagestring
The error description returned when the request fails.

Response examples

  • Task succeeded
  • Task failed
  • Query request failed
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.
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"
}

Error codes

If the model call fails and returns an error message, see Error codes for resolution.