tencent cloud

LLM Service TokenHub

Kling Image Generation API Guide

ダウンロード
フォーカスモード
フォントサイズ
最終更新日: 2026-10-20 15:21:47
AI翻訳

Overview

Kling is a series of visual generation models launched by Kuaishou. This document describes how to call the Kling image generation models Kling-Image-v3 (kling-image-v3), Kling-Image-o1 (kling-image-o1), and Kling-Image-v3-omni (kling-image-v3-omni) through TokenHub. These models support text-to-image and image-to-image generation, allowing you to generate images by combining a reference image with text prompts, or by text alone. The o1 and Omni models support multiple reference images, and Omni supports series image generation and native 4K ultra-high-definition output.

Prerequisites

You have registered a Tencent Cloud account and activated the TokenHub service.
You have obtained an API Key from the TokenHub console.
Enable postpaid billing for the corresponding model in Console - Online Inference - Vision Models.
Note:
In all examples below, YOUR_API_KEY must be replaced with your own API Key. The authentication method is the request header Authorization: Bearer YOUR_API_KEY.

Call Process

Image generation is a time-consuming task, so the API uses an asynchronous call mode, which is divided into two steps:
1. Submit a task: Call the image generation API, which returns the task task_id upon success.
2. Poll for results: Call the query task API with the task task_id (recommended every 3 to 5 seconds) until task_status = succeed, and obtain the image URLs from task_result.images.

Model List

Model Name
model Parameter Value
Supported Capability
Prompt Limit
Resolution
Kling-Image-v3
kling-image-v3
Text-to-image generation/image-to-image generation (single-image reference)
2500 characters
1K / 2K
Kling-Image-o1
kling-image-o1
Text-to-image generation/image-to-image generation (multi-image reference)
2500 characters
1K / 2K
Kling-Image-v3-omni
kling-image-v3-omni
Text-to-image generation/image-to-image generation (multi-image reference)/series image generation
2500 characters
1K / 2K / 4K
Note:
All three models support eight aspect ratios: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, and 21:9. kling-image-o1 and kling-image-v3-omni additionally support auto, which intelligently determines the aspect ratio based on the input content.

Image Generation (Kling-Image-v3)

1. API Description

The Kling-Image-v3 image generation API supports text-to-image and image-to-image (single-image reference) generation: if image is provided, image-to-image generation is performed. If not, text-to-image generation is performed based on text prompts. Both positive and negative prompts are supported.
API: POST https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/generation

2. Input Parameters

Parameter Name
Required
Type
Description
model
Yes
string
Model ID. Valid values: kling-image-v3
prompt
Yes
string
Positive text prompt, with a maximum length of 2500 characters. If image is not passed, text-to-image generation is performed based on this text.
negative_prompt
No
string
Negative text prompt, with a maximum length of 2500 characters. It is supported only for text-to-image generation; negative prompts are not supported in image-to-image generation scenarios where image is not empty.
image
No
string
Reference image (single image). If a reference image is provided, image-to-image generation is used.
Supports image URL (ensure it is accessible) or Base64 encoding. For Base64, you do not need to add the data:image/png;base64, prefix; directly pass the Base64 string itself.
element_list
No
array
Subject reference list, configured based on subject IDs in the subject library. Format: "element_list": [{"element_id": subject ID}].
The total number of reference subjects and reference images must not exceed 10.
aspect_ratio
No
string
Aspect ratio of the generated image (width:height).
Valid values: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9. Default value: 16:9.
resolution
No
string
Resolution of the generated image.
Valid values: 1k (1K standard definition), 2k (2K high definition). Default value: 1k.
n
No
integer
Number of generated images. Value range: [1, 9]. Default value: 1.
watermark_info
No
object
Whether to simultaneously generate a watermarked result. Format: "watermark_info": {"enabled": boolean}.
true indicates that a watermarked result is generated, and false indicates that it is not. Custom watermarks are not supported.

3. Request Example

# Text-to-Image / Image-to-Image
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/generation' \\
-H 'Authorization: Bearer YOUR_API_KEY' \\
-H 'Content-Type: application/json' \\
-d '{
"model": "kling-image-v3",
"prompt": "a small orange kitten sitting on a sunny windowsill",
"image": "https://example.com/input.jpg",
"aspect_ratio": "1:1",
"resolution": "2k",
"n": 3
}'
For text-to-image generation, simply omit the image field. In this case, you can also pass negative_prompt (negative prompts are not supported for image-to-image generation).

4. Output Parameters

Parameter Name
Type
Description
code
string
Error code.
message
string
Error message.
request_id
string
Request ID generated by the system, used for tracking requests and troubleshooting.
data.task_id
string
Task ID.
data.task_status
string
Task status, enumerated values: submitted (submitted), processing (processing), succeed (succeeded), failed (failed).
data.created_at
integer
Task creation time, Unix timestamp in ms.
data.updated_at
integer
Task update time, Unix timestamp in ms.

5. Response Example

{
"code": 0,
"message": "SUCCEED",
"request_id": "58b5fba6-b418-4cfa-9ecb-fa5e0406bc6d",
"data": {
"task_id": "251435731-WandImage-d59f0494e75a47d791135b1294892545",
"task_status": "submitted",
"created_at": 1790237643425,
"updated_at": 1790237643425,
"task_info": {}
}
}

Omni Image Generation (Kling-Image-o1 / Kling-Image-v3-omni)

1. API Description

The image generation APIs for Kling-Image-o1 and Kling-Image-v3-omni support text-to-image, multi-image reference image-to-image, and series image generation: if image_list (up to 10 images) is provided, multi-image reference is used, and specific reference images can be referenced in prompts via <<<image_N>>>. kling-image-v3-omni can enable series image generation through result_type and supports direct 4K ultra-high-definition output.
API: POST https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/generation

2. Input Parameters

Parameter Name
Required
Type
Description
model
Yes
string
Model ID. Valid values: kling-image-o1, kling-image-v3-omni
prompt
Yes
string
Text prompt, which can contain positive and negative descriptions, with a maximum length of 2500 characters.
In multi-image reference scenarios, you can reference a specific reference image in the prompt using the <<<image_1>>> format, for example: blend the person from <<<image_1>>> into the scene of <<<image_2>>>. If image_list is not passed, text-to-image generation is performed based on this text.
image_list
No
array[string]
Reference image list (multiple images), up to 10 images. If a reference image list is provided, multi-image reference image-to-image generation is used.
Supports image URL (ensure it is accessible) or Base64 encoding. For Base64, you do not need to add the data:image/png;base64, prefix; directly pass the Base64 string itself.
element_list
No
array
Subject reference list, configured based on subject IDs in the subject library. Format: "element_list": [{"element_id": subject ID}].
The total number of reference subjects and reference images must not exceed 10.
aspect_ratio
No
string
Aspect ratio of the generated image (width:height).
Valid values: 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9, auto (intelligently determines the aspect ratio based on the input content). Default value: auto.
Note: In text-to-image scenarios (when image_list is not passed), auto is not supported.
resolution
No
string
Resolution of the generated image.
Valid values: 1k (1K standard definition), 2k (2K high definition), 4k (4K ultra high definition). Default value: 1k.
4K is supported only by kling-image-v3-omni; kling-image-o1 supports 1K / 2K.
n
No
integer
Number of generated images. Value range: [1, 9]. Default value: 1.
This parameter is invalid when result_type is series.
result_type
No
string
Switch for toggling between single image / image series for generated results.
Valid values: single (single image, default), series (image series). Image series are supported only by kling-image-v3-omni.
series_amount
No
integer
Number of images in series mode. Takes effect only when result_type is series.
Valid values: 2 to 9, auto (intelligently selects the number based on the input content). Default value: 4.
watermark_info
No
object
Whether to simultaneously generate a watermarked result. Format: "watermark_info": {"enabled": boolean}.
true indicates that a watermarked result is generated, and false indicates that it is not. Custom watermarks are not supported.

3. Request Example

Multi-Image Reference (Kling-Image-o1)
# Text-to-Image / Multi-Image Reference Image-to-Image
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/generation' \\
-H 'Authorization: Bearer YOUR_API_KEY' \\
-H 'Content-Type: application/json' \\
-d '{
"model": "kling-image-o1",
"prompt": "put the character in <<<image_1>>> into the scene of <<<image_2>>>",
"image_list": [
"https://example.com/character.jpg",
"https://example.com/scene.jpg"
],
"resolution": "2k",
"n": 1
}'
Multi-Image Reference + Series Image Generation (Kling-Image-v3-omni)
# Text-to-Image / Multi-Image Reference Image-to-Image / Series Image Generation
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/generation' \\
-H 'Authorization: Bearer YOUR_API_KEY' \\
-H 'Content-Type: application/json' \\
-d '{
"model": "kling-image-v3-omni",
"prompt": "a small orange kitten sitting on a sunny windowsill",
"image_list": ["https://example.com/input.jpg"],
"result_type": "series",
"series_amount": 3
}'
The output parameters and response examples of the submission task are the same as those of Image Generation (Kling-Image-v3).

Querying Tasks

1. API Description

Query the status and results of an image generation task. After submitting a task and receiving the task_id, poll this API to obtain the results (recommended every 3 to 5 seconds). Once the task succeeds, obtain the single-image result from task_result.images. For series image tasks where result_type is series, obtain the results from task_result.series_images.
API: GET https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/tasks/{task_id}

2. Input Parameters

Parameter Name
Required
Type
Description
task_id
Yes
string
Task ID (path parameter), which is the task_id returned when the task is submitted.

3. Request Example

curl -X GET 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/kling-image/tasks/YOUR_TASK_ID' \\
-H 'Authorization: Bearer YOUR_API_KEY'

4. Output Parameters

Field
Type
Description
code
integer
Error code.
message
string
Error message.
request_id
string
Request ID generated by the system, used for tracking requests and troubleshooting.
tokenhub_usage
object
Usage consumption.
tokenhub_usage.total_tokens
integer
Number of tokens consumed by this task, used for billing/reconciliation.
data.task_id
string
Task ID.
data.task_status
string
Task status, enumerated values: submitted (submitted), processing (processing), succeed (succeeded), failed (failed).
data.task_status_msg
string
Task status information, which displays the failure reason when a task fails.
data.created_at
integer
Task creation time, Unix timestamp in ms.
data.updated_at
integer
Task update time, Unix timestamp in ms.
data.task_result.images[].index
integer
Image number, ranging from 0 to 9.
data.task_result.images[].url
string
URL of the generated image.
data.task_result.images[].watermark_url
string
Download URL of the watermarked image (returned when watermark_info.enabled is true).
data.task_result.series_images[].index
integer
Series image number (returned for series image tasks).
data.task_result.series_images[].url
string
URL of the series image (returned for series image tasks).

5. Response Example

{
"code": 0,
"data": {
"created_at": 1790158890000,
"task_status_msg": "",
"updated_at": 1790158935886,
"task_id": "1256342408-WandImage-7f7d37d4db5d4d308b5a0d9a8374d7fb",
"task_info": {

},
"task_result": {
"images": [
{
"index": 0,
"url": "https://xxxxx.png"
},
{
"index": 1,
"url": "https://xxxxx.png"
}
]
},
"task_status": "succeed"
},
"message": "SUCCEED",
"request_id": "6efe9620-b3c6-472d-ac36-0322d3041e87",
"tokenhub_usage": {
"total_tokens": 40000
}
}

Appendix



Error Code Descriptions

HTTP Status Code
Business Code
Business Code Definition
Business Code Description
Suggested Solution
200
0
Request succeeded
-
-
401
1000
Authentication failed
Authentication failed
Check whether Authorization is correct.
401
1001
Authentication failed
Authorization is empty.
Enter the correct Authorization in the Request Header.
401
1002
Authentication failed
Invalid Authorization value
Enter the correct Authorization in the Request Header.
401
1003
Authentication failed
Authorization is not yet valid.
Check the token's effective start time, and wait for it to take effect or reissue the token.
401
1004
Authentication failed
Authorization has expired.
Check the token's validity period and reissue it.
429
1100
Account exception
Account exception
Check the account configuration information.
429
1101
Account exception
Account overdue payment (postpaid scenario)
Top up the account to ensure sufficient balance.
429
1102
Account exception
Resource pack used up/expired (prepaid scenario)
Purchase additional resource packages, or activate the postpaid service if available.
403
1103
Account exception
No access to the requested resource, such as API/model.
Check the account permissions.
400
1200
Invalid request parameters
Invalid request parameters
Check whether the request parameters are correct.
400
1201
Invalid request parameters
Invalid parameters, such as incorrect key or invalid value.
Refer to the specific information in the message field of the response body, and modify the request parameters.
404
1202
Invalid request parameters
Invalid request method
Check the API documentation and use the correct request method.
404
1203
Invalid request parameters
The requested resource does not exist, such as the model.
Refer to the specific information in the message field of the response body, and modify the request parameters.
400
1300
Trigger Policy
Trigger platform policy
Check whether the platform policy is triggered.
400
1301
Trigger Policy
Trigger platform content security policy
Check the input content, modify it, and initiate the request again.
429
1302
Trigger Policy
API requests are too frequent, exceeding the platform rate limit.
Reduce the request frequency, retry later, or contact customer service to increase the limit.
429
1303
Trigger Policy
Concurrency or QPS exceeds the prepaid resource pack limit.
Reduce the request frequency, retry later, or contact customer service to increase the limit.
429
1304
Trigger Policy
Trigger platform IP address allowlist policy
Contact customer service.
500
5000
Internal error.
Internal server error
Retry later, or contact customer service.
503
5001
Internal error.
The server is temporarily unavailable, usually due to maintenance.
Retry later, or contact customer service.
504
5002
Internal error.
Internal server timeout, usually due to backlog.
Retry later, or contact customer service.

General Constraints on Image Assets

Reference images support .jpg, .jpeg, and .png formats. Each image must be less than or equal to 10 MB, with width and height no less than 300 px, and an aspect ratio between 1:2.5 and 2.5:1. Ensure that image URLs are accessible. For Base64 encoding, do not add the data:image/png;base64, prefix. Pass the Base64 string directly. Multi-image reference (image_list) supports up to 10 images. The total number of reference subjects and reference images must not exceed 10.

FAQs

1. What Is the Difference Between Text-to-Image and Image-to-Image?

The same API supports both modes: for kling-image-v3, passing image enables image-to-image generation, and for kling-image-o1 / kling-image-v3-omni, passing image_list enables image-to-image generation, using the image content as reference. If neither is passed, text-to-image generation is performed (generated solely from the prompt). All three models support both modes.

2. How to Generate Image Sets?

Only kling-image-v3-omni supports this: pass series in result_type and specify the number with series_amount (2 to 9 or auto, default 4). In this case, the n parameter is invalid, and the results are obtained from task_result.series_images returned by the query task.

3. When Can Negative Prompts Be Used?

Only Kling-Image-v3 supports negative_prompt, and it takes effect only in text-to-image scenarios. It is not supported for image-to-image generation (when image is passed). For Kling-Image-o1 / Kling-Image-v3-omni, you can write negative descriptions directly in prompt.

4. Do Generated Image URLs Expire?

The generated result is a temporary address that expires in 12 hours. Download and save it promptly after the task succeeds.


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック