Kling 4.0 Flash

Generate 720p videos lasting 3–20 seconds with POST /v1/videos/generations.

Generation modeModel IDInput
Text-to-videokling-4.0-flash-text-to-videoDescribe the scene, movement and sound in input.prompt
First-frame image-to-videokling-4.0-flash-image-to-videoSupply one first frame and an optional prompt in input.contents
Omni references and editingkling-4.0-flash-omniCombine images, videos and existing subjects in input.contents to generate or edit a video

Pricing and credit reservations

720p inputCredits per billable secondBillable seconds
No video input, including image-only subjects23.44O
Video input, including video-character subjects15.62O + max(I, O)

O is the billable output duration. If you supply input.settings.duration, you pay for the requested seconds even when the media file is slightly longer or shorter. If you omit it, billing uses the target duration selected by the model. The model uses an explicit duration in the prompt first. For an Omni edit it then falls back to the duration of the video being edited, rounded to the nearest whole second. The default in other cases is 10 seconds. I is the combined duration of reference videos, the video being edited, and video-character subjects.

At an account multiplier of 1, a 10-second output with no video input costs 234.40 credits. With an 8-second input video, the same output costs 312.40 credits for 20 billable seconds. With a 15-second input video it costs 390.50 credits for 25 billable seconds. The rate and base charge are rounded to two decimal places. The account multiplier is applied to the base charge and the result is rounded to two decimal places.

The API reserves credits at creation. It reserves the requested output duration, or 20 seconds for automatic duration. An input video or subject also reserves up to 20 seconds of input to cover possible video subjects. For automatic duration at a multiplier of 1, the reservation is 468.80 credits without videos or subjects, or 624.80 credits with a video or subject. To estimate a reservation, send the same model and input to POST /v1/estimate. Include your API key to apply your account multiplier.

After successful generation, unused credits are returned. The completed task's credits_consumed gives the final charge. When available, usage.output_seconds reports the media file duration, which can differ from billable seconds. If required usage is missing, the platform queries it before settlement. A confirmed failure returns the reserved credits.

After submission ends, a successful lookup that finds no task causes the platform to mark the task as failed and refund its precharge, provided no success has been recorded. Temporary query errors continue through recovery.

Endpoint and authentication

Send JSON to POST /v1/videos/generations with Authorization: Bearer YOUR_API_KEY. The optional callback_url belongs alongside model and input. All three models output 720p. To request a duration, set input.settings.duration to a whole number from 3 to 20 seconds.

Text-to-video

Use kling-4.0-flash-text-to-video and describe the scene and action in the required input.prompt string. A prompt alone is enough to generate a video. The optional input.settings.aspect_ratio accepts 16:9 (default), 9:16, 1:1, or 21:9.

This request generates a 10-second vertical video and costs 234.40 credits at an account multiplier of 1.

curl -X POST 'https://api.aivideoapi.ai/v1/videos/generations' \
  -H "Authorization: Bearer ${API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "kling-4.0-flash-text-to-video",
    "input": {
      "prompt": "A night train passes through the city. Pan from the station platform to its lit windows.",
      "settings": { "duration": 10, "aspect_ratio": "9:16" }
    },
    "callback_url": "https://app.example.com/webhooks/video"
  }'

Prompts accept up to 26,000 English characters or 11,000 non-English characters. For mixed text, English characters / 26000 + non-English characters / 11000 ≤ 1.

First-frame image-to-video

Send one first_frame and optionally one prompt in contents. The first frame takes type and url and determines the output aspect ratio. Send this JSON to the same generation endpoint, replacing the example URL with a downloadable file.

{
  "model": "kling-4.0-flash-image-to-video",
  "input": {
    "contents": [
      { "type": "first_frame", "url": "https://media.example.com/platform.jpg" },
      { "type": "prompt", "text": "Keep the camera still as the flag on the platform begins to flutter." }
    ],
    "settings": { "duration": 6 },
    "options": { "watermark_info": { "enabled": true } }
  }
}

Omni references and video editing

Include up to one prompt in contents. Supported materials are first_frame, refer_image, feature_video, base_video and element. Each custom material id must be unique within the task. Reference it in your prompt as @id. Supply both the existing element_id and a custom id for each subject.

{
  "model": "kling-4.0-flash-omni",
  "input": {
    "contents": [
      { "type": "base_video", "id": "clip", "url": "https://media.example.com/train.mp4" },
      { "type": "refer_image", "id": "sky", "url": "https://media.example.com/sunset.jpg" },
      { "type": "prompt", "text": "Replace the sky in @clip with the sunset colors from @sky. Keep the train and its original sound." }
    ],
    "settings": { "duration": 10, "audio": "original" }
  }
}

settings.audio defaults to native, which generates sound for the scene. To keep original audio, set it to original and include a base_video or feature_video. A base video supplies the audio when present. Otherwise the first feature video supplies it. Omni accepts the four fixed text-to-video aspect ratios and defaults to adaptive, which selects the aspect ratio from the prompt and input materials.

MaterialRequirements
ImagesJPEG/PNG through an HTTP(S) URL or Base64, up to 30 MB each. Both dimensions must be at least 300 px, with an aspect ratio from 2:5 to 5:2. Omni accepts up to 10 images, including at most one first frame.
VideosMP4/MOV through an HTTP(S) URL, up to 300 MB each. Each clip and the combined input video duration must be 3–20 seconds. Both dimensions must be 700–4553 px, with at most 8,294,400 pixels, an aspect ratio from 2:5 to 5:2, and 24–60 fps.
Subjects and totalsUp to 7 subjects, including at most 3 video-character subjects. Input videos and video-character subjects together must total at most 5, with at most one base video. Images, videos and subjects together must total at most 15.

Results and callbacks

The creation response contains the platform task ID.

{
  "code": 200,
  "msg": "success",
  "data": { "taskId": "29bd04f8-3c15-4374-a364-4b484782d235" }
}

Query it using an API key from the same account.

curl 'https://api.aivideoapi.ai/v1/tasks/29bd04f8-3c15-4374-a364-4b484782d235' \
  -H "Authorization: Bearer ${API_KEY}"

All three Flash models use the same query and callback format. The data.taskId in the creation response is the id in both the query response and callback body. Queries return the task object directly. Timestamps are Unix seconds.

Pending and processing

A newly created task may return pending. estimated_seconds is an estimate of the wait time.

{
  "id": "29bd04f8-3c15-4374-a364-4b484782d235",
  "status": "pending",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 0,
  "created_at": 1794096000,
  "estimated_seconds": 300
}

During generation, the status is processing. When progress is null, keep polling the same ID. In both states, credits_consumed is 0 while the precharge is already reserved from your available balance.

{
  "id": "29bd04f8-3c15-4374-a364-4b484782d235",
  "status": "processing",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 0,
  "created_at": 1794096000,
  "progress": null
}

Completed query result

For the 10-second text-to-video request above, output.urls[0] is the downloadable video. The file runs for 10.041 seconds. At an account multiplier of 1, the charge is 234.40 credits for the requested 10 seconds.

{
  "id": "29bd04f8-3c15-4374-a364-4b484782d235",
  "status": "completed",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 234.40,
  "created_at": 1794096000,
  "completed_at": 1794096065,
  "output": {
    "urls": [
      "https://media.example.com/results/night-train.mp4?token=example"
    ]
  },
  "usage": {
    "output_seconds": 10.041
  }
}

By default, the API returns the provider’s video URL. Keep its signature parameters and download it before it expires. If you requested a watermark and a watermarked version is available, its URL is in output.metadata.watermark_urls. The optional usage object can include output_seconds for the actual file duration and input_seconds for video input.

Failed query result

A failed generation also returns HTTP 200 when queried. Read status and error to determine the outcome. In this separate example, the precharge has been refunded and the final charge is zero.

{
  "id": "b853d103-0feb-49f8-b238-ae6bf935aca2",
  "status": "failed",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 0,
  "created_at": 1794096120,
  "error": {
    "code": "upstream_error",
    "message": "Video generation failed. Please try again."
  }
}

Receiving task callbacks

Set callback_url at the top level of the creation request. The platform sends a JSON POST to that URL after settling a successful task or refunding a failed one. The requests below show what your endpoint receives. Each body matches the corresponding terminal query example.

Success callback

POST /webhooks/video HTTP/1.1
Host: app.example.com
Content-Type: application/json
X-Task-Id: 29bd04f8-3c15-4374-a364-4b484782d235
X-Event: task.completed
X-Event-ID: 29bd04f8-3c15-4374-a364-4b484782d235:task.completed
X-Timestamp: 1794096066

{
  "id": "29bd04f8-3c15-4374-a364-4b484782d235",
  "status": "completed",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 234.40,
  "created_at": 1794096000,
  "completed_at": 1794096065,
  "output": {
    "urls": [
      "https://media.example.com/results/night-train.mp4?token=example"
    ]
  },
  "usage": {
    "output_seconds": 10.041
  }
}

Failure callback

POST /webhooks/video HTTP/1.1
Host: app.example.com
Content-Type: application/json
X-Task-Id: b853d103-0feb-49f8-b238-ae6bf935aca2
X-Event: task.failed
X-Event-ID: b853d103-0feb-49f8-b238-ae6bf935aca2:task.failed
X-Timestamp: 1794096135

{
  "id": "b853d103-0feb-49f8-b238-ae6bf935aca2",
  "status": "failed",
  "model": "kling-4.0-flash-text-to-video",
  "credits_consumed": 0,
  "created_at": 1794096120,
  "error": {
    "code": "upstream_error",
    "message": "Video generation failed. Please try again."
  }
}

Deduplicate callbacks using X-Event-ID, which stays the same across retries. X-Timestamp is the Unix time in seconds of the delivery attempt. Respond with HTTP 2xx within 10 seconds, including for events already processed. The platform retries a failed delivery up to twice. To verify the final state, query the task identified by X-Task-Id with your API key.