Kling 3.0 API Integration Guide & Examples
| Endpoint | Capability | Required fields |
|---|---|---|
POST /kling/text-to-video/kling-3.0 | Text to video | prompt |
POST /kling/image-to-video/kling-3.0 | Image to video (first frame, optional last frame and elements) | contents (with a first_frame) |
GET /kling/tasks?task_ids={id} or ?external_task_ids={id} | Query a task | task_ids or external_task_ids (one of them) |
ModelGo accepts the paths and request/response shapes of Kling's official 3.0 API (settings, options, contents[], …).
With Kling's official samples, replace the API host with
https://api.modelgo.ai/klingand authenticate withAuthorization: Bearer $MODELGO_API_KEY(no Kling JWT signing).
1. Create a task
Text to video
curl https://api.modelgo.ai/kling/text-to-video/kling-3.0 \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A small red ball rolling slowly across a wooden table, soft daylight",
"settings": {"resolution": "720p", "aspect_ratio": "16:9", "duration": 5, "audio": "native"}
}'Image to video
curl https://api.modelgo.ai/kling/image-to-video/kling-3.0 \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{"type": "prompt", "text": "The puppy slowly turns its head"},
{"type": "first_frame", "url": "https://example-cdn.com/dog.jpg"}
],
"settings": {"resolution": "1080p", "duration": 5}
}'A successful create returns {"code": 0, "data": {"id": "gw_…", "status": "submitted"}}; data.id is the gateway task id used for polling and downloading.
2. Parameters
contents[] (image-to-video)
type | Fields | Description |
|---|---|---|
first_frame | url | Required, at most one. A publicly downloadable http(s) URL; inline base64 images (bare base64 or a data: URI) are not accepted and return 400 |
last_frame | url | Optional, at most one. Must be sent together with first_frame |
prompt | text | Optional, at most one, ≤ 3072 characters |
element | element_id, id | Optional, up to 3; element_id is the Kling-side subject ID; id is unique within the task, used to refer to the element in the prompt, and is forwarded upstream together with element_id |
For text-to-video, prompt is a top-level field: required, ≤ 3072 characters.
settings
| Field | Values | Description |
|---|---|---|
resolution | 720p / 1080p / 4k | Default 720p; other values return 400 |
audio | native / off | Whether to generate native audio, default off; native is billed at the audio price tier |
duration | integer 3–15 | Length in seconds, default 5 |
aspect_ratio | 16:9 / 9:16 / 1:1 | text-to-video only; image to video follows the first frame |
multi_shot | bool | Multi-shot switch, see below. A prompt written as 镜头 n, seconds, description; (镜头 is a literal marker, see below) with the field omitted is treated as true; false makes the marker ordinary prompt text |
options
watermark_info:{"enabled": true/false}; it does not change the price.callback_url: accepted but not honoured — the gateway sends no callback, poll byid.external_task_id: your own task ID, unique per API key (a reused one returns400, code1201), at most 128 characters and no commas; query it withGET /kling/tasks?external_task_ids={id}. Create and query responses carryexternal_id.
Fields outside the tables above are refused at creation (400, naming the field). When multi_shot: true, element or watermark_info.enabled: true is not currently available, creation returns 400 (provider_unsupported); these are never silently dropped.
Multi-shot
With settings.multi_shot set to true, the shots are written in prompt:
- Custom shots: write them as
镜头 n, seconds, description;— for example镜头 1, 3, a cat blinks by the window; 镜头 2, 3, the cat stretches;.镜头(Chinese for "shot") is the literal marker the upstream parser matches — type it exactly as shown; the description itself can be in any language. Shots are numbered from 1 in order, at most 6, each description ≤ 512 characters, and the shot lengths must add up tosettings.duration(default 5), otherwise creation returns400. - Automatic shots: any other prompt is split into shots by the model.
First-frame image requirements
A direct link the upstream can GET: no auth, no redirects, no dependence on Referer / Cookie; JPG / PNG, ≤ 10MB, width and height ≥ 300px, aspect ratio 1:2.5–2.5:1. A failed image fetch fails the task (status=failed) with no charge.
3. Poll a task
curl "https://api.modelgo.ai/kling/tasks?task_ids=gw_6dce033e-9243-4a64-9c57-73d08a8e379a" \
-H "Authorization: Bearer $MODELGO_API_KEY"A task created with options.external_task_id can also be queried by it:
curl "https://api.modelgo.ai/kling/tasks?external_task_ids=order-42" \
-H "Authorization: Bearer $MODELGO_API_KEY"On completion:
{
"code": 0,
"message": "SUCCEED",
"data": [
{
"id": "gw_6dce033e-9243-4a64-9c57-73d08a8e379a",
"status": "succeeded",
"outputs": [
{
"type": "video",
"url": "https://api.modelgo.ai/v1/videos/gw_6dce033e-9243-4a64-9c57-73d08a8e379a/content",
"duration": "6"
}
]
}
]
}status:submitted→processing→succeeded/failed. On failuremessagegives the reason, and the task is not charged.- Query one task per request: use either
task_idsorexternal_task_idswith a single ID (several IDs, or both parameters, return400). Only tasks created with the same API key are visible. - Generation usually takes 1–3 minutes; poll every 5–10 seconds with backoff.
outputs[].urlpoints at the gateway content endpoint and needs no credential — the link itself is the credential;durationis the delivered length in seconds.
4. Download the video
curl https://api.modelgo.ai/v1/videos/gw_6dce033e-9243-4a64-9c57-73d08a8e379a/content -o kling.mp4Returns the video/mp4 bytes and supports Range; 409 while unfinished, 404 when expired or missing.
5. Billing and error responses
- Billed by delivered video seconds (
outputs[].duration); the unit price depends on input type (text / image), tier and whether audio is generated, as shown in the console model list. A refused create (400) or a failed generation (failed) is not charged. - A failed request keeps its HTTP status, and the body matches the official shape:
{"code": 1201, "message": "…", "request_id": "…"}, wherecodeis a business code from the official error table andmessagenames the cause. A generation that fails is not a request error: it still returnscode=0with taskstatus=failed.