Vai al contenuto
Riferimento API
Riferimento API

Kling Modifica video

Usa l'endpoint edit video per creare un Task asincrono.

01

Panoramica

Usa l'endpoint edit video con un modello supportato. Usa il Task ID restituito per recuperarne lo stato, oppure fornisci callback_url per le consegne documentate di seguito.

Avvio rapido

  1. Crea una Chiave API e impostala come RUNAPI_API_KEY.
  2. Scegli un modello supportato e invia una richiesta POST il cui corpo corrisponda allo schema di quel modello.
  3. Conserva l'ID attività restituito, quindi esegui il polling fino a uno stato terminale o gestisci i callback documentati di seguito.

Endpoint

POST /api/v1/kling/edit_video
URL di base
https://runapi.ai
Versione API
v1
Autenticazione
Authorization: Bearer YOUR_API_TOKEN
02

Modelli supportati

Apri la pagina di un modello per i prezzi correnti, i limiti di frequenza e i dettagli sull'uso commerciale.

03

Schema della richiesta

Corpo JSON

I campi e i valori consentiti dipendono dal modello selezionato. Se fornito, callback_url riceve le notifiche Task documentate di seguito.

kling-v3-omni-edit10 campi
aspect_ratiostring
Opzionale

Rapporto d'aspetto dell'output; le richieste solo sorgente richiedono auto.

Valori consentiti: auto, 16:9, 9:16, 1:1
callback_urlstring
Opzionale

URL webhook per notifiche asincrone.

duration_secondsinteger
Opzionale

Durata dell'output in secondi.

Valori consentiti: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 Predefinito: 5
enable_soundboolean
Opzionale

Abilita la generazione sonora sincronizzata.

Predefinito: false
modelstring
Obbligatorio

Slug del modello.

output_resolutionstring
Opzionale

Risoluzione di output.

Valori consentiti: 720p, 1080p, 4k Predefinito: 720p
promptstring
Obbligatorio

Descrizione del video.

Intervallo: 1 - 2500
reference_image_urlsarray
Opzionale

URL ordinati di immagini di riferimento.

Intervallo elementi: 1 - 4
source_task_idstring
Opzionale

ID task compatibile completato; non può essere combinato con source_video_url.

source_video_urlstring
Opzionale

URL del video sorgente pubblico; non può essere combinato con source_task_id.

kling-v3-omni-reference10 campi
aspect_ratiostring
Opzionale

Rapporto d'aspetto dell'output; le richieste solo sorgente richiedono auto.

Valori consentiti: auto, 16:9, 9:16, 1:1
callback_urlstring
Opzionale

URL webhook per notifiche asincrone.

duration_secondsinteger
Opzionale

Durata dell'output in secondi.

Valori consentiti: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 Predefinito: 5
enable_soundboolean
Opzionale

Abilita la generazione sonora sincronizzata; le richieste con video sorgente richiedono false.

Predefinito: false
modelstring
Obbligatorio

Slug del modello.

output_resolutionstring
Opzionale

Risoluzione di output.

Valori consentiti: 720p, 1080p, 4k Predefinito: 720p
promptstring
Obbligatorio

Descrizione del video.

Intervallo: 1 - 2500
reference_image_urlsarray
Opzionale

URL ordinati di immagini di riferimento.

Intervallo elementi: 1 - 4
source_task_idstring
Opzionale

ID task compatibile completato; non può essere combinato con source_video_url.

source_video_urlstring
Opzionale

URL del video sorgente pubblico; non può essere combinato con source_task_id.

Regole condizionali

Questi requisiti si applicano quando tutte le condizioni elencate corrispondono.

  1. Quando model = kling-v3-omni-edit, source_task_id = {"present" => false}, source_video_url = {"present" => false}
    Obbligatorio
    Non accettato
  2. Quando model = kling-v3-omni-edit, source_video_url = {"present" => true}
    Obbligatorio
    Non accettato
    source_task_id
  3. Quando model = kling-v3-omni-edit, source_task_id = {"present" => true}
    Obbligatorio
    Non accettato
    source_video_url
  4. Quando model = kling-v3-omni-edit, reference_image_urls = {"present" => false}, source_video_url = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  5. Quando model = kling-v3-omni-edit, reference_image_urls = {"present" => false}, source_task_id = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  6. Quando model = kling-v3-omni-edit, reference_image_urls = {"present" => true}, source_video_url = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  7. Quando model = kling-v3-omni-edit, reference_image_urls = {"present" => true}, source_task_id = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  8. Quando model = kling-v3-omni-reference, source_task_id = {"present" => false}, source_video_url = {"present" => false}
    Obbligatorio
    Non accettato
  9. Quando model = kling-v3-omni-reference, source_video_url = {"present" => true}
    Obbligatorio
    Non accettato
    source_task_id
  10. Quando model = kling-v3-omni-reference, source_task_id = {"present" => true}
    Obbligatorio
    Non accettato
    source_video_url
  11. Quando model = kling-v3-omni-reference, reference_image_urls = {"present" => false}, source_video_url = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  12. Quando model = kling-v3-omni-reference, reference_image_urls = {"present" => false}, source_task_id = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  13. Quando model = kling-v3-omni-reference, reference_image_urls = {"present" => true}, source_video_url = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
  14. Quando model = kling-v3-omni-reference, reference_image_urls = {"present" => true}, source_task_id = {"present" => true}
    Obbligatorio
    aspect_ratio
    Non accettato
04

Crea accettazione

HTTP 202

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "billing": {
      "properties": {
        "refund": {
          "oneOf": [
            {
              "properties": {
                "refunded_at": {
                  "type": "string"
                }
              },
              "required": [
                "refunded_at"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "reservation": {
          "oneOf": [
            {
              "properties": {
                "amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "amount_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "settlement": {
          "oneOf": [
            {
              "properties": {
                "amount_micro_cents": {
                  "type": "integer"
                },
                "charged_amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "charged_amount_cents",
                "amount_micro_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "required": [
        "reservation",
        "settlement",
        "refund"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    },
    "task_replayed": {
      "type": "boolean"
    }
  },
  "required": [
    "id",
    "status",
    "billing"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "processing"
}
05

Polling in elaborazione

HTTP 200

GET /api/v1/kling/edit_video/:id

Schema della risposta
JSON
{
  "properties": {
    "billing": {
      "properties": {
        "refund": {
          "oneOf": [
            {
              "properties": {
                "refunded_at": {
                  "type": "string"
                }
              },
              "required": [
                "refunded_at"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "reservation": {
          "oneOf": [
            {
              "properties": {
                "amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "amount_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "settlement": {
          "oneOf": [
            {
              "properties": {
                "amount_micro_cents": {
                  "type": "integer"
                },
                "charged_amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "charged_amount_cents",
                "amount_micro_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "required": [
        "reservation",
        "settlement",
        "refund"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "billing"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "processing"
}
06

Polling completato

HTTP 200

GET /api/v1/kling/edit_video/:id

Schema della risposta
JSON
{
  "properties": {
    "billing": {
      "properties": {
        "refund": {
          "oneOf": [
            {
              "properties": {
                "refunded_at": {
                  "type": "string"
                }
              },
              "required": [
                "refunded_at"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "reservation": {
          "oneOf": [
            {
              "properties": {
                "amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "amount_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "settlement": {
          "oneOf": [
            {
              "properties": {
                "amount_micro_cents": {
                  "type": "integer"
                },
                "charged_amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "charged_amount_cents",
                "amount_micro_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "required": [
        "reservation",
        "settlement",
        "refund"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    },
    "videos": {
      "items": {
        "properties": {
          "url": {
            "type": "string",
            "x-runapi-generated-media": true
          }
        },
        "required": [
          "url"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    }
  },
  "required": [
    "id",
    "status",
    "videos",
    "billing"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "completed",
  "videos": [
    {
      "url": "https://file.runapi.ai/reference-video.mp4"
    }
  ]
}
07

Polling non riuscito

HTTP 200

GET /api/v1/kling/edit_video/:id

Schema della risposta
JSON
{
  "properties": {
    "billing": {
      "properties": {
        "refund": {
          "oneOf": [
            {
              "properties": {
                "refunded_at": {
                  "type": "string"
                }
              },
              "required": [
                "refunded_at"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "reservation": {
          "oneOf": [
            {
              "properties": {
                "amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "amount_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "settlement": {
          "oneOf": [
            {
              "properties": {
                "amount_micro_cents": {
                  "type": "integer"
                },
                "charged_amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "charged_amount_cents",
                "amount_micro_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "required": [
        "reservation",
        "settlement",
        "refund"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    "error": {
      "type": "string"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "failed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "error",
    "billing"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "error": "Task processing failed.",
  "id": "tsk_reference_demo",
  "status": "failed"
}
08

Callback cliente: completato

HTTP 200

POST callback_url

Schema della risposta
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    },
    "videos": {
      "items": {
        "properties": {
          "url": {
            "type": "string",
            "x-runapi-generated-media": true
          }
        },
        "required": [
          "url"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    }
  },
  "required": [
    "id",
    "status",
    "videos"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "id": "tsk_reference_demo",
  "status": "completed",
  "videos": [
    {
      "url": "https://file.runapi.ai/reference-video.mp4"
    }
  ]
}
09

Callback cliente: fallito

HTTP 200

POST callback_url

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "properties": {
            "code": {
              "type": "string"
            },
            "limit_cents": {
              "type": "integer"
            },
            "message": {
              "type": "string"
            },
            "reset_at": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            },
            "used_cents": {
              "type": "integer"
            },
            "window": {
              "enum": [
                "1h",
                "1d",
                "7d",
                "daily",
                "weekly",
                "monthly",
                "lifetime"
              ],
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ],
          "type": "object",
          "unevaluatedProperties": false
        }
      ]
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "failed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": {
    "code": "generation_failed",
    "message": "Task processing failed."
  },
  "id": "tsk_reference_demo",
  "status": "failed"
}
10

Errori

HTTP 401

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Authentication required"
}
11

Errori

HTTP 401

GET /api/v1/kling/edit_video/:id

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Authentication required"
}
12

Errori

HTTP 400

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "Messaggio di errore leggibile.",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "Riepilogo di convalida leggibile dall'utente.",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "Messaggi di convalida con chiave per campo della richiesta pubblica, con un array di stringhe leggibili dall'utente per ogni campo.",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}

Esempio di risposta

JSON
{
  "error": "model must be one of: kling-v3-omni-edit, kling-v3-omni-reference"
}
13

Errori

HTTP 402

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Insufficient balance"
}
14

Errori

HTTP 429

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "API key credit limit exceeded"
}
15

Errori

HTTP 409

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "The request uses features that are not supported for the selected model"
}
16

Errori

HTTP 429

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Rate limit reached. Please retry later."
}
17

Errori

HTTP 503

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Service under maintenance, please try again later"
}
18

Errori

HTTP 504

POST /api/v1/kling/edit_video

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "The request timed out"
}
19

Errori

HTTP 404

GET /api/v1/kling/edit_video/:id

Schema della risposta
JSON
{
  "properties": {
    "error": {
      "description": "Messaggio di errore leggibile.",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

Esempio di risposta

JSON
{
  "error": "Task with id 'tsk_reference_demo' not found"
}
20

Esempi di Codice Generati

Usa cURL direttamente, oppure installa un SDK per il tuo linguaggio. Ogni esempio invia la richiesta validata mostrata in questo riferimento.

Installa

Shell
pip install runapi-kling
PYTHON
import os
from runapi.kling import KlingClient

client = KlingClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.edit_video.create(
  model="kling-v3-omni-edit",
  prompt="Turn the source into a hand-painted watercolor scene.",
  source_video_url="https://cdn.runapi.ai/public/samples/video.mp4",
  reference_image_urls=["https://cdn.runapi.ai/public/samples/image.jpg"],
  duration_seconds=8,
  output_resolution="1080p",
  enable_sound=True,
  aspect_ratio="16:9"
)