お知らせ: MAI Image 2.7 が登場、期間限定で20%オフ。テキストからの画像生成と画像編集の全ラインナップが対象です。今すぐ体験する
お知らせ: MAGI 2 新登場の期間限定20%オフ、テキスト生成・画像生成・参照生成の動画全ラインナップが対象、今すぐ体験
お知らせ: 2026 ブラックフライデー × サイバーマンデー:チャージで最大30%多く獲得、DeepSeek 無料利用 · キャンペーンを見る
HiAPI
ナビゲーションを開く

kling-image-4.0

Kling Image 4.0 · kling-image-4.0

生成タスクの作成

POST /v1/tasks

ヘッダー

Authorizationstring必須

アカウントの API キー。すべてのリクエストで必須です。例:Bearer YOUR_HIAPI_API_KEY。API キーを取得

Content-Typestring任意

リクエストボディは常に JSON として解析されます。送信する場合は application/json(charset 付き可)のみ受け付け、他の値は 415 を返します。例:application/json。

Idempotency-Keystring任意

冪等キー。最大 255 バイト。同じアカウントで同じキーの再試行はタスクを 1 つだけ作成し、リプレイは最初の taskId を返します。

冪等キー

ネットワークタイムアウトやクライアントの自動再試行時、同じキーではタスクを 1 回だけ作成し、二重課金は発生しません(適用範囲 = API キーのアカウント)。業務側の一意識別子(例:"order-42")をキーに使うことを推奨します。同じキーのリプレイは最初の taskId を返し、キーは初回送信から 24 時間で失効します。詳細なシナリオ表は統一非同期 API の紹介ページをご覧ください。

ボディ

modelstring必須

現在の固定値:kling-image-4.0

routestring任意

現在の固定値:default

inputobject必須

kling-image-4.0 とルート default の業務パラメータオブジェクト。下のパラメータ表を参照してください。

modestring任意デフォルト: "default"

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

オプション:defaultseries
countinteger任意デフォルト: 1min 1max 10

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

lengthstring任意デフォルト: "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.

オプション:shortmediumlong
promptstring必須minLength 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.

elementsarray任意maxItems 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 ]

配列要素

tagstring任意
オプション:characteranimalpropcostumesceneeffectothers
namestring必須minLength 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_urlsarray必須minItems 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 ]

descriptionstring任意maxLength 100
task_typestring必須

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

オプション:imagewebpageecommerce
image_urlsarray任意maxItems 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 ]

resolutionstring任意デフォルト: "2k"

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

オプション:1k2k4k8k
style_imagestring任意minLength 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_ratiostring任意デフォルト: "auto"

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

オプション:auto9:162:33:41:14:33:216:9
すべて表示(1 件)閉じる
21:9
subject_imagestring任意minLength 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.

callbackobject任意

終了状態の通知設定。省略した場合はコールバックされず、呼び出し側でポーリングします。

コールバック(Webhook)

作成時に callback.url を指定すると、タスク終了時に HiAPI があなたのサービスへ POST し、ポーリングが不要になります。コールバックのリクエストボディはタスク詳細と同構造です。署名検証・再送・冪等の詳細は統一非同期 API 紹介ページのコールバック説明を参照してください。

urlstring必須

callback を指定する場合は必須。タスク終了後にこの URL へ POST します。有効な http(s) URL である必要があります。

whenstring任意デフォルト: "final"

現在は final のみ対応(success / fail の両方で通知)。

オプション:final
storagestring任意デフォルト: "temp"

成果物の保存期間:temp(デフォルト・約 7 日)または persistent(長期保存・サイズ課金)。残高不足や保存上限超過の場合は temp に自動降格します。実際に適用された段階はタスク詳細レスポンスで確認できます。

オプション:temppersistent

リクエスト例

# 非同期タスクを送信。成功すると即座に taskId を返します(生成完了は待ちません)
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 /v1/tasks/:id

レスポンスフィールド

taskIdstring必須

タスク ID。先頭は固定で tk-hiapi-。

modelstring必須

解決済みのモデル完全名。route パラメータで送信したタスクは base@route(例:gpt-image-2/text-to-image@ext)を返し、それ以外は送信時のモデル名と同一です。

routestring任意

route パラメータを明示して送信したタスクでのみ出現し、送信時の値をエコーします。

statusstring必須

タスク状態。

ステータス値

queued キュー投入済み、未開始。 handling 処理中。 archiving 処理完了、成果物準備中。 success 終端:完了。成果物利用可能(output を返却)。 fail 終端:失敗(error を返却)。 送信後は status で判断します:success と fail が終端、それ以外は非終端です。1〜3 秒間隔で終端までポーリングすることを推奨します。成功したら output[].url から成果物をダウンロードし、expireAt までに保存先へ転送してください。長期保存が必要な場合は作成時に storage: "persistent" を指定します。

creatednumber必須

タスク作成時刻(Unix 秒)。

completednumber必須

終了状態になった Unix 秒。非終端では 0 固定。

outputarray任意

status == success のときのみ出現。成果物リスト — 常に配列で、1 タスクで複数の type を同時に返すことがあります(例:video + first_frame)。

Array [ object ]

配列要素

urlstring必須

成果物の URL。直接ダウンロードできます。

typestring必須

現在の候補値:video、image、audio、first_frame、last_frame、thumbnail。今後拡張される可能性があります。

expireAtnumber必須

成果物にアクセスできる期限(Unix 秒)。期限までにダウンロードまたは転送してください。

errorobject任意

status == fail のときのみ出現。

codestring必須

業務エラーコード。

messagestring必須

エラーの説明。

レスポンス例

成功

{
  "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
      }
    ]
  }
}

処理中(非終端)

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

失敗

{
  "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"
    }
  }
}