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.
The request content type. Set this header to Authenticates the request with a Model Studio API key. Use the format Enables asynchronous processing. Set this header to
The model ID. Set this field to kling/kling-v4-long-image-generation.The input content.
The message array. Only single-turn input is supported. The array must contain exactly one message object.
The message role. Set this field to The message content, including one non-empty text entry and any reference images required for the scenario.
The prompt that describes the content, style, and layout of the long image. The The reference image, provided as an HTTP/HTTPS URL or Base64-encoded data.Used only for web page design. When The long image generation parameters.
The long image generation scenario:The length of the e-commerce product detail page. This parameter takes effect only when The resolution level of the output long image:Whether to generate an additional watermarked image:Long image generation always outputs one image. Set this parameter to
The task information.
The task status. After successful submission, the status is The task ID used to query the task status and results. The ID remains valid for queries for 24 hours.The unique request identifier used for request tracing and troubleshooting.The error code returned when the request fails.The error description returned when the request fails.
Replace
Authenticates the request with a Model Studio API key. Use the format
The task ID returned when you submitted the task.
The task status and generation results.
The task ID.The task status:The time when the task was submitted.The time when the task started running.The time when the task ended.Whether the task is complete.The error code returned when task execution fails.The error description returned when task execution fails.The model output. The array contains one result object.
The reason generation stopped. The value is The message returned by the model.
The message role. The value is always The generated long image content.
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.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.The output content type. The value is always Usage statistics for successful generation results.
The long image dimensions in the format The number of successfully generated images. The value is The resolution level of the generated long image. Valid values are The number of input reference images. The value is The long image generation scenario:The length of the e-commerce product detail page. Returned only when 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.The unique request identifier used for request tracing and troubleshooting.The error code returned when the request fails.The error description returned when the request fails.
If the model call fails and returns an error message, see Error codes for resolution.
Create a long image generation task
Request endpoint
POST
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:
-
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.
output.task_id and then query the task results.
Request headers
Content-TypestringRequiredapplication/json.AuthorizationstringRequiredBearer <API Key>.X-DashScope-AsyncstringRequiredenable. If this header is missing, the API returns the error current user api does not support synchronous calls.Request body
modelstringRequiredinputobjectRequiredProperties
Properties
messagesarrayRequiredMessage object properties
Message object properties
rolestringOptionaluser.contentarrayRequiredContent object properties
Content object properties
textstringRequiredcontent 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.
<<<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 requiredskill=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. Useimage_typeto distinguish them.
- 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 requiredskill=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.
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.parametersobjectRequiredProperties
Properties
skillstringRequiredecommerce: generate an e-commerce product detail page.webpage: generate a long image of a web page design.
lengthstringOptionalskill=ecommerce:short: approximately 2–5 content modules.medium: the default value, approximately 6–10 content modules.long: approximately 11–18 content modules.
resolutionstringOptional1k: the default value.2k.
watermarkbooleanOptionalfalse: the default value. Do not generate an additional watermarked image.true: generate an additional watermarked image.
nintegerOptional1 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
Response parameters
outputobjectProperties
Properties
task_statusstringPENDING, which means the task is queued.task_idstringrequest_idstringcodestringmessagestringResponse examples
- Successful submission
- Failed submission
Save
output.task_id for subsequent queries.Response
Query task results
Request endpoint
GET
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}{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.
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
AuthorizationstringRequiredBearer <API Key>.Path parameters
task_idstringRequiredRequest example
Request
Response parameters
outputobjectProperties
Properties
task_idstringtask_statusstringPENDING: queued.RUNNING: processing.SUCCEEDED: completed successfully.FAILED: failed.CANCELED: canceled.UNKNOWN: the task does not exist or its status is unknown.
submit_timestringscheduled_timestringend_timestringfinishedbooleancodestringmessagestringchoicesarrayResult object properties
Result object properties
finish_reasonstringstop when generation completes normally.messageobjectProperties
Properties
rolestringassistant.contentarrayContent object properties
Content object properties
imagestringwatermark_imagestringtypestringimage.usageobjectProperties
Properties
sizestringwidth*height. The model determines the dimensions based on the content.image_countinteger1 when long image generation succeeds.SRstring1k and 2k.input_image_countinteger0 when no reference images are provided for web page design.skillstringecommerce: e-commerce product detail page.webpage: web page design.
lengthstringskill=ecommerce:short: short.medium: medium.long: long.
credits_consumednumberrequest_idstringcodestringmessagestringResponse 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