Kling Image Generation
curl --request POST \
--url https://api.mixroute.ai/kling/image-generation/kling-4.0import requests
url = "https://api.mixroute.ai/kling/image-generation/kling-4.0"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/kling/image-generation/kling-4.0', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mixroute.ai/kling/image-generation/kling-4.0",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mixroute.ai/kling/image-generation/kling-4.0"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mixroute.ai/kling/image-generation/kling-4.0")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/kling/image-generation/kling-4.0")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyImage Series
Kling Image Generation
Submit a Kling Image 4.0 generation task using the native contents, settings and options fields.
Kling Image Generation
curl --request POST \
--url https://api.mixroute.ai/kling/image-generation/kling-4.0import requests
url = "https://api.mixroute.ai/kling/image-generation/kling-4.0"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.mixroute.ai/kling/image-generation/kling-4.0', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mixroute.ai/kling/image-generation/kling-4.0",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.mixroute.ai/kling/image-generation/kling-4.0"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mixroute.ai/kling/image-generation/kling-4.0")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mixroute.ai/kling/image-generation/kling-4.0")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodySend a MixRoute API key as a Bearer token. Use the exact path below: the model catalog lists
Reference images and Elements share a limit of 10 inputs. To reference one explicitly, use
An accepted request returns
When the matching task reports
kling-image-4.0, but /kling/image-generation/kling-image-4.0 is not accepted. Do not add /v1, a body model field, or a metadata wrapper.
POST https://api.mixroute.ai/kling/image-generation/kling-4.0
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | Input items. Include a nonempty prompt item. |
settings | object | No | Controls image count, resolution, and aspect ratio. |
options | object | No | Optional webhook, external task ID, and watermark settings. |
Input Items
type | Other fields |
|---|---|
prompt | Required. Put the prompt in text, not a top-level prompt field. |
refer_image | Use url for a reachable image URL or Base64 image data and id for a unique reference name. |
element | Use element_id for a multi-image Element available to the routed upstream account. Set a unique reference id. |
@id in the prompt. Images must be JPG, JPEG, or PNG, at most 30 MB each; both sides must be at least 300 px and their width-to-height ratio must be between 2:5 and 5:2.
Prompt limit: up to 50,000 English characters or 21,000 non-English characters. For mixed text, the English count divided by 50,000 plus the non-English count divided by 21,000 must not exceed 1.
Settings
| Field | Type | Default | Description |
|---|---|---|---|
result_type | string | single | single returns independent images; series returns related images. |
n | integer | 1 | 1–9 images; only used when result_type is single. |
series_amount | integer / string | 4 | 2–10 images or auto; only used in series mode. auto lets the service choose the count. |
resolution | string | 2k | Choose 2k, 4k, or 8k. |
aspect_ratio | string | auto | auto, 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, or 21:9. |
Options
| Field | Type | Required | Description |
|---|---|---|---|
callback_url | string | No | Webhook URL. Use the gateway task ID from data.id for polling. |
external_task_id | string | No | Optional custom ID. It does not replace the gateway ID in task queries. |
watermark_info.enabled | boolean | No | Set to true to request a watermarked copy; defaults to false. |
Generate One Image
curl --request POST 'https://api.mixroute.ai/kling/image-generation/kling-4.0' \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"type": "prompt",
"text": "A single blue ceramic mug centered on a white table, studio product photograph."
}
],
"settings": {
"result_type": "single",
"n": 1,
"resolution": "2k",
"aspect_ratio": "1:1"
}
}'
code: 0 and a gateway task ID in data.id; it does not return the image yet.
Retrieve the Image
Copydata.id to KLING_TASK_ID. Poll with one ID per call; see Query Kling Task for statuses and errors.
curl --get 'https://api.mixroute.ai/kling/tasks' \
--header "Authorization: Bearer $MIXROUTE_API_KEY" \
--data-urlencode "task_ids=$KLING_TASK_ID"
{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "task_example",
"status": "succeeded",
"outputs": [
{
"type": "image",
"url": "https://example.com/generated.png"
}
]
}
]
}
succeeded, read the url of each type: "image" entry in outputs. Download from the result URL without forwarding your MixRoute API key.