{
  "openapi": "3.0.3",
  "info": {
    "title": "爱乐评 Open API",
    "description": "AI 歌曲分析服务的开放接口。上传音频文件，返回编曲、人声、结构、歌词四个维度的专业点评与评分。默认隐私模式：分析完成后服务器立即删除音频文件，不保留任何分析记录。每次分析消耗 10 积分，积分在 https://aiyueping.com 网页端充值。",
    "version": "1.0.0",
    "contact": {
      "name": "爱乐评客服",
      "email": "molingg@gmail.com",
      "url": "https://aiyueping.com"
    }
  },
  "servers": [
    {
      "url": "https://aiyueping.com",
      "description": "生产环境"
    }
  ],
  "security": [
    {
      "apiKeyAuth": []
    }
  ],
  "paths": {
    "/v1/analyze": {
      "post": {
        "operationId": "analyzeSong",
        "summary": "分析歌曲",
        "description": "上传音频文件进行 AI 分析，返回各维度评分与点评。分析通常需要 30~90 秒，客户端超时建议设置为 300 秒以上。每次调用消耗 10 积分，分析失败不扣积分。",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["audio"],
                "properties": {
                  "audio": {
                    "type": "string",
                    "format": "binary",
                    "description": "音频文件（mp3/wav/flac/m4a 等常见格式，最大 80MB）"
                  },
                  "song_name": {
                    "type": "string",
                    "description": "歌曲名，缺省时取上传文件名"
                  },
                  "author_name": {
                    "type": "string",
                    "description": "作者名"
                  },
                  "lyrics": {
                    "type": "string",
                    "description": "歌词文本（多行）。强烈建议提供：有歌词时歌词维度的分析准确得多"
                  },
                  "mode": {
                    "type": "string",
                    "enum": ["privacy", "private", "public"],
                    "default": "privacy",
                    "description": "privacy=分析后不保留任何数据（默认）；private=保存到账号但不公开；public=保存并参与公开排行"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "分析成功",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnalyzeResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/InsufficientCredits" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/AnalyzeFailed" }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "getMe",
        "summary": "查询账号与积分余额",
        "description": "返回当前 API Key 对应账号的基本信息和剩余积分。",
        "responses": {
          "200": {
            "description": "查询成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "user": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string", "description": "用户ID" },
                        "name": { "type": "string", "description": "用户昵称" },
                        "credits": { "type": "integer", "description": "剩余积分", "example": 1640 }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API Key 鉴权。在 https://aiyueping.com 完成充值后，进入「个人主页 → API 密钥」创建 Key（形如 hys_xxxx，明文只展示一次）。请求头格式：Authorization: Bearer <API Key>"
      }
    },
    "schemas": {
      "DimensionScore": {
        "type": "object",
        "properties": {
          "score": { "type": "number", "description": "该维度得分（0~10，纯音乐的人声/歌词维度为 0）", "example": 7.8 },
          "comments": { "type": "string", "description": "该维度的专业点评" }
        }
      },
      "AnalyzeResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "mode": { "type": "string", "enum": ["privacy", "private", "public"], "description": "本次分析使用的数据保留模式" },
          "credits_remaining": { "type": "integer", "description": "扣费后的剩余积分", "example": 1640 },
          "data": {
            "type": "object",
            "properties": {
              "song_name": { "type": "string" },
              "authorName": { "type": "string" },
              "overall_score": { "type": "number", "description": "总分（各有效维度平均）", "example": 7.6 },
              "comments": { "type": "string", "description": "整体点评" },
              "arrangement": { "$ref": "#/components/schemas/DimensionScore" },
              "vocal": { "$ref": "#/components/schemas/DimensionScore" },
              "structure": { "$ref": "#/components/schemas/DimensionScore" },
              "lyrics": { "$ref": "#/components/schemas/DimensionScore" },
              "tags": {
                "type": "array",
                "items": { "type": "string" },
                "description": "风格/元素标签",
                "example": ["#民谣", "#女声", "#中文"]
              },
              "song_id": { "type": "string", "description": "仅 mode=private/public 时返回，可在网页端查看该歌曲" },
              "percentiles": { "type": "object", "description": "仅 mode=private/public 时返回，各维度在全站的百分位" }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": false },
          "message": { "type": "string", "description": "错误说明（中文）" }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "参数错误（未上传文件、mode 取值非法等）",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Unauthorized": {
        "description": "API Key 缺失、无效或已被删除",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "InsufficientCredits": {
        "description": "积分不足，请到 https://aiyueping.com 充值",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RateLimited": {
        "description": "请求过于频繁（单 IP 每 10 分钟最多 30 次分析），按 Retry-After 响应头稍后重试",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "AnalyzeFailed": {
        "description": "分析失败（模型错误、音频无法解析等），失败不扣积分",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    }
  }
}
