The Kling image generation model supports two tasks: text-to-image and reference image-to-image.
This document applies only to the China (Beijing) region. Use an API key from this region.
Alibaba Cloud Model Studio has released a workspace-specific domain for the China (Beijing) region: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com. The new dedicated domain delivers superior performance and higher stability for inference requests. We recommend migrating from https://dashscope.aliyuncs.com to the new domain.
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.
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 parameters |
Text-to-imageSupported models:
Image-to-image (storyboard mode)Supported model: Supports the following modes:
|
Request headers |
|
|
Content-Type The content type of the request. Must be |
|
|
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. |
|
|
X-DashScope-Async Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be Important
If this request header is missing, the error "current user api does not support synchronous calls" is returned. |
|
Request body |
|
|
model The model name. Valid values:
|
|
|
input Input parameters object, containing the following fields: parameters Controls image generation, such as number of images and aspect ratio. |
Response parameters |
Successful responseSave the
Error responseTask creation failed. See Error codes.
|
|
output Task output information. |
|
|
request_id Unique request identifier for tracing and troubleshooting. |
|
|
code Error code. Returned only for failed requests. See Error codes. |
|
|
message Detailed error message. Returned only for failed requests. See Error codes. |
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 parameters |
Query task resultsReplace |
Request headers |
|
|
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. |
|
URL path parameters |
|
|
task_id The ID of the task. |
Response parameters |
Task succeeded
Task failedIf the task fails for any reason, the response includes error details in the code and message fields. See Error messages for troubleshooting.
|
|
output Task output information. |
|
|
usage Statistics for successful outputs. |
|
|
request_id Unique request identifier for tracing and troubleshooting. |
|
|
code Error code. Returned only for failed requests. See Error codes. |
|
|
message Detailed error message. Returned only for failed requests. See Error codes. |
Error codes
If the model call fails and returns an error message, see Error codes for resolution.