使用AI模型生成带或不带歌词的音乐。
custom_mode、instrumental、modelcustom_mode: true):title 必填,最多 80 字符prompt 可选;提供时将严格作为歌词使用并在生成的音轨中演唱。若同时传入 lyrics,优先使用 lyrics 作为歌词style、lyrics、negative_tags 至少提供一项,全部为空时将拒绝生成instrumental: true:生成纯音乐(无歌词)instrumental: false:使用 lyrics(未传则回退到 prompt)作为歌词duration、negative_tags、vocal_gender、style_weight、weirdness_constraint、audio_weight、variety、persona_id、persona_modelprompt 3000字符,style 200字符prompt 5000字符,style 1000 字符style 1000字符;lyrics 5000字符title 长度限制:80字符(所有模型)custom_mode: false):prompt 可选;作为 核心创意,歌词将根据它自动生成(不严格匹配输入),最多 3000 字符lyrics 可作为歌词附件,与 prompt 同时使用image_urls、video_urls、audio_urls、style、lyrics 至少提供一项,全部为空时将拒绝生成image_urls、video_urls、audio_urls 仅在此模式下有效duration、vocal_gender、style_weight、weirdness_constraint、audio_weight、variety、persona_id、persona_modelstyle+ lyrics +image_urls +video_urls +audio_urlsprompt(string):描述所需音频内容的提示词。可选。自定义模式下作为歌词;非自定义模式下作为核心创意(最多 3000 字符)。lyrics(string):歌词内容。可选。V6 最多 5000 字符。自定义模式优先于 prompt 作为歌词;非自定义模式可作为歌词附件与 prompt 同时使用。image_urls(array):图片参考。仅在 custom_mode 为 false 时有效。最多 5 张,单张不超过 10 MB,支持 jpeg、png、webp、bmp。video_urls(array):视频参考。仅在 custom_mode 为 false 时有效。最多 1 个,单个不超过 100 MB,时长不超过 241 秒,支持 mp4、mov、webm。audio_urls(array):音频参考。仅在 custom_mode 为 false 时有效。时长需在 6 秒至 30 分钟之间,单个不超过 500 MB。style(string):音乐风格规范。字符限制见上方「参数详情」。negative_tags(string):从生成音频中排除的音乐风格或特征。可选。vocal_gender(string):人声性别偏好。m 男声,f 女声。仅在 custom_mode 为 true 时生效。根据实践,此参数只能加强概率,但不能保证一定遵循男女声的指令。style_weight(number):对指定风格的遵循强度。范围 0–1,保留两位小数。仅在 custom_mode 为 true 时有效。weirdness_constraint(number):创意/离散程度。范围 0–1,保留两位小数。仅在 custom_mode 为 true 时有效。audio_weight(number):音频要素相对权重。范围 0–1,保留两位小数。仅在 custom_mode 为 true 时有效。variety(number):生成结果的多样性。范围 0–4 的整数,默认 1。仅在 custom_mode 为 true 时有效。0 off(严格同一风格),1 normal(默认,平衡),2 high(风格差异明显),3 extra(大胆探索),4 max(最大差异)。persona_id(string):Persona ID 或 Voice ID。可选。要生成 Persona ID,请访问 生成 Persona 接口。persona_model(string):persona 模型,可选 style_persona 或 voice_persona。仅 V5(已废弃)、V5.5(已废弃)、V6、V6_MINI、V6_WILD 可用。duration(number):音频时长,单位为秒。范围 10–360,默认 20。仅在 custom_mode 为 true 且 model 为 custom_mode: false 开始使用,更简单text(文本生成)、first(第一首完成)、complete(全部完成)curl --location 'https://api.kie.ai/api/v1/jobs/createTask' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "ai-music-api/generate",
"callBackUrl": "https://api.example.com/callback",
"input": {
"prompt": "A calm and relaxing piano track with soft melodies",
"custom_mode": true,
"instrumental": true,
"model": "V4",
"style": "Classical",
"title": "Peaceful Piano Meditation",
"negative_tags": "Heavy Metal, Upbeat Drums",
"vocal_gender": "m",
"style_weight": 0.65,
"weirdness_constraint": 0.65,
"audio_weight": 0.65,
"persona_id": "persona_123",
"persona_model": "style_persona",
"duration": 20
}
}'{
"code": 200,
"msg": "success",
"data": {
"taskId": "5c79****be8e"
}
}