The Kling image generation model supports two tasks: text-to-image and reference image-to-image .
Model overview
Model name | Capabilities | Input modality | Output image specifications |
|---|---|---|---|
kling/kling-v3-image-generation |
| Text, image | Image resolution: 1k, 2k Aspect ratio: 16:9, 9:16, 1:1 Number of images: specified by parameter n (1–9) Image format: png |
kling/kling-v3-omni-image-generation |
| Text, image | Image resolution: 1k, 2k, 4k Aspect ratio: 16:9, 9:16, 1:1 Number of images:
Image format: png |
Prerequisites
- Activate the service: Go to the Alibaba Cloud Model Studio console, search for “Kling”, find the Kling AI model card, click Activate Now, and confirm activation and authorization in the pop-up window.
- Configure your API key: Select the region and retrieve your API key, then configure the API key as an environment variable.
HTTP invocation
Image generation takes time, typically one to two minutes. The API uses asynchronous invocation. The full process includes two core steps: Create task → Poll for results, as follows:
Step 1: Submit an image generation task
Beijing region: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/image-generation/generation
Replace {WorkspaceId} with your actual workspace ID.
Request parametersRequest headersContent-Typestring (Required)The content type of the request. Must be application/json.Authorization string (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.X-DashScope-Async string (Required)Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be enable.Request bodymodelstring (required)The model name. Valid values:
object (required)Input parameters object, containing the following fields:
Properties messages array (required)An array of request content. Only single-turn conversations are supported, so the array must contain exactly one object with the properties role and content.
Properties role string (optional)The message role. Set this parameter to user.contentarray (required)Message content, including a text prompt (text) and optional reference images (image, multiple allowed).
Properties text string(conditionally required)A positive prompt describing the desired image content, style, and composition.Supports Chinese and English. Maximum length is 2500 characters. Each Chinese character, letter, digit, or symbol counts as one character. Exceeding the limit will result in an error.Example value: A sitting orange cat with a happy expression, lively and cute, photorealistic.Note: Only one text field is allowed. Omitting it or providing multiple will cause an error.image string (optional)URL of a reference image.
array (optional)List of subjects to preserve.
Properties element_id integer (conditionally required)Required when element_list is provided. Represents the subject ID. Retrieve subject IDs from Kling - Subject ID list.Quantity limit: the total number of reference images plus reference subjects (element_list array length) must not exceed 10.object (optional)Controls image generation, such as number of images and aspect ratio.
Properties n integer (optional)Number of images to generate.
string (optional)Supported model: kling/kling-v3-omni-image-generation.Type of generated images.
integer (optional)Supported model: kling/kling-v3-omni-image-generation.Number of images in storyboard mode. Valid range 2–9. Default is 4.Takes effect only when result_type=series.aspect_ratio string (optional)Aspect ratio of the output image.
string (optional)Output image resolution.
bool (optional)Specifies whether to simultaneously generate a watermarked version of the image. The watermark appears in the bottom-right corner with fixed text “Kling AI”.
|
Supported models: kling/kling-v3-omni-image-generation and kling/kling-v3-image-generation. |
Response parametersoutputobjectTask output information.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringUnique request identifier for tracing and troubleshooting.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes. |
Save the task_id to query the task status and result. |
Step 2: Query task results
Beijing region: GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
Replace {WorkspaceId} with your actual workspace ID.
- Polling recommendation: Image generation takes several minutes. Use a polling mechanism with a reasonable interval, such as five seconds, to fetch results.
- Task status flow: PENDING (queued) → RUNNING (in progress) → SUCCEEDED (success) or FAILED (failure).
- task_id validity: 24 hours. After expiration, results cannot be retrieved and the API returns status
UNKNOWN. - RPS limit: The query endpoint has a default RPS of 20. For higher-frequency polling or event notifications, configure asynchronous task callbacks.
- Additional operations: For batch queries, task cancellation, and other operations, see Manage asynchronous tasks.
Request parametersRequest headersAuthorizationstring (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.URL path parameterstask_idstring (Required)The ID of the task. |
Replace {task_id} with the task_id value returned by the previous API call. The task_id is valid for queries for 24 hours, Replace {WorkspaceId} with your actual workspace ID. |
Response parametersoutputobjectTask output information.
Properties choices arrayModel-generated output. This array contains exactly one element.
Properties finish_reason stringReason the task stopped. Value is stop for natural completion.message objectMessage returned by the model.
Properties role stringMessage role. Always assistant.contentarray
Properties type stringType of output content. Always image.image stringURL of the generated image in PNG format. The link expires after 30 days. Download and save the image promptly.objectStatistics for successful outputs.
Properties image_count integerNumber of generated images.size stringResolution of generated images in width*height format. Example value: 1360*768.SR stringResolution tier of generated images. Example value: 1080.stringUnique request identifier for tracing and troubleshooting.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes. |
|