{
  "openapi": "3.1.0",
  "info": {
    "title": "SeedRouter Kling 4.0",
    "version": "1.0.0",
    "description": "Kling 4.0 video with stereo sound from text, keyframes or image, video and audio references, or an edit or extension of a video, at 720p or 1080p. Asynchronous task delivery; media by URL only; callbacks are not offered; tasks cannot be cancelled."
  },
  "servers": [
    {
      "url": "https://api.seedrouter.ai/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/videos/generations": {
      "post": {
        "summary": "Create a video generation task",
        "operationId": "createVideoTask",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VideoRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted. Poll the returned id; no video is returned by this call.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaskAccepted"
                }
              }
            }
          },
          "400": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{task_id}": {
      "get": {
        "summary": "Read an owned image task",
        "operationId": "getImageTask",
        "parameters": [
          {
            "name": "task_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^task_[A-Za-z0-9]{1,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Processing, completed or failed task. Polling timeout is not a task failure.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "401": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Public error; no infrastructure details.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "VideoRequest": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "const": "kling-4-0"
          },
          "prompt": {
            "type": "string",
            "description": "Optional for image to video only. Mention references as @Image1, @Video1, @Audio1, numbered from 1 in each list."
          },
          "duration": {
            "type": "integer",
            "minimum": 3,
            "maximum": 30,
            "default": 5,
            "description": "3–30 seconds. Edit: left out, the output follows the input video. Extend: the length of the new part."
          },
          "resolution": {
            "type": "string",
            "enum": [
              "720p",
              "1080p"
            ],
            "default": "720p"
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "21:9",
              "auto"
            ],
            "description": "auto for reference mode only. Defaults: text 16:9, image the first frame, reference auto, edit the input video. Not accepted with extend."
          },
          "image_urls": {
            "minItems": 1,
            "maxItems": 10,
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "Image to video: up to 2, the first then the last frame. Reference (omni_reference_task_type reference) and edit: up to 10 reference images."
          },
          "image_with_roles": {
            "minItems": 1,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "first_frame",
                    "last_frame",
                    "keyframe",
                    "middle_frame",
                    "reference_image"
                  ]
                }
              },
              "required": [
                "url",
                "role"
              ],
              "additionalProperties": false
            },
            "description": "Frames or reference images with roles. Exactly 1 first frame, up to 8 keyframes in order, 10 frames in total."
          },
          "first_frame_image": {
            "type": "string",
            "format": "uri",
            "description": "First frame for image to video."
          },
          "last_frame_image": {
            "type": "string",
            "format": "uri",
            "description": "Last frame for image to video, or the target last frame for extend."
          },
          "video_urls": {
            "minItems": 1,
            "maxItems": 5,
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "Reference videos: up to 5, 30 seconds used in total, billed at the video-input rate. For edit or extend, exactly 1 in place of video_url."
          },
          "video_url": {
            "type": "string",
            "format": "uri",
            "description": "Input video for edit (at least 3 seconds; the first 30 are used) or extend."
          },
          "audio_urls": {
            "minItems": 1,
            "maxItems": 3,
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "Reference audio: up to 3 clips of 5–30 seconds each; 15 reference files in total."
          },
          "omni_reference_task_type": {
            "type": "string",
            "enum": [
              "auto",
              "reference",
              "edit",
              "extend"
            ],
            "default": "auto"
          },
          "audio_setting": {
            "type": "string",
            "enum": [
              "origin",
              "auto"
            ],
            "description": "origin keeps the input audio, auto regenerates it. Edit, or reference with videos; not extend."
          }
        },
        "required": [
          "model"
        ],
        "additionalProperties": false
      },
      "TaskAccepted": {
        "type": "object",
        "required": [
          "id",
          "model",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "model": {
            "enum": [
              "kling-4-0"
            ]
          },
          "status": {
            "const": "processing"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "Task": {
        "type": "object",
        "required": [
          "id",
          "model",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "model": {
            "enum": [
              "kling-4-0"
            ]
          },
          "status": {
            "enum": [
              "processing",
              "completed",
              "failed"
            ]
          },
          "created_at": {
            "type": "integer"
          },
          "finished_at": {
            "type": "integer"
          },
          "output": {
            "type": "object",
            "properties": {
              "video_url": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          "error": {
            "$ref": "#/components/schemas/Error"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "enum": [
              10001,
              10002,
              20001,
              20002,
              30001,
              30002,
              50001,
              50002,
              50003,
              60001,
              60002,
              60003,
              60004,
              90001
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "$ref": "#/components/schemas/Error"
          }
        }
      }
    }
  }
}
