---
title: "Generate a Kling 4.0 video"
method: POST
path: "/api/v1/video/kling4"
tags: ["Video"]
---

# Generate a Kling 4.0 video

`POST /api/v1/video/kling4`

## Request

- Base URL: `https://www.seedance2ai.io`
- URL: `https://www.seedance2ai.io/api/v1/video/kling4`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/seedance2ai/apis/seedance-2-0-ai-public-api/docs/api/v1/video/kling4/post.ts> (a function with typed inputs; its response is checked against the schema)

type reference-to-video covers text-only prompts and reference images, videos, subjects (elements), and voices. type keyframe-to-video interpolates between a first frame, optional middle frames, and a last frame.

Rules: at most 15 references in total and at most 5 videos per request; reference videos and video subjects together are capped at 30 seconds. A keyframe request allows at most duration + 1 frames, up to 10. Refer to references in the prompt by name (@image_1, @video_1, a subject's or voice's name, @first_frame, @keyframe_1, @last_frame); a mention that matches no reference is rejected before charging.

## Headers

- `Idempotency-Key` string

## Request body

- union
  - object
    - `type` 'keyframe-to-video', required
    - `prompt` string, required
    - `duration` integer
    - `resolution` '720p' | '1080p'
    - `aspect_ratio` 'auto' | '16:9' | '9:16' | '1:1' | '21:9'
    - `first_frame_url` string, uri: A publicly reachable https URL. asset:// URLs are not accepted.
    - `keyframe_urls` string[]
    - `last_frame_url` string, uri: A publicly reachable https URL. asset:// URLs are not accepted.
  - object
    - `type` 'reference-to-video', required
    - `prompt` string, required
    - `duration` integer
    - `resolution` '720p' | '1080p'
    - `aspect_ratio` 'auto' | '16:9' | '9:16' | '1:1' | '21:9'
    - `image_urls` string[]
    - `video_urls` string[]
    - `keep_original_sound` boolean
    - `elements` object[]
      - `name` string, required
      - `image_urls` string[]
      - `video_url` string, uri: A publicly reachable https URL. asset:// URLs are not accepted.
      - `tag` 'character' | 'animal' | 'prop' | 'costume' | 'scene' | 'effect' | 'others'
      - `description` string
      - `voice_url` string, uri: A publicly reachable https URL. asset:// URLs are not accepted.
    - `voices` object[]
      - `name` string, required
      - `audio_url` string, uri, required: A publicly reachable https URL. asset:// URLs are not accepted.

## Response `202`

Task accepted. Poll GET /api/v1/tasks/{id} with the returned id (prefix sd2_) until status is completed or failed, and read the files from result_urls there.

- object
  - `id` string, required
  - `status` 'processing' | 'completed', required: Usually processing. A channel that waits for the image inside the request returns completed; the task's result_urls are then ready at GET /api/v1/tasks/{id}.
  - `model` 'kling4', required
  - `credits_used` number: Credits charged for this task.
  - `remaining_credits` number

## Other responses

- `400`: invalid_request: bad JSON, an unsupported field, or a value outside the documented constraints. The message names the first failing field and details lists them all. Fix the request; retrying it unchanged fails again.
- `401`: unauthorized: the API key is missing, invalid, or revoked.
- `402`: insufficient_credits: the key owner's balance is too low. Some responses also include required_credits and available_credits. Add credits before retrying.
- `403`: purchase_required: the operation needs a successful credits or plan purchase. credits_frozen: credit spending is temporarily unavailable for this account; topping up does not lift it.
- `409`: idempotency_conflict: the Idempotency-Key was used with a different body, or the first request with this key is still running. Use a new key for a new request; wait and retry for a running one.
- `429`: rate_limited: submissions are limited to 30 per 60 seconds and reads to 120 per 60 seconds per account; Seedance requests that inspect reference media have a lower limit. Wait for Retry-After before retrying.
- `500`: internal_error: an unexpected server failure. Retry with the same Idempotency-Key; contact support if it persists.
- `503`: service_busy: a temporary generation or credit-concurrency issue. Retry with the same Idempotency-Key after a short delay.
- `default`: Another structured error. Branch on error.code rather than the HTTP status.

---

[API](https://skmtc.dev/seedance2ai/apis/seedance-2-0-ai-public-api.md) - [All operations](https://skmtc.dev/seedance2ai/apis/seedance-2-0-ai-public-api/llms.txt) - [OpenAPI document](https://skmtc.dev/seedance2ai/apis/seedance-2-0-ai-public-api/revisions/e4ef5c6db219?raw)
