Kling の画像生成
Kling で画像を非同期に生成・拡張します。パラメータ、レスポンス、注意点をまとめています。
| 項目 | 値 |
|---|---|
| Base URL | https://api.hop-base.com/v1 |
| 画像タスクを送信 | POST /v1/images/generations |
| タスクを照会 | GET /v1/video/tasks/{task_id} |
| プラン | 「Kling 公式」 |
Kling の画像モデルはすべて非同期タスクです。送信すると 202 とタスク id が返り、照会エンドポイントをポーリングすると、完了したタスクの outputs[] に画像 URL が入ります。
利用できるモデル
| モデル | モデル ID | quality ティア | 参照画像 | 公式価格 |
|---|---|---|---|---|
| Kling 画像 3.0 | kling-image-v3 | 1k / 2k | 0〜1 枚 | $0.0294/ 枚 |
| Kling 画像 3.0 Omni | kling-image-v3-omni | 1k / 2k / 4k | 0〜10 枚 | $0.0294〜/ 枚 |
| Kling 画像 O1 | kling-image-o1 | 1k / 2k / 4k | 0〜10 枚 | $0.0294〜/ 枚 |
| Kling 画像 2.1(テキストから画像) | kling-image-v2-1 | 1k / 2k | 不可 | $0.0147/ 枚 |
| Kling 画像 2.1(画像から画像) | kling-image-v2-1-i2i | 1k / 2k | ちょうど 1 枚 | $0.0294/ 枚 |
| Kling 画像 2.1(複数参照) | kling-image-v2-1-multi-ref | 1k / 2k | 2〜4 枚 | $0.0588〜/ 枚 |
| Kling 画像拡張 | kling-image-expand | 1k | ちょうど 1 枚 | $0.0294/ 枚 |
選び方:テキストだけなら 2.1(テキストから画像)、4k や多数の参照画像が必要なら 3.0 Omni か O1、既存の画像を外側へ広げるなら画像拡張を選んでください。
リクエストパラメータ
| パラメータ | 必須 | 型と制限 | デフォルト | 説明 |
|---|---|---|---|---|
model | 必須 | 文字列 | — | 上表の画像モデル ID |
prompt | 画像なしでは必須 | 文字列 | — | 空でない images と少なくとも一方 |
quality | 任意 | 1k / 2k / 4k | 1k | 画質ティア。選べる値はモデルごとに異なる |
n | 任意 | 整数 1〜9 | 1 | 生成枚数 |
images | モデル別 | url / file_id の要素の配列 | — | 参照画像、または拡張する元画像 |
extra | 拡張専用 | 4 つの拡張比率を持つオブジェクト | — | 画像拡張を参照 |
- 受け付けるのはこれらのフィールドのみで、
size、aspect_ratio、response_formatなどは 400 になります。 modelに動画モデルの ID を指定すると 400 になります。qualityは大文字・小文字を区別せず、highやstandardなど OpenAI 形式の値は拒否されます。nは出力画像 1 枚ごとに課金されます。- 他の画像モデルで空でない
extraを指定すると 400 になります。
参照画像
images[] の各要素には url か file_id のどちらか一方だけを指定し、usage は付けません。
{
"model": "kling-image-v3-omni",
"prompt": "2 枚の画像のカップを同じ木のテーブルに並べる",
"quality": "2k",
"images": [
{ "url": "https://cdn.example.com/cup-a.png" },
{ "file_id": "your-file-id" }
]
}urlは絶対パスで、パブリックにアクセス可能なhttp://またはhttps://の URL である必要があります。- 空文字列、相対パス、
file://など HTTP(S) 以外のスキーム、プライベートやループバックのアドレス、認証情報を含む URL は送信時に同期的に拒否されます。 file_idは現在のキーで使える Kling 素材である必要があり、Seedance 素材 ID は使えません。- 参照画像の枚数はモデルごとに制限されます。利用できるモデルを参照してください。
画像拡張
kling-image-expand は 1 枚の画像を外側へ拡張します。比率は extra に指定します。
{
"model": "kling-image-expand",
"images": [{ "url": "https://example.com/input.png" }],
"extra": {
"left_expansion_ratio": 0.5,
"right_expansion_ratio": 0.5,
"up_expansion_ratio": 0,
"down_expansion_ratio": 0
}
}- 4 つの比率はそれぞれ 0〜2 の数値で、省略した比率は 0 です。
- 4 つの比率をすべて 0 にはできません。
- 拡張後の面積は元画像の 3 倍を超えられません:(1+左+右) × (1+上+下) ≤ 3。
レスポンス
送信に成功すると HTTP 202 が返り、タスク ID はトップレベルの id に kt57x<task-id> のような形式で入っています。
{
"id": "ktEXAMPLE",
"object": "image.generation.task",
"model": "kling-image-v3",
"status": "queued",
"created": 1790000000,
"billing_bucket": "img_1k",
"requested_images": 1
}この id で GET /v1/video/tasks/{task_id} をポーリングします。完了したタスクは次のようになります。
{
"id": "ktEXAMPLE",
"object": "video.generation.task",
"model": "kling-image-v3",
"status": "completed",
"progress": 100,
"created": 1790000000,
"outputs": [
"https://api.hop-base.com/example-signed-image.png"
],
"usage": { "bucket": "img_1k", "billed_images": 1 }
}| フィールド | 型 | 説明 |
|---|---|---|
id | string | HopBase のタスク ID。送信時と照会時で同じ |
object | string | 送信時は image.generation.task、照会時は video.generation.task |
status | string | queued → processing → completed または failed |
progress | integer | 進捗率。照会時のみ |
requested_images | integer | リクエストした枚数。送信時のみ |
billing_bucket | string | 画質に対応する課金ティア。送信時のみ |
outputs | string[] | 画像 URL の配列。completed のときのみ |
usage.billed_images | integer | 課金された枚数。実際の出力枚数と同じ |
error.code / error.message | string | failed のときのみ。失敗したタスクを参照 |
終了状態は completed と failed のみなので、それ以外の値は実行中として扱ってください。
タスク終了後は、照会レスポンスのルートの usage に cost(このタスクで残高から実際に差し引かれた金額。課金なしの失敗は 0)と通貨の currency も含まれます。
例
テキストから画像のタスクを送信し、終了までポーリングしてから 1 枚目の画像をダウンロードします。
# 1. 送信
curl https://api.hop-base.com/v1/images/generations \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-image-v3",
"prompt": "日差しの当たる木のテーブルに置かれた陶器のティーポット",
"quality": "1k",
"n": 1
}'
# 2. 返された id で、status が completed か failed になるまで照会
curl https://api.hop-base.com/v1/video/tasks/ktYOUR_TASK_ID \
-H "Authorization: Bearer sk-your-key"注意事項
- 画像 URL は
api.hop-base.comから配信され、タスク完了時点から 6 時間有効なので、早めにダウンロードしてください。 - 再度照会しても同じ URL が返るだけで有効期限は延長されず、期限切れのリンクは 410 を返します。
- 作成から 2 時間経っても終わらないタスクは失敗扱いとなって課金されず、タスクは取り消せません。
- Kling の画像生成は残高の予約を行わず、残高が 0 以下になった時点でのみブロックされます。
- 課金対象の処理を送信する前に、
GET /v1/modelsでキーが返す正確なモデル ID を確認してください。
- ゲートウェイはリクエストの構造と枚数のみを検証し、解像度、形式、サイズはタスク実行中に公式側で検証されるため、規格外の素材は送信の数分後に失敗します。
- リクエストボディは厳格に解析され、ネストしたオブジェクト内の未知のフィールドや、ボディの後に続く 2 つ目の JSON 値も 400 となり、課金されません。
- 画像タスクは Kling の動画タスクと照会エンドポイントおよびタスク一覧
GET /v1/video/tasksを共有します。 - Kling の画像モデルは
POST /v1/images/generationsからのみ送信でき、動画エンドポイントに送ると 400 になります。
よくあるエラー
送信時のエラーではタスクは作成されず、課金もされません。error.message に理由が示されます。
| エラー | 対処 |
|---|---|
request body does not match the JSON contract: json: unknown field "size" | 余分なフィールドを削除し、画質は quality で指定 |
prompt and input images cannot both be empty | prompt か参照画像を追加 |
images[0] must provide exactly one of url or file_id | 各要素に url か file_id の一方だけを残す |
images[0].url must be a publicly accessible absolute http(s) URL | 公開された HTTP(S) の URL を使う |
model "kling-image-v3" does not support quality tier "4k" | モデルが対応するティアを選ぶ |
model "kling-image-v2-1-multi-ref" requires 2 to 4 input images | モデルの要件に合わせて参照画像の枚数を調整 |
model "<モデル ID>" is not an image model in this catalog | GET /v1/models で ID を確認(404) |
# で始まる行が発生条件、次の行が error.message の原文です。
# 表にないフィールド
request body does not match the JSON contract: json: unknown field "<フィールド名>"
# prompt と images がどちらも空
prompt and input images cannot both be empty
# images[] の要素に url / file_id がない、または両方ある
images[<番号>] must provide exactly one of url or file_id
# url が公開された絶対 http(s) アドレスでない
images[<番号>].url must be a publicly accessible absolute http(s) URL
# images[] の要素に usage を指定
images[<番号>].usage is not part of the image generation API; remove this field
# モデルが提供していない quality ティア
model "<モデル ID>" does not support quality tier "<値>"
# n が 1–9 の範囲外
n must be between 1 and 9, got <値>
# 参照画像がモデルの上限を超えた
model "<モデル ID>" accepts at most <上限> input images, got <枚数>
# kling-image-v2-1 に画像を指定
model "kling-image-v2-1" is a text-to-image model and does not accept input images
# kling-image-v2-1-i2i の画像がちょうど 1 枚でない
model "kling-image-v2-1-i2i" requires exactly 1 input image
# kling-image-v2-1-multi-ref の画像が 2–4 枚でない
model "kling-image-v2-1-multi-ref" requires 2 to 4 input images
# 拡張以外のモデルで extra を指定
model "<モデル ID>" does not accept unverified extra parameters
# 拡張の画像がちょうど 1 枚でない
image expansion requires exactly 1 input image
# 拡張の extra に 4 つの比率以外のキー
extra.<キー> is not a verified parameter of the image expansion API
# 拡張比率が 0 から 2 の数値でない
extra.<キー> must be a number between 0 and 2
# 4 つの比率がすべて 0
the four expansion ratios cannot all be 0
# 拡張後の面積が元画像の 3 倍を超える
expanded area cannot exceed 3x the original image
# 画像モデル ID がカタログにない(404)
model "<モデル ID>" is not an image model in this catalog失敗したタスク
タスクが失敗しても、照会は HTTP 200 で返り、status は failed になります。処理の分岐は error.code の安定したコードで行い、エラーの説明をユーザーに表示してください。以前に失敗したタスクにはコードがない場合があります。
| 状況 | error.code |
|---|---|
| prompt または参照画像が審査で拒否 | input_sensitive |
| 出力が審査でブロック | safety_rejected |
| 同時実行数の上限 | rate_limited |
| モデルのバージョンが提供終了 | unsupported_model |
| prompt が長すぎる、またはパラメータや素材が不正 | invalid_request |
| 参照画像を読み込めない | reference_input_invalid |
| 生成失敗、または完了前に停止 | generation_failed |
| 作成から 2 時間経っても終わらない | timeout |
| 出力なしでタスクが終了 | no_output |
# input_sensitive
the prompt was rejected by content moderation; rephrase it and submit again
the reference image was rejected by content moderation; replace it and submit again
the prompt or reference image was rejected by content moderation; revise it and submit again
# safety_rejected
the generated result was blocked by content moderation; adjust the prompt or reference media and submit again
# rate_limited
this model is at its concurrency limit right now; please retry shortly
# unsupported_model
this model version is no longer available; switch to another model and submit again
# invalid_request
the prompt is too long for this model (at most 2500 characters); shorten it and submit again
the request was rejected as invalid by the model; check the parameters and media against the documented limits, then submit again
# reference_input_invalid
a reference image or video is missing or could not be read; make sure every URL is publicly reachable and points to a supported file, then submit again
# generation_failed
image generation failed; please retry, and contact support with the task ID if it keeps failing
image generation was stopped before it finished; please retry, and contact support with the task ID if it keeps failing
… contact support with the task ID
# timeout
task did not reach a billable terminal state within 2 hours; polling stopped
# no_output
image generation finished without a usable output; please retry, and contact support with the task ID if it keeps failing課金
Kling の画像は出力画像 1 枚ごとに、モデルと画質ティアに応じたレートで課金されます。失敗したタスクとポーリングは課金されません。各モデルの価格は上表のモデルカードに、実際の適用レートはログイン後のモデルカタログに表示されます。
次のステップ
- 画像生成 API: すべての画像シリーズの概要
- GPT Image、Gemini の画像生成、Seedream、Grok Imagine の画像生成: ほかの画像シリーズ
- Kling の動画: Kling の動画、モーションコントロール、アバター、リップシンク
- 画像を生成と動画タスクを照会: API リファレンス
- トラブルシューティング: エラーメッセージから対処法を探す