{
  "openapi": "3.1.0",
  "info": {
    "title": "灵动 API",
    "version": "2026.09",
    "description": "灵动 API 公开图片、视频、任务和余额接口。模型能力与价格以 GET /api/pricing 的实时返回为准。创建任务遇到超时或未知状态时，不应自动重复提交。",
    "contact": {
      "name": "灵动 API",
      "url": "https://www.lingdongapi.com/"
    }
  },
  "servers": [
    {
      "url": "https://www.lingdongapi.com",
      "description": "正式环境"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/video/generations": {
      "post": {
        "operationId": "createVideoGeneration",
        "summary": "创建视频生成任务",
        "description": "参考素材必须是无需登录即可访问的公网 URL。创建请求可能计费，客户端不得因超时自动重复提交。",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VideoGenerationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "任务已创建；从响应中取得任务 ID，后续始终沿用该 ID 查询。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/video/generations/{task_id}": {
      "get": {
        "operationId": "getVideoGeneration",
        "summary": "查询视频生成任务",
        "parameters": [
          {
            "$ref": "#/components/parameters/TaskId"
          }
        ],
        "responses": {
          "200": {
            "description": "任务详情",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VideoTask"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/images/generations": {
      "post": {
        "operationId": "createImageGeneration",
        "summary": "创建图片生成请求",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageGenerationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "图片生成响应；具体字段以线上响应为准。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos/{task_id}/content": {
      "get": {
        "operationId": "getVideoContent",
        "summary": "下载已完成的视频",
        "description": "仅在任务状态为 completed 后调用。支持 HEAD 和 Range 请求。",
        "parameters": [
          {
            "$ref": "#/components/parameters/TaskId"
          }
        ],
        "responses": {
          "200": {
            "description": "视频文件",
            "content": {
              "video/*": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/dashboard/billing/balance": {
      "get": {
        "operationId": "getBillingBalance",
        "summary": "查询账户余额与累计已用金额",
        "responses": {
          "200": {
            "description": "账户余额；不要缓存该响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingBalance"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/pricing": {
      "get": {
        "operationId": "listPublicModelPricing",
        "summary": "读取公开模型能力、计费方式和实时价格",
        "security": [],
        "responses": {
          "200": {
            "description": "公开模型列表和 pricing_version；支持 ETag。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PublicModel"
                      }
                    },
                    "pricing_version": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "在 Authorization 请求头中发送 Bearer API_KEY。"
      }
    },
    "parameters": {
      "TaskId": {
        "name": "task_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "IdempotencyKey": {
        "name": "X-Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "业务侧唯一字符串，用于避免客户端重试造成重复提交。",
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "公开错误响应",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "VideoGenerationRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "当前可调用的公开模型名。",
            "examples": [
              "cvk-k"
            ]
          },
          "prompt": {
            "type": "string"
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "videos": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "audios": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "ratio": {
            "type": "string",
            "examples": [
              "16:9",
              "9:16"
            ]
          },
          "duration": {
            "type": "number"
          },
          "resolution": {
            "type": "string",
            "examples": [
              "720p"
            ]
          },
          "watermark": {
            "type": "boolean",
            "default": false
          },
          "notify_url": {
            "type": "string",
            "format": "uri",
            "description": "仅支持公网 HTTPS 443 地址。"
          },
          "notify_secret": {
            "type": "string",
            "minLength": 8,
            "maxLength": 512
          }
        },
        "additionalProperties": false
      },
      "ImageGenerationRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "examples": [
              "gpt-image-2.5-flare"
            ]
          },
          "prompt": {
            "type": "string"
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "size": {
            "type": "string",
            "examples": [
              "1024x1024"
            ]
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "default": 1
          },
          "notify_url": {
            "type": "string",
            "format": "uri"
          },
          "notify_secret": {
            "type": "string",
            "minLength": 8,
            "maxLength": 512
          }
        },
        "additionalProperties": false
      },
      "VideoTask": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "task_id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "completed",
              "failed"
            ]
          },
          "progress": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "completed_at": {
            "type": "integer"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "video_url": {
            "type": "string",
            "format": "uri"
          }
        },
        "additionalProperties": true
      },
      "BillingBalance": {
        "type": "object",
        "required": [
          "object",
          "balance",
          "used_balance",
          "currency",
          "currency_symbol"
        ],
        "properties": {
          "object": {
            "type": "string",
            "examples": [
              "billing_balance"
            ]
          },
          "balance": {
            "type": "number"
          },
          "used_balance": {
            "type": "number"
          },
          "currency": {
            "type": "string"
          },
          "currency_symbol": {
            "type": "string",
            "examples": [
              "¥"
            ]
          }
        },
        "additionalProperties": true
      },
      "PublicModel": {
        "type": "object",
        "properties": {
          "model_name": {
            "type": "string"
          },
          "callable": {
            "type": "boolean"
          },
          "group_name": {
            "type": "string"
          },
          "billing_unit": {
            "type": "string",
            "enum": [
              "request",
              "second",
              "token"
            ]
          },
          "model_price": {
            "type": "number"
          },
          "max_reference_images": {
            "type": "integer"
          },
          "max_reference_videos": {
            "type": "integer"
          },
          "max_reference_audios": {
            "type": "integer"
          },
          "supported_duration": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "supported_ratios": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported_resolutions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "supported_qualities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "notes": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      }
    }
  }
}
