{
  "openapi": "3.1.0",
  "info": {
    "title": "云影 YUNFRAME 视频生成 API",
    "version": "v1",
    "summary": "视频生成对外接口：模型目录、报价、创建任务、查询、下载、素材与积分",
    "description": "Base URL 形如 https://<站点地址>/functions/v1/app，所有路径以其为服务器地址前缀。鉴权只认创建时保存的 API Key（Bearer）。重要：站点网关会先进入同源检查，POST 与 DELETE 必须携带 Origin: <站点地址>，缺失或写成其他站点会直接返回 403 request origin is invalid；GET 不受此限制。积分、模型规格与价格由后台配置决定，请以 GET /v1/models 与 POST /v1/videos/quote 的实时返回为准。",
    "contact": {
      "name": "云影 YUNFRAME"
    }
  },
  "servers": [
    {
      "url": "https://yunframe-studio-a1duq57mvk2.qoder.zone/functions/v1/app",
      "description": "正式站点"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "目录",
      "description": "服务与模型信息"
    },
    {
      "name": "视频",
      "description": "报价、创建、查询、下载、取消"
    },
    {
      "name": "素材",
      "description": "参考图片、视频、音频"
    },
    {
      "name": "积分",
      "description": "余额与流水"
    }
  ],
  "paths": {
    "/v1/service-status": {
      "get": {
        "tags": [
          "目录"
        ],
        "operationId": "serviceStatus",
        "summary": "服务状态",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "apiVersion": {
                      "type": "string",
                      "const": "v1"
                    },
                    "pricingRevision": {
                      "type": "string"
                    },
                    "models": {
                      "type": "integer",
                      "description": "启用中的模型数量"
                    },
                    "acceptingJobs": {
                      "type": "boolean"
                    },
                    "checkedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "目录"
        ],
        "operationId": "listModels",
        "summary": "模型目录与计价规则",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "pricingRevision": {
                      "type": "string"
                    },
                    "checkedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "models": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/balance": {
      "get": {
        "tags": [
          "积分"
        ],
        "operationId": "getBalance",
        "summary": "余额与冻结积分",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "balance": {
                      "type": "integer",
                      "description": "可用积分"
                    },
                    "heldPoints": {
                      "type": "integer",
                      "description": "在途任务冻结积分"
                    },
                    "pointsPerYuan": {
                      "type": "integer",
                      "description": "多少积分等于 1 元，当前为 10"
                    },
                    "pricingRevision": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/ledger": {
      "get": {
        "tags": [
          "积分"
        ],
        "operationId": "listLedger",
        "summary": "积分流水（最近 50 条）",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "transactions": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "$ref": "#/components/schemas/Transaction"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos/quote": {
      "post": {
        "tags": [
          "视频"
        ],
        "operationId": "quoteVideo",
        "summary": "报价（不建任务、不扣积分）",
        "parameters": [
          {
            "$ref": "#/components/parameters/Origin"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "pricingRevision": {
                      "type": "string"
                    },
                    "quote": {
                      "$ref": "#/components/schemas/Quote"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos": {
      "post": {
        "tags": [
          "视频"
        ],
        "operationId": "createVideo",
        "summary": "创建生成任务",
        "description": "首次受理返回 201 created:true；使用相同 clientReference 与完全相同参数重放返回 200 created:false 并给出原任务。参数不同则 409 idempotency_conflict。请求体上限 384 KB，出现未列出的字段返回 400 invalid_input。上游暂停接单时仍返回 201，任务停在 queued 并在 errorCode 说明原因，积分保持冻结且不会自动重试。",
        "parameters": [
          {
            "$ref": "#/components/parameters/Origin"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "已创建并冻结积分",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResponse"
                }
              }
            }
          },
          "200": {
            "description": "命中原订单",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "tags": [
          "视频"
        ],
        "operationId": "listVideos",
        "summary": "本账户最近任务",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 50
            },
            "description": "没有 offset 分页，最多返回最近 50 条"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "jobs": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "$ref": "#/components/schemas/Job"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos/{id}": {
      "get": {
        "tags": [
          "视频"
        ],
        "operationId": "getVideo",
        "summary": "任务详情（含提示词）",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "job": {
                      "$ref": "#/components/schemas/Job"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos/{id}/cancel": {
      "post": {
        "tags": [
          "视频"
        ],
        "operationId": "cancelVideo",
        "summary": "取消排队中的任务",
        "description": "已完成、已失败、待核对的任务返回 409 video_cancel_not_allowed。取消成功后冻结积分释放。上游暂停接单而停在 queued 的任务同样可以取消并退回积分。",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          },
          {
            "$ref": "#/components/parameters/Origin"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "job": {
                      "$ref": "#/components/schemas/Job"
                    },
                    "wallet": {
                      "type": "object"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/videos/{id}/content": {
      "get": {
        "tags": [
          "视频"
        ],
        "operationId": "downloadVideo",
        "summary": "下载成片",
        "description": "分片归档时直接返回 video/mp4 字节流并支持 Range；单文件归档时返回 application/json，携带约 5 分钟内有效的 url，需要再请求一次该地址。未完成 409 video_not_ready，过期 410 video_content_expired。",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          },
          {
            "name": "Range",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "example": "bytes=0-"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "MP4 字节流",
            "content": {
              "video/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "206": {
            "description": "Range 分片"
          },
          "416": {
            "description": "Range 不合法"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/assets": {
      "post": {
        "tags": [
          "素材"
        ],
        "operationId": "createAsset",
        "summary": "上传参考素材",
        "description": "base64 与 url 二选一。base64 是纯内容编码，解码后 ≤ 8 MB；url 必须是公网 HTTPS，禁止内网地址、端口、账号信息与重定向，拉取 ≤ 15 MB 且实际 Content-Type 必须与声明一致。",
        "parameters": [
          {
            "$ref": "#/components/parameters/Origin"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssetRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "asset": {
                      "$ref": "#/components/schemas/Asset"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "tags": [
          "素材"
        ],
        "operationId": "listAssets",
        "summary": "本账户最近素材（最多 50 个）",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "assets": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "$ref": "#/components/schemas/Asset"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/assets/{id}": {
      "delete": {
        "tags": [
          "素材"
        ],
        "operationId": "deleteAsset",
        "summary": "删除未被任务占用的素材",
        "parameters": [
          {
            "$ref": "#/components/parameters/AssetId"
          },
          {
            "$ref": "#/components/parameters/Origin"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "deleted": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "网站「API 密钥」页创建的密钥，形如 yf_ + 40 位十六进制字符"
      }
    },
    "parameters": {
      "JobId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "AssetId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "Origin": {
        "name": "Origin",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "example": "https://yunframe-studio-a1duq57mvk2.qoder.zone"
        },
        "description": "站点网关同源检查：写请求必须携带本站地址，否则 403 request origin is invalid"
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "maxLength": 200
        },
        "description": "与请求体 clientReference 等价的订单编号"
      }
    },
    "responses": {
      "Error": {
        "description": "错误响应（扁平结构）",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string",
                  "description": "错误编号，见文档错误码表"
                },
                "request_id": {
                  "type": "string"
                }
              }
            },
            "example": {
              "error": "insufficient_points",
              "request_id": "6f1c2a34-0000-0000-0000-000000000000"
            }
          }
        }
      }
    },
    "schemas": {
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "提交时填写的 modelId"
          },
          "name": {
            "type": "string"
          },
          "family": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "highlights": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "resolutions": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "480p",
                "720p",
                "1080p"
              ]
            }
          },
          "ratios": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "16:9",
                "9:16",
                "1:1",
                "4:3",
                "3:4",
                "21:9"
              ]
            }
          },
          "seconds": {
            "type": "object",
            "description": "按画质给出时长范围",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "min": {
                  "type": "integer"
                },
                "max": {
                  "type": "integer"
                },
                "default": {
                  "type": "integer"
                }
              }
            }
          },
          "referenceLimits": {
            "$ref": "#/components/schemas/ReferenceLimits"
          },
          "billing": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "per_second"
                  },
                  "pointsPerSecond": {
                    "type": "integer"
                  }
                }
              },
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "per_item"
                  },
                  "pointsShort": {
                    "type": "integer"
                  },
                  "pointsLong": {
                    "type": "integer"
                  },
                  "shortMaxSeconds": {
                    "type": "integer",
                    "const": 15
                  }
                }
              }
            ]
          }
        }
      },
      "ReferenceLimits": {
        "type": "object",
        "properties": {
          "images": {
            "type": "integer"
          },
          "videos": {
            "type": "integer"
          },
          "audios": {
            "type": "integer"
          },
          "total_media": {
            "type": "integer"
          },
          "video_seconds": {
            "type": "integer"
          },
          "audio_seconds": {
            "type": "integer"
          }
        }
      },
      "QuoteRequest": {
        "type": "object",
        "required": [
          "modelId",
          "seconds"
        ],
        "additionalProperties": false,
        "properties": {
          "modelId": {
            "type": "string"
          },
          "seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 300
          },
          "ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "4:3",
              "3:4",
              "21:9",
              "auto"
            ]
          },
          "resolution": {
            "type": "string",
            "enum": [
              "480p",
              "720p",
              "1080p"
            ]
          },
          "expectedPoints": {
            "type": "integer"
          },
          "expectedPricingRevision": {
            "type": "string"
          }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "modelId": {
            "type": "string"
          },
          "modelName": {
            "type": "string"
          },
          "seconds": {
            "type": "integer"
          },
          "ratio": {
            "type": "string"
          },
          "resolution": {
            "type": "string"
          },
          "billingMode": {
            "type": "string",
            "enum": [
              "per_second",
              "per_item"
            ]
          },
          "points": {
            "type": "integer",
            "description": "本次要扣的积分，整数，无需换算"
          },
          "currency": {
            "type": "string",
            "const": "points"
          },
          "maxReferenceBytes": {
            "type": "integer"
          },
          "supportedSeconds": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "supportedRatios": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "referenceLimits": {
            "$ref": "#/components/schemas/ReferenceLimits"
          }
        }
      },
      "CreateRequest": {
        "type": "object",
        "required": [
          "modelId",
          "prompt",
          "seconds"
        ],
        "additionalProperties": false,
        "properties": {
          "modelId": {
            "type": "string"
          },
          "prompt": {
            "type": "string",
            "maxLength": 45000,
            "description": "去空格后非空"
          },
          "seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 300
          },
          "ratio": {
            "type": "string",
            "enum": [
              "16:9",
              "9:16",
              "1:1",
              "4:3",
              "3:4",
              "21:9",
              "auto"
            ]
          },
          "resolution": {
            "type": "string",
            "enum": [
              "480p",
              "720p",
              "1080p"
            ]
          },
          "referenceIds": {
            "type": "array",
            "maxItems": 50,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "clientReference": {
            "type": "string",
            "pattern": "^[\\x20-\\x7e]{1,200}$"
          },
          "expectedPoints": {
            "type": "integer"
          },
          "expectedPricingRevision": {
            "type": "string"
          }
        }
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "created": {
            "type": "boolean",
            "description": "false 表示命中原订单"
          },
          "job": {
            "$ref": "#/components/schemas/Job"
          },
          "pricingRevision": {
            "type": "string"
          },
          "balance": {
            "type": "integer"
          },
          "heldPoints": {
            "type": "integer"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "requestId": {
            "type": "string",
            "format": "uuid",
            "description": "clientReference 折算出的稳定编号"
          },
          "modelId": {
            "type": "string"
          },
          "modelName": {
            "type": "string"
          },
          "seconds": {
            "type": "integer"
          },
          "ratio": {
            "type": "string"
          },
          "billingMode": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "preparing",
              "submitting",
              "queued",
              "processing",
              "completed",
              "failed",
              "cancelled",
              "needs_review"
            ]
          },
          "points": {
            "type": "integer"
          },
          "providerStatus": {
            "type": "string"
          },
          "errorCode": {
            "type": "string"
          },
          "storageStatus": {
            "type": "string"
          },
          "archiveMode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "chunked",
              "single",
              null
            ]
          },
          "retentionDays": {
            "type": [
              "integer",
              "null"
            ]
          },
          "downloadAvailable": {
            "type": "boolean"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "providerExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "referenceCount": {
            "type": "integer"
          },
          "prompt": {
            "type": "string",
            "description": "仅任务详情返回"
          }
        }
      },
      "AssetRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string"
          },
          "contentType": {
            "type": "string",
            "enum": [
              "image/jpeg",
              "image/png",
              "image/webp",
              "video/mp4",
              "video/quicktime",
              "video/webm",
              "audio/mpeg",
              "audio/wav",
              "audio/x-wav",
              "audio/mp3"
            ]
          },
          "base64": {
            "type": "string",
            "description": "纯 Base64，解码后 ≤ 8 MB"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "公网 HTTPS，拉取 ≤ 15 MB"
          },
          "durationSeconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3600
          }
        }
      },
      "Asset": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "fileId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "image",
              "video",
              "audio"
            ]
          },
          "sizeBytes": {
            "type": "integer"
          },
          "contentType": {
            "type": "string"
          },
          "durationSeconds": {
            "type": [
              "integer",
              "null"
            ]
          },
          "status": {
            "type": "string"
          },
          "assignedJobId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "hold",
              "release",
              "settle",
              "redemption",
              "credit"
            ]
          },
          "points": {
            "type": "integer"
          },
          "availableDelta": {
            "type": "integer"
          },
          "heldDelta": {
            "type": "integer"
          },
          "description": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
