{
  "openapi": "3.1.0",
  "info": {
    "title": "SeedRouter Kling Image 4.0",
    "version": "1.0.0",
    "description": "Generate 2K or 4K still images from one prompt and up to ten named reference images. Asynchronous delivery of image URLs."
  },
  "servers": [
    {
      "url": "https://api.seedrouter.ai/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/images/generations": {
      "post": {
        "summary": "Create a still image or a connected image series",
        "operationId": "createImageTask",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted. Poll the returned id; no image 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"
                }
              }
            }
          },
          "413": {
            "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": {
      "ImageRequest": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "const": "kling-image-4-0"
          },
          "contents": {
            "minItems": 1,
            "maxItems": 11,
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "prompt"
                    },
                    "text": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "text"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "refer_image"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "id": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "url"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            "description": "One prompt and up to ten reference images. Each supplied reference ID must be unique.",
            "contains": {
              "type": "object",
              "properties": {
                "type": {
                  "const": "prompt"
                }
              },
              "required": [
                "type"
              ]
            },
            "minContains": 1,
            "maxContains": 1
          },
          "settings": {
            "type": "object",
            "properties": {
              "result_type": {
                "description": "Defaults to single.",
                "type": "string",
                "enum": [
                  "single",
                  "series"
                ]
              },
              "n": {
                "description": "Single mode output count. Defaults to one.",
                "type": "integer",
                "minimum": 1,
                "maximum": 9
              },
              "series_amount": {
                "description": "Series mode accepts an integer from 2 to 10, default 4. For 5–10 images, mention every reference, use readable references of 20 MB or less, and keep the prompt within 20,000 characters after conversion to positional references. Ignored in single mode.",
                "anyOf": [
                  {
                    "type": "integer",
                    "minimum": 2,
                    "maximum": 10
                  },
                  {
                    "type": "string",
                    "const": "auto"
                  }
                ]
              },
              "resolution": {
                "description": "Defaults to 2k.",
                "type": "string",
                "enum": [
                  "2k",
                  "4k"
                ]
              },
              "aspect_ratio": {
                "description": "Defaults to auto.",
                "type": "string",
                "enum": [
                  "auto",
                  "16:9",
                  "9:16",
                  "1:1",
                  "4:3",
                  "3:4",
                  "3:2",
                  "2:3",
                  "21:9"
                ]
              }
            },
            "additionalProperties": false,
            "if": {
              "properties": {
                "result_type": {
                  "const": "series"
                }
              },
              "required": [
                "result_type"
              ]
            },
            "then": {
              "properties": {
                "series_amount": {
                  "type": "integer",
                  "minimum": 2,
                  "maximum": 10
                }
              }
            }
          },
          "options": {
            "type": "object",
            "properties": {
              "watermark_info": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean",
                    "const": false
                  }
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "model",
          "contents"
        ],
        "additionalProperties": false
      },
      "TaskAccepted": {
        "type": "object",
        "required": [
          "id",
          "model",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "model": {
            "const": "kling-image-4-0"
          },
          "status": {
            "const": "processing"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "Task": {
        "type": "object",
        "required": [
          "id",
          "model",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "model": {
            "const": "kling-image-4-0"
          },
          "status": {
            "enum": [
              "processing",
              "completed",
              "failed"
            ]
          },
          "created_at": {
            "type": "integer"
          },
          "finished_at": {
            "type": "integer"
          },
          "output": {
            "type": "object",
            "properties": {
              "created": {
                "type": "integer"
              },
              "data": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "url"
                  ],
                  "properties": {
                    "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"
          }
        }
      }
    }
  }
}
