{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/musicsforyou-com/json-schema/musicsforyou-com-generate-request-schema.json",
  "title": "GenerateRequest",
  "description": "spec、rendered、prompt 三选一 / Provide exactly one of spec, rendered or prompt",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/musicsforyou-com-openapi.json#/components/schemas/GenerateRequest",
  "type": "object",
  "properties": {
    "spec": {
      "$ref": "#/$defs/GenerationSpec",
      "description": "推荐：compile 返回的 spec，服务端会重新校验 / Recommended: the spec from compile (re-linted server side)"
    },
    "rendered": {
      "$ref": "#/$defs/RenderedInput"
    },
    "prompt": {
      "type": "string",
      "minLength": 1,
      "maxLength": 3000,
      "description": "不经编译的一句描述，由供应商自己写词 / Plain prompt, provider writes lyrics itself"
    },
    "instrumental": {
      "type": "boolean",
      "default": false
    },
    "model": {
      "type": "string",
      "description": "可选模型 id / Optional model id (see GET /v1/capabilities)"
    },
    "parentId": {
      "type": "string",
      "description": "作为哪首作品的修改版 / Parent generation id"
    },
    "idempotencyKey": {
      "type": "string",
      "minLength": 8,
      "maxLength": 128,
      "description": "幂等键：同键重复提交返回同一条 generation / Idempotency key"
    }
  },
  "anyOf": [
    {
      "required": [
        "spec"
      ]
    },
    {
      "required": [
        "rendered"
      ]
    },
    {
      "required": [
        "prompt"
      ]
    }
  ],
  "$defs": {
    "CompileRequestEcho": {
      "type": "object",
      "properties": {
        "userText": {
          "type": "string"
        },
        "uiLanguage": {
          "$ref": "#/$defs/UiLanguage"
        },
        "sceneId": {
          "type": [
            "string",
            "null"
          ]
        },
        "lyricLanguage": {
          "oneOf": [
            {
              "$ref": "#/$defs/LyricLanguage"
            },
            {
              "type": "null"
            }
          ]
        },
        "vocalPreference": {
          "oneOf": [
            {
              "$ref": "#/$defs/VocalPreference"
            },
            {
              "type": "null"
            }
          ]
        },
        "instrumental": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "durationSeconds": {
          "type": [
            "number",
            "null"
          ]
        },
        "userLyrics": {
          "oneOf": [
            {
              "$ref": "#/$defs/UserLyrics"
            },
            {
              "type": "null"
            }
          ]
        },
        "clarificationAnswer": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "userText",
        "uiLanguage"
      ]
    },
    "CompositionPlan": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "titleAlternatives": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "centralIdea": {
          "type": "string"
        },
        "hook": {
          "type": [
            "string",
            "null"
          ]
        },
        "genre": {
          "type": "object",
          "properties": {
            "primary": {
              "type": "string"
            },
            "accents": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "primary",
            "accents"
          ]
        },
        "tempo": {
          "type": "object",
          "properties": {
            "feel": {
              "type": "string"
            },
            "bpmHint": {
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "feel",
            "bpmHint"
          ]
        },
        "instruments": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "role": {
                "type": "string",
                "enum": [
                  "lead",
                  "rhythm",
                  "harmony",
                  "accent"
                ]
              }
            },
            "required": [
              "name",
              "role"
            ]
          }
        },
        "vocal": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "gender": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "m",
                "f"
              ]
            },
            "texture": {
              "type": "string"
            }
          },
          "required": [
            "gender",
            "texture"
          ]
        },
        "sections": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Section"
          }
        },
        "styleDraft": {
          "type": "object",
          "properties": {
            "identity": {
              "type": "string"
            },
            "mood": {
              "type": "string"
            },
            "rhythm": {
              "type": "string"
            },
            "instrumentation": {
              "type": "string"
            },
            "production": {
              "type": "string"
            }
          },
          "required": [
            "identity",
            "mood",
            "rhythm",
            "instrumentation",
            "production"
          ]
        },
        "exclusions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "explanation": {
          "type": "string"
        }
      },
      "required": [
        "title",
        "titleAlternatives",
        "centralIdea",
        "hook",
        "genre",
        "tempo",
        "instruments",
        "vocal",
        "sections",
        "styleDraft",
        "exclusions",
        "explanation"
      ],
      "description": "作曲方案 / Composition plan"
    },
    "Diagnostic": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "severity": {
          "type": "string",
          "enum": [
            "error",
            "warning",
            "info"
          ]
        },
        "path": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "autoFixable": {
          "type": "boolean"
        }
      },
      "required": [
        "code",
        "severity",
        "path",
        "message",
        "autoFixable"
      ]
    },
    "GenerationSpec": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "type": "string",
          "const": "3.0"
        },
        "id": {
          "type": "string"
        },
        "revision": {
          "type": "integer"
        },
        "parentSpecId": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "ready",
            "needs_input",
            "needs_revision"
          ],
          "description": "ready 可提交；needs_input 看 question 追问；needs_revision 看 error 级 diagnostics / ready = submit; needs_input = ask `question`; needs_revision = fix error diagnostics"
        },
        "profileId": {
          "type": "string"
        },
        "request": {
          "$ref": "#/$defs/CompileRequestEcho"
        },
        "intent": {
          "oneOf": [
            {
              "$ref": "#/$defs/IntentSpec"
            },
            {
              "type": "null"
            }
          ]
        },
        "composition": {
          "oneOf": [
            {
              "$ref": "#/$defs/CompositionPlan"
            },
            {
              "type": "null"
            }
          ]
        },
        "rendered": {
          "oneOf": [
            {
              "$ref": "#/$defs/Rendered"
            },
            {
              "type": "null"
            }
          ]
        },
        "diagnostics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Diagnostic"
          }
        },
        "question": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "question": {
              "type": "string"
            },
            "field": {
              "type": "string"
            }
          },
          "required": [
            "question",
            "field"
          ]
        },
        "explanation": {
          "type": "string",
          "description": "给用户看的解释 / Explanation for the end user"
        },
        "provenance": {
          "$ref": "#/$defs/Provenance"
        }
      },
      "required": [
        "schemaVersion",
        "id",
        "revision",
        "parentSpecId",
        "status",
        "profileId",
        "request",
        "intent",
        "composition",
        "rendered",
        "diagnostics",
        "question",
        "explanation",
        "provenance"
      ],
      "description": "编译结果（GenerationSpec v3）。原样回传给 POST /v1/generations 即可生成 / Compiled spec; pass it back unchanged to generate."
    },
    "IntentSpec": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "song",
            "instrumental"
          ]
        },
        "sceneId": {
          "type": [
            "string",
            "null"
          ]
        },
        "genreRefs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "lyricLanguage": {
          "oneOf": [
            {
              "$ref": "#/$defs/LyricLanguage"
            },
            {
              "type": "null"
            }
          ]
        },
        "vocalPreference": {
          "oneOf": [
            {
              "$ref": "#/$defs/VocalPreference"
            },
            {
              "type": "null"
            }
          ]
        },
        "moods": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tempoFeel": {
          "type": [
            "string",
            "null"
          ]
        },
        "artistRefs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "requestedTraits": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "name",
              "requestedTraits"
            ]
          }
        },
        "facts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PersonalFact"
          }
        },
        "exclusions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "term": {
                "type": "string"
              },
              "sourceQuote": {
                "type": "string"
              }
            },
            "required": [
              "term",
              "sourceQuote"
            ]
          }
        },
        "durationSeconds": {
          "type": [
            "number",
            "null"
          ]
        },
        "assumptions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "clarification": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "question": {
              "type": "string"
            },
            "field": {
              "type": "string"
            }
          },
          "required": [
            "question",
            "field"
          ]
        }
      },
      "required": [
        "kind",
        "sceneId",
        "genreRefs",
        "lyricLanguage",
        "vocalPreference",
        "moods",
        "tempoFeel",
        "artistRefs",
        "facts",
        "exclusions",
        "durationSeconds",
        "assumptions",
        "clarification"
      ],
      "description": "解析出的意图 / Parsed intent"
    },
    "LyricLanguage": {
      "type": "string",
      "enum": [
        "zh",
        "yue",
        "en",
        "ja"
      ],
      "description": "歌词语言 / Lyric language (yue = Cantonese)"
    },
    "PersonalFact": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "person",
            "relationship",
            "date",
            "place",
            "memory",
            "phrase",
            "trait"
          ]
        },
        "value": {
          "type": "string"
        },
        "sourceQuote": {
          "type": "string"
        },
        "inclusion": {
          "type": "string",
          "enum": [
            "required",
            "optional"
          ]
        },
        "preservation": {
          "type": "string",
          "enum": [
            "exact",
            "semantic"
          ]
        },
        "preferredSection": {
          "type": "string",
          "enum": [
            "chorus",
            "verse",
            "bridge",
            "any"
          ]
        }
      },
      "required": [
        "id",
        "kind",
        "value",
        "sourceQuote",
        "inclusion",
        "preservation",
        "preferredSection"
      ]
    },
    "Provenance": {
      "type": "object",
      "properties": {
        "compilerVersion": {
          "type": "string"
        },
        "parserModel": {
          "type": [
            "string",
            "null"
          ]
        },
        "composerModel": {
          "type": [
            "string",
            "null"
          ]
        },
        "knowledgeIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "llmCalls": {
          "type": "number"
        },
        "cached": {
          "type": "boolean"
        }
      },
      "required": [
        "compilerVersion",
        "parserModel",
        "composerModel",
        "knowledgeIds",
        "llmCalls",
        "cached"
      ]
    },
    "Rendered": {
      "type": "object",
      "properties": {
        "model": {
          "type": "string",
          "description": "供应商模型 id / Provider model id"
        },
        "instrumental": {
          "type": "boolean"
        },
        "title": {
          "type": "string"
        },
        "style": {
          "type": "string",
          "description": "英文风格标签，逗号分隔 / English style tags, comma separated"
        },
        "lyrics": {
          "type": [
            "string",
            "null"
          ],
          "description": "带 [Verse]/[Chorus] 段落标记的歌词 / Lyrics with section markers"
        },
        "negativeTags": {
          "type": [
            "string",
            "null"
          ]
        },
        "vocalGender": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "m",
            "f"
          ]
        },
        "duration": {
          "type": [
            "number",
            "null"
          ],
          "description": "秒 / seconds"
        }
      },
      "required": [
        "model",
        "instrumental",
        "title",
        "style",
        "lyrics",
        "negativeTags",
        "vocalGender",
        "duration"
      ],
      "description": "可直接提交生成的字段 / Fields ready to submit to generate_music"
    },
    "RenderedInput": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "maxLength": 200
        },
        "style": {
          "type": "string",
          "maxLength": 2000
        },
        "lyrics": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 10000
        },
        "negativeTags": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 500
        },
        "vocalGender": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "m",
            "f"
          ]
        },
        "styleWeight": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "weirdnessConstraint": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "audioWeight": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        },
        "duration": {
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "title",
        "style"
      ],
      "description": "高级模式：直接给渲染字段 / Advanced: submit rendered fields directly"
    },
    "Section": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "intro",
            "verse",
            "pre_chorus",
            "chorus",
            "post_chorus",
            "bridge",
            "instrumental",
            "outro"
          ]
        },
        "label": {
          "type": "string"
        },
        "cues": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "段落级表演提示 / Performance cues"
        },
        "lines": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "歌词行；器乐段为空 / Lyric lines, empty for instrumental sections"
        },
        "usedFactIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "id",
        "kind",
        "label",
        "cues",
        "lines",
        "usedFactIds"
      ]
    },
    "UiLanguage": {
      "type": "string",
      "enum": [
        "zh",
        "en",
        "ja"
      ],
      "description": "界面/解释文字语言 / Language of explanations"
    },
    "UserLyrics": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "maxLength": 10000,
          "description": "用户自带歌词 / User-supplied lyrics"
        },
        "action": {
          "type": "string",
          "enum": [
            "preserve",
            "edit"
          ],
          "description": "preserve 一字不改；edit 允许润色 / preserve = keep verbatim, edit = may polish"
        }
      },
      "required": [
        "text",
        "action"
      ]
    },
    "VocalPreference": {
      "type": "string",
      "enum": [
        "m",
        "f",
        "duet",
        "choir"
      ],
      "description": "人声偏好 / Vocal preference"
    }
  }
}