Skip to content
API Reference

Kling Image

Kling AI's Image 4.0 models, served directly through Siraya AI. They generate images from a prompt, optionally guided by reference images. The output is a single image, a coherent set of images, or one tall page image.

POST https://llm.siraya.ai/v1/images/generations

Supported Models

Model ID Description
kling-image-4.0 Kling Image 4.0: text-to-image and reference-guided generation, as one image or a series. Resolution tiers 1k, 2k (default) and 4k
kling-image-4.0-long Kling Image 4.0 long image: one tall web page or e-commerce detail page. Default resolution 1k. See Long image

The call is synchronous: it waits for Kling to finish and returns the images. A single 2K image typically takes under a minute. A four-image series or a long image takes about four minutes. For long jobs, send async: true with a callbackUrl. See Asynchronous generation.

Request Parameters

Parameter Type Required Details
Authorization string Yes Your API Key (e.g., Bearer <API_KEY>)

Body

Parameter Type Required Details
model string Yes kling-image-4.0 or kling-image-4.0-long
prompt string Yes, here or as a prompt entry in contents Text description of the image. Reference images can be named in it by their id (@image_1), see contents below
resolution string No 1k, 2k or 4k. Default 2k (1k on kling-image-4.0-long)
aspect_ratio string No Frame ratio, e.g. 1:1, 16:9, 9:16. The accepted values are Kling's own for this model
n integer No Number of images for a single-image request
result_type string No series generates a coherent set of images (shared subject and style) instead of independent ones
series_amount integer or "auto" No How many images a series contains, or auto to let the model decide. Read only when result_type is series
skill, length string No Long-image page type and length, see Long image
image string or array No Reference image URL, or an array of them. Each one is sent to Kling as a refer_image
image_list array No More reference images, each {"image": "<url>"}. Added after those in image
watermark_info object No {"enabled": true} also produces a watermarked copy of each image, returned as data[].watermark_url; the main image is unchanged
contents array No Kling's own material list, see below
settings, options object No Kling's own settings / options objects, accepted as written. A platform field above that sets the same key wins
async boolean No true returns immediately and delivers the result to callbackUrl
callbackUrl string With async The URL the platform POSTs the result to

Kling's own material list. contents takes Kling's entry types directly: prompt, refer_image, style_refer_image, subject_refer_image and element. Use it when a reference needs a role other than a plain reference image, or an id for the prompt to refer to:

"contents": [
  {"type": "subject_refer_image", "url": "https://example.com/character.png", "id": "image_1"},
  {"type": "style_refer_image",   "url": "https://example.com/style.png",     "id": "image_2"}
]

A top-level prompt takes precedence over a prompt entry in contents. References sent in image / image_list replace any refer_image entries in contents, and take over their ids in order, so @id in the prompt still resolves.

Refused parameters. OpenAI-style image fields have no meaning here and are rejected with a 400 that names the field: size (use aspect_ratio and resolution), quality, style, response_format, background, output_format, output_compression, moderation, user, sequential_image_generation, seed, negative_prompt and image_urls (use image). The following are also refused, including inside settings or options:

  • extra_body: send its keys at the top level instead.
  • callback_url and external_task_id: the result comes back on the response (use the platform's async and callbackUrl for a webhook).
  • Any key not listed above.

POST /v1/images/edits is not available for these models. Send the reference image as image on /v1/images/generations.

Code Examples

Text to image

curl https://llm.siraya.ai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "kling-image-4.0",
    "prompt": "Anime cel-shaded sticker of a detective evidence bag holding a small daisy, pure white background, bold clean outlines, flat colors, no text",
    "aspect_ratio": "1:1",
    "resolution": "2k"
  }'
import requests

url = "https://llm.siraya.ai/v1/images/generations"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <API_KEY>",
}
data = {
    "model": "kling-image-4.0",
    "prompt": "Anime cel-shaded sticker of a detective evidence bag holding a small daisy, pure white background, bold clean outlines, flat colors, no text",
    "aspect_ratio": "1:1",
    "resolution": "2k",
}

response = requests.post(url, headers=headers, json=data, timeout=600)
print(response.json()["data"][0]["url"])

Reference-guided series

curl https://llm.siraya.ai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "kling-image-4.0",
    "prompt": "The character from @image_1 in four scenes: at a desk, in the rain, on a train, at sunrise",
    "result_type": "series",
    "series_amount": 4,
    "aspect_ratio": "16:9",
    "contents": [
      {"type": "subject_refer_image", "url": "https://example.com/character.png", "id": "image_1"}
    ],
    "async": true,
    "callbackUrl": "https://your-app.com/webhooks/siraya-image"
  }'

Long image

kling-image-4.0-long lays out one tall image: a web page, or an e-commerce product detail page. It uses the same endpoint and parameters as kling-image-4.0, plus two that set the page:

Parameter Type Details
skill string webpage or ecommerce: the kind of page to lay out
length string ecommerce only: short, medium (default) or long

Both can also be written inside Kling's settings. resolution defaults to 1k. The response names the page type in mode (long_image_webpage or long_image_ecommerce) and, for an e-commerce page, the length it was generated at in length.

curl https://llm.siraya.ai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <API_KEY>" \
  -d '{
    "model": "kling-image-4.0-long",
    "prompt": "Product detail page for a waterproof hiking boot: hero shot, materials, sizing chart, care instructions",
    "skill": "ecommerce",
    "length": "medium",
    "image": "https://example.com/boot.png",
    "async": true,
    "callbackUrl": "https://your-app.com/webhooks/siraya-image"
  }'

Response

{
    "created": 1796052001,
    "model": "kling-image-4.0",
    "resolution": "2k",
    "mode": "image",
    "data": [
        { "url": "https://.../image.png?Expires=...&Signature=..." }
    ],
    "usage": { "generated_images": 1 }
}
Field Meaning
created Unix time the Kling task was created, in seconds
model The model ID you sent
resolution The resolution tier the request ran at: what you sent, or the model's default when omitted. It names a tier, not a pixel measurement (a 1:1 2k image is 2048×2048)
mode image for single images, image_set for a series, long_image_webpage or long_image_ecommerce for a long image
length Long e-commerce images only: the page length used
data[].url A generated image. The link is signed and expires, so copy the file somewhere durable
data[].watermark_url The watermarked copy, when watermark_info.enabled was true
data[].group_id Groups the images of one series
usage.generated_images Number of images returned
usage.input_images Reference images sent (each refer_image, style_refer_image, subject_refer_image or element entry). Absent when there were none

Asynchronous generation

With async: true and a callbackUrl, the request returns at once with an id and status: "processing". When Kling finishes, the platform POSTs to callbackUrl a body equal to the response above plus that id and "status": "completed". Images arrive as data[].url links, not base64. There is no poll endpoint for images, so callbackUrl is required. See Asynchronous generation for the general flow and the failure callback.