Notice: MAI Image 2.7 launch limited-time 20% off, covering the full text-to-image and image editing lineup, try it now
Notice: MAGI 2 launch limited-time 20% off, covering text-to-video, image-to-video, and reference-to-video across the board. Try it now
Notice: Black Friday 2026 × Cyber Monday: Get up to 30% extra on top-ups, DeepSeek free to use · View the promotion
Open navigation

kling-image-4.0

Kling Image 4.0 · kling-image-4.0

Create a generation task

POST /v1/tasks

Headers

AuthorizationstringRequired

Account API key. Required on every request. Example: Bearer YOUR_HIAPI_API_KEY. Get your API key

Content-TypestringOptional

The request body is always parsed as JSON; when sent, only application/json (optionally with charset) is accepted — any other value returns 415. Example: application/json.

Idempotency-KeystringOptional

Idempotency key, up to 255 bytes. Retries with the same key from the same account create the task only once; replays return the original taskId.

Idempotency key

On network timeouts or client retries, the same key creates the task only once — no double charges (scope: the API key's account). Use a business-unique identifier as the key (e.g. "order-42"); replays return the original taskId, and keys expire 24 hours after the first request. See the Unified Async API overview for the full scenario matrix.

Body

modelstringRequired

Current fixed value: kling-image-4.0

routestringOptional

Current fixed value: default

inputobjectRequired

Business parameters for kling-image-4.0 and route default — see the parameter table below.

modestringOptionalDefault: "default"

Ordinary images only. Default mode generates 1–9 images; series generates 2–10 related images.

Options:defaultseries
countintegerOptionalDefault: 1min 1max 10

Number of output images. Default mode: 1–9; series: 2–10; long image: 1.

lengthstringOptionalDefault: "medium"

Ecommerce long images only. Medium is the default. Short: about 2–5 sections; medium: 6–10; long: 11–18. Sections are within one image, not separate outputs.

Options:shortmediumlong
promptstringRequiredminLength 1maxLength 20000pattern \S

Describe the image. Reference images with @image_1 and subjects with @name. For webpage references use @style and @subject. In long-image prompts, literal email addresses or @handles must use full-width @ or a space after @. Referencing missing material is rejected.

elementsarrayOptionalmaxItems 10

Ordinary images only. Each named subject is charged once per request, regardless of its image count. Use distinct names (case-insensitive). References plus subjects total at most 10.

Array [ object ]

Array items

tagstringOptional
Options:characteranimalpropcostumesceneeffectothers
namestringRequiredminLength 1maxLength 20pattern ^[A-Za-z0-9_㐀-鿿]+$

Chinese characters, letters, digits and underscore only; unique ignoring case. Reserved image_N and object_N names are forbidden.

image_urlsarrayRequiredminItems 2maxItems 4

2–4 public JPG/JPEG/PNG images of the same subject from different angles, at most 20 MB each. First image is the primary view.

Array [ string ]

descriptionstringOptionalmaxLength 100
task_typestringRequired

Output type: ordinary or series images, webpage long image, or ecommerce long image.

Options:imagewebpageecommerce
image_urlsarrayOptionalmaxItems 10

Public JPG/PNG URLs, up to 20 MB each. Ordinary images: references plus subjects total at most 10; ecommerce: 1–3 required; webpage: not supported. Ecommerce images should have both dimensions at least 300 px and an aspect ratio between 2:5 and 5:2; unsuitable files can fail during generation.

Array [ string ]

resolutionstringOptionalDefault: "2k"

Ordinary images: 2k/4k/8k. Long images: 1k/2k.

Options:1k2k4k8k
style_imagestringOptionalminLength 1pattern ^https?://

Optional webpage style reference; webpage output only. Public JPG/JPEG/PNG, at most 20 MB. Refer to it as @style in the prompt.

aspect_ratiostringOptionalDefault: "auto"

Ordinary images only. Auto chooses a ratio from the prompt and references.

Options:auto9:162:33:41:14:33:216:9
Show all (1)Show less
21:9
subject_imagestringOptionalminLength 1pattern ^https?://

Optional webpage subject reference; webpage output only. Public JPG/JPEG/PNG, at most 20 MB. Refer to it as @subject in the prompt.

callbackobjectOptional

Terminal-state notification config. When omitted, no callback is delivered — poll the task yourself. See the callback note below.

Callbacks (Webhook)

Provide callback.url when creating a task and HiAPI POSTs to your service once the task reaches a terminal state — no polling needed. The callback payload mirrors the task detail structure; signature verification, delivery retries and idempotency are documented on the Unified Async API overview page.

urlstringRequired

Required when callback is present. A POST is sent to this URL once the task reaches a terminal state; must be a valid http(s) URL.

whenstringOptionalDefault: "final"

Only final is supported today — notified on both success and fail.

Options:final
storagestringOptionalDefault: "temp"

Artifact storage tier: temp (default, retained about 7 days) or persistent (long-term, billed by size). Insufficient balance or exceeding the storage cap silently downgrades to temp; the effective tier is shown in the task detail response.

Options:temppersistent

Request examples

# Submit an async task; returns a taskId immediately (no waiting for generation)
curl -X POST "https://api.hiapi.ai/v1/tasks" \
  -H "Authorization: Bearer $HIAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "kling-image-4.0",
  "input": {
    "mode": "default",
    "count": 1,
    "length": "medium",
    "prompt": "…",
    "task_type": "…",
    "resolution": "2k",
    "aspect_ratio": "auto"
  }
}'

200 OK

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "tk-hiapi-01HZTQ8BX2N3GM3YFK4Z9D7VQR"
  }
}

400 Bad Request

{
  "code": 400,
  "message": "invalid request",
  "data": null,
  "error_code": "INVALID_REQUEST"
}

Get task detail

GET /v1/tasks/:id

Response fields

taskIdstringRequired

Task ID, always prefixed with tk-hiapi-.

modelstringRequired

Resolved full model name. Tasks submitted with the route parameter return base@route (e.g. gpt-image-2/text-to-image@ext); otherwise identical to the name passed at creation.

routestringOptional

Present only when the task was submitted with an explicit route parameter; echoes the submitted value.

statusstringRequired

Task status.

Status values

queued Queued, not started yet. handling Being processed. archiving Processing finished, artifacts being prepared. success Terminal: completed, artifacts available (output returned). fail Terminal: failed (error returned). After submission, check status: success and fail are terminal, everything else is non-terminal. Poll every 1–3 seconds until terminal. On success, download artifacts from output[].url and transfer them before expireAt; pass storage: "persistent" at creation time when long-term retention is needed.

creatednumberRequired

Task creation time (Unix seconds).

completednumberRequired

Unix seconds when the task reached a terminal state; fixed to 0 while not terminal.

outputarrayOptional

Present only when status == success. Artifact list — always an array; a single task may return multiple types at once (e.g. video + first_frame).

Array [ object ]

Array items

urlstringRequired

Artifact URL, directly downloadable.

typestringRequired

Current possible values: video, image, audio, first_frame, last_frame, thumbnail; more may be added later.

expireAtnumberRequired

Unix seconds until which the artifact remains accessible; download or transfer before it expires.

errorobjectOptional

Present only when status == fail.

codestringRequired

Business error code.

messagestringRequired

Error description.

Response examples

Success

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "tk-hiapi-01HZTQ8BX2N3GM3YFK4Z9D7VQR",
    "model": "happyhorse-1-0",
    "status": "success",
    "created": 1777282033,
    "completed": 1777282099,
    "output": [
      {
        "url": "https://cdn.hiapi.ai/tasks/.../video.mp4",
        "type": "video",
        "expireAt": 1777886899
      }
    ]
  }
}

Processing (non-terminal)

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "tk-hiapi-...",
    "model": "happyhorse-1-0",
    "status": "archiving",
    "created": 1777282033,
    "completed": 0
  }
}

Failed

{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "tk-hiapi-...",
    "model": "happyhorse-1-0",
    "status": "fail",
    "created": 1777282033,
    "completed": 1777282099,
    "error": {
      "code": "TASK_FAILED",
      "message": "task failed"
    }
  }
}