Skip to content

kling-v2-1 图片生成

说明

异步任务接口,用于提交kling 2.1 文生图任务,具体生成进度与结果请通过任务查询接口获取。

请求地址

http
POST /open/v1/ai_creation/task/submit
http
access_token: {{access_token}}
Content-Type: application/json

请求参数 Body

json
{
  "ref_img_url": [
    "https://res.chanjing.cc/chanjing/res/aigc_creation/photo/xxx.jpg"
  ],
  "ref_prompt": "少女风时尚海报,柔光,杂志封面质感",
  "creation_type": 3,
  "aspect_ratio": "3:4",
  "clarity": 2048,
  "number_of_images": 1,
  "model_code": "kling-v2-1"
}

参数说明

字段类型是否必传示例说明
ref_img_urlarray<string>["https://res.chanjing.cc/chanjing/res/aigc_creation/photo/xxx.jpg"]参考图 URL 列表,只支持传 1 张
ref_promptstring少女风时尚海报,柔光,杂志封面质感图片生成提示词
creation_typeint3创作类型,图片生成为 3
aspect_ratiostring9:16输出图片宽高比,例如 1:13:44:39:1616:9,默认 1:1
clarityint2048图片清晰度,仅支持 1k1024、2k2048,默认 1024(1k)
number_of_imagesint1本次任务生成图片数量,1-4张
model_codestringkling-v2-1模型编码,可灵 2.1 固定为 kling-v2-1

可灵 2.1 不支持参考图参数 ref_img_url

响应示例

json
{
  "trace_id": "96afa792520b0e6a86d72e89435bc0a7",
  "code": 0,
  "msg": "success",
  "data": "a60747d7-dc05-4afc-b2ef-ee4370ed53c6"
}

响应字段说明

字段说明
code响应状态码
msg响应信息
trace_id请求链路追踪 ID
data提交的创作 ID

响应状态码说明

code说明
0响应成功
400传入参数格式错误
10400AccessToken 验证失败
40000参数错误
40001超出 QPS 限制
50000系统内部错误

示例代码

shell
curl --location --request POST 'https://www.chanjing.cc/open/v1/ai_creation/task/submit' \
--header 'access_token: {{access_token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "ref_prompt": "生成一张微缩模型风格的创意场景图。画面中央是一个古典青花瓷碗,碗里盛着雪白的汤圆,最上面一颗破皮流出黑芝麻馅。",
    "creation_type": 3,
    "aspect_ratio": "9:16",
    "clarity": 2048,
    "number_of_images": 1,
    "model_code": "kling-v2-1"
}'
go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	url := "https://www.chanjing.cc/open/v1/ai_creation/task/submit"
	method := "POST"

	payload := strings.NewReader(`{
    "ref_prompt": "生成一张微缩模型风格的创意场景图。画面中央是一个古典青花瓷碗,碗里盛着雪白的汤圆,最上面一颗破皮流出黑芝麻馅。",
    "creation_type": 3,
    "aspect_ratio": "9:16",
    "clarity": 2048,
    "number_of_images": 1,
    "model_code": "kling-v2-1"
}`)

	client := &http.Client{}
	req, err := http.NewRequest(method, url, payload)
	if err != nil {
		fmt.Println(err)
		return
	}

	req.Header.Add("access_token", "{{access_token}}")
	req.Header.Add("Content-Type", "application/json")

	res, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer res.Body.Close()

	body, err := io.ReadAll(res.Body)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(string(body))
}
java
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"ref_prompt\": \"生成一张微缩模型风格的创意场景图。画面中央是一个古典青花瓷碗,碗里盛着雪白的汤圆,最上面一颗破皮流出黑芝麻馅。\",\n    \"creation_type\": 3,\n    \"aspect_ratio\": \"9:16\",\n    \"clarity\": 2048,\n    \"number_of_images\": 1,\n    \"model_code\": \"kling-v2-1\"\n}");
Request request = new Request.Builder()
  .url("https://www.chanjing.cc/open/v1/ai_creation/task/submit")
  .method("POST", body)
  .addHeader("access_token", "{{access_token}}")
  .addHeader("Content-Type", "application/json")
  .build();
Response response = client.newCall(request).execute();
py
import requests
import json

url = "https://www.chanjing.cc/open/v1/ai_creation/task/submit"

payload = json.dumps({
  "ref_prompt": "生成一张微缩模型风格的创意场景图。画面中央是一个古典青花瓷碗,碗里盛着雪白的汤圆,最上面一颗破皮流出黑芝麻馅。",
  "creation_type": 3,
  "aspect_ratio": "9:16",
  "clarity": 2048,
  "number_of_images": 1,
  "model_code": "kling-v2-1"
})
headers = {
  'access_token': '{{access_token}}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)