PixMind Docs
API ReferenceVideo ModelsKling 4.0

Kling 4.0 API

Kling 4.0 video generation, editing, extension and billing

Generate, edit and extend 3–30 second videos at 720p/1080p with stereo audio.

Provider

Kling AI

Model ID

kling-v4

Endpoint

POST /api-platform/v1/generations

Authentication

Base URL: https://aihub-admin.aimix.pro. Send Authorization: Bearer <PIXMIND_API_KEY> on both creation and polling requests, and Content-Type: application/json when submitting JSON. Keep your key in a server environment variable.

Model notes

  • Five modes: text-to-video, image-to-video, reference, edit and extend. Poll the returned PixMind task ID using GET /api-platform/v1/tasks/{taskId}.
  • Editing or reference videos: bill output seconds + max(output seconds, input seconds). Probe input duration, round up its sum and cap at 30 seconds. Editing without duration follows input; extension bills only the new segment. Failed tasks are fully refunded.
  • Exactly one first frame, at most one last frame and eight keyframes (10 total). References: 10 images, 5 videos (30 seconds total), 3 audio clips (5–30 seconds each), 15 assets combined. Use public HTTP(S) URLs.
  • No mode=std/pro/4k, negative_prompt, watermark=true or audio=false. Extension does not accept aspect_ratio or audio_setting. API is charged at the supplied official USD list rates; wallet points are rounded up once per request.

Request parameters

ParameterTypeRequiredDescription
modelstringYes

Stable PixMind model ID. Use `kling-v4`.

Allowed values: kling-v4

promptstringNo

Required except for image-to-video.

resolutionstringNo

Output video resolution.

Allowed values: 720p, 1080p

Default: 720p

durationintegerNo

Requested clip duration in seconds.

Allowed values: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30

Default: 3

aspectRatiostringNo

Requested output aspect ratio.

Allowed values: 16:9, 9:16, 1:1, 21:9, auto

Default: 16:9

imageUrlstring (URI)No

Starting image for image-to-video generation.

first_frame_imagestringNo

First frame URL; do not mix with other image input forms.

last_frame_imagestringNo

Last frame or extension target frame URL.

omni_reference_task_typestringNo

auto (default), reference, edit or extend. Studio mode also accepts reference/edit/extend.

image_urlsstring[]No

First/last frames, or reference images with explicit reference/edit mode.

image_with_rolesobject[]No

Each item: url and role (first_frame, last_frame, keyframe, middle_frame, reference_image). Do not mix image input forms.

video_urlsstring[]No

Reference videos. For edit/extend, exactly one input video; video_url is also accepted.

audio_urlsstring[]No

Up to three reference audio clips, each 5–30 seconds.

audio_settingstringNo

origin or auto, for edit or reference-video mode only.

Request example

cURL
curl --request POST 'https://aihub-admin.aimix.pro/api-platform/v1/generations' \
  -H "Authorization: Bearer $PIXMIND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "kling-v4",
  "prompt": "A paper boat drifts through rainwater; stereo rainfall and soft footsteps",
  "duration": 5,
  "resolution": "720p",
  "aspect_ratio": "9:16"
}'
JavaScript
// Node.js 20+. Keep the API key on your server.
const apiKey = process.env.PIXMIND_API_KEY;
if (!apiKey) throw new Error("PIXMIND_API_KEY is required");

const response = await fetch("https://aihub-admin.aimix.pro/api-platform/v1/generations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "model": "kling-v4",
  "prompt": "A paper boat drifts through rainwater; stereo rainfall and soft footsteps",
  "duration": 5,
  "resolution": "720p",
  "aspect_ratio": "9:16"
}),
  signal: AbortSignal.timeout(30_000)
});

const task = await response.json();
if (!response.ok || task.code !== 1000) {
  throw new Error(task.message ?? task.error?.message ?? `HTTP ${response.status}`);
}
console.log(task);

Accepted task response

Generation is asynchronous. Save taskId and poll GET /api-platform/v1/tasks/{taskId} until status is ready or failed.

200 OK
{
  "code": 1000,
  "data": {
    "id": "vid_44160",
    "taskId": 44160,
    "type": "video",
    "model": "kling-v4",
    "status": "processing"
  }
}

Query the task and retrieve results

Replace 44160 with data.taskId from the accepted response, using a key belonging to the same user. pending and processing are non-terminal; ready and failed are terminal. On ready, read images (images) or videoUrl (videos); on failed, read errorMessage. The example stops after 60 queries. If it times out, save taskId and query again later instead of creating a duplicate task. Example result URLs are placeholders.

cURL
curl 'https://aihub-admin.aimix.pro/api-platform/v1/tasks/44160' \
  -H "Authorization: Bearer $PIXMIND_API_KEY"
JavaScript
// Continue after the request example above.
const taskId = task.data?.taskId;
if (!Number.isInteger(taskId)) throw new Error("Missing numeric taskId");

async function waitForTask(taskId) {
  for (let attempt = 0; attempt < 60; attempt++) {
    await new Promise(resolve => setTimeout(resolve, Math.min(2000 * 1.5 ** attempt, 10000)));
    const response = await fetch(`https://aihub-admin.aimix.pro/api-platform/v1/tasks/${taskId}`, {
      headers: { Authorization: `Bearer ${apiKey}` },
      signal: AbortSignal.timeout(30_000)
    });
    const result = await response.json();
    if (!response.ok || result.code !== 1000) {
      throw new Error(result.message ?? `HTTP ${response.status}`);
    }
    const data = result.data;
    if (data.status === "ready") return data;
    if (data.status === "failed") {
      throw new Error(data.errorMessage ?? "Generation failed");
    }
    if (!["pending", "processing"].includes(data.status)) {
      throw new Error(`Unexpected task status: ${data.status}`);
    }
  }
  throw new Error(`Polling timed out; save taskId ${taskId} to query again later`);
}

const result = await waitForTask(taskId);
console.log(result.videoUrl);
200 OK · ready
{
  "code": 1000,
  "data": {
    "taskId": 44160,
    "type": "video",
    "model": "kling-v4",
    "status": "ready",
    "progress": 100,
    "videoUrl": "https://example.com/result.mp4"
  }
}

On this page