Kling 3.0 API Integration Guide & Examples

EndpointCapabilityRequired fields
POST /kling/text-to-video/kling-3.0Text to videoprompt
POST /kling/image-to-video/kling-3.0Image 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 tasktask_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/kling and authenticate with Authorization: Bearer $MODELGO_API_KEY (no Kling JWT signing).

1. Create a task

Text to video

bash
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

bash
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)

typeFieldsDescription
first_frameurlRequired, 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_frameurlOptional, at most one. Must be sent together with first_frame
prompttextOptional, at most one, ≤ 3072 characters
elementelement_id, idOptional, 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

FieldValuesDescription
resolution720p / 1080p / 4kDefault 720p; other values return 400
audionative / offWhether to generate native audio, default off; native is billed at the audio price tier
durationinteger 3–15Length in seconds, default 5
aspect_ratio16:9 / 9:16 / 1:1text-to-video only; image to video follows the first frame
multi_shotboolMulti-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 by id.
  • external_task_id: your own task ID, unique per API key (a reused one returns 400, code 1201), at most 128 characters and no commas; query it with GET /kling/tasks?external_task_ids={id}. Create and query responses carry external_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 to settings.duration (default 5), otherwise creation returns 400.
  • 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

bash
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:

bash
curl "https://api.modelgo.ai/kling/tasks?external_task_ids=order-42" \
  -H "Authorization: Bearer $MODELGO_API_KEY"

On completion:

json
{
  "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 failure message gives the reason, and the task is not charged.
  • Query one task per request: use either task_ids or external_task_ids with a single ID (several IDs, or both parameters, return 400). Only tasks created with the same API key are visible.
  • Generation usually takes 1–3 minutes; poll every 5–10 seconds with backoff.
  • outputs[].url points at the gateway content endpoint and needs no credential — the link itself is the credential; duration is the delivered length in seconds.

4. Download the video

bash
curl https://api.modelgo.ai/v1/videos/gw_6dce033e-9243-4a64-9c57-73d08a8e379a/content -o kling.mp4

Returns 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": "…"}, where code is a business code from the official error table and message names the cause. A generation that fails is not a request error: it still returns code=0 with task status=failed.