音乐生成
Billing Rules
0.035 美元 每次请求,模型为 v4.5-all,有且仅有这一个模型。
基础配置
Base URL: https://api.foxaihub.com/api/v2
HTTP 头部
{
"api-key": "Your API Key",
}
任务提交
Endpoint: /music/task
Method: POST
Content-Type: application/json
HTTP body, 允许传入不同的参数,实现不同的生成模式。
- 1. 描述
- 2. 自定义
- 3. 续写
{
"topic": "a song about spring",
"is_instrumental": true
}
解释:topic 字段是对歌曲的描述,is_instrumental 用于控制是否包含人声。
{
"tags": "female vocal, pop, dream pop",
"lyrics": "[Verse 1]\nIn waves of starlit magic\nMy heart turns so tragic\nYou say you love another\nWhile my mind turns static\nTell me what you need\nAs thoughts turn sporadic\nThis love fades faster than the titanic\n\n[Chorus]\nI float through endless melodies\nPast echoes of \"I'm sorry\"\nI just want another last chance\n\n[Verse 2]\nIn this ethereal haze, why am I alone?\nI just wanna be loved, drift with someone to hold\nMemories shimmer bright when I called on the phone\nBut now the calls you answer are his and not my own\n\n[Chorus]\nI float through endless melodies\nLost in this sweet romance\nPast echoes of \"I'm sorry\"\nI just want another last chance"
}
解释:tags字段用于描述音乐的标签,注意,该字段为字符串类型。 lyrics字段是歌词,如果为空,则表示无人声。
Coming soon.
响应
{
"success": true,
"task_id": "4f3acce5-eb32-46b4-9c96-9cc1e2b2c922"
}
task_id 作为追踪该任务的唯一 id。
结果查询
路径: /music/task?ids=
每次最少查询1 个任务结果,最多查询 25 个任务结果,不同task_id通过逗号隔开。
/task?ids=0196bd6d-57a4-7000-96c6-f74ee7998e5f,0196bd6d-acc0-7000-81ae-a56d8b0631b6
方法: GET
HTTP 响应,根据状态可区分如下几种结果
- 1. processing
- 2. queued
- 3. streaming
- 4. completed
- 5. failed
表述任务尚在处理,data 字段还没有有效的数据。
任务已经进入生成队列。
[
{
"status": "queued",
"task_id": "5d23ace6-c7da-4429-a48d-b6d235c629ac",
"gen_params": {
"topic": "female vocal, pop, dream pop",
"is_instrumental": true
},
"data": {
"clip_ids": [
"b5ced187-1e86-484c-b8a3-1eb9356d95ce",
"c37ee650-349f-4bc3-9418-bf0e7587ea65"
]
},
"created_at": "2026-03-16T08:36:04.000Z",
"updated_at": "2026-03-16T08:36:05.000Z"
}
]
任务返回可以流式播放的 audio_url 地址,但是任务还尚未彻底完成。
[
{
"status": "streaming",
"task_id": "4f3acce5-eb32-46b4-9c96-9cc1e2b2c922",
"gen_params": {
"tags": "female vocal, pop, dream pop",
"lyrics": "[Verse 1]\nIn waves"
},
"data": [
{
"id": "a7737313-9815-438d-920d-ff29d07d064c",
"title": "",
"handle": "zafs8qv",
"status": "streaming",
"user_id": "2dba1255-ebac-4e9b-a1d5-2b92d7a1fcb1",
"has_hook": false,
"is_liked": false,
"metadata": {
"tags": "female vocal, pop, dream pop",
"task": "",
"type": "gen",
"prompt": "[Verse 1]\nIn waves ",
"stream": true,
"has_stem": false,
"is_remix": false,
"priority": 0,
"can_remix": true,
"is_mumble": false,
"model_badges": {
"songrow": {...},
"make_instrumental": false,
"uses_latest_model": false
},
"audio_url": "https://audiopipe.sonic.ai/?item_id=a7737313-9815-438d-920d-ff29d07d064c",
"image_url": "https://cdn2.sonic.ai/image_a7737313-9815-438d-920d-ff29d07d064c.jpeg",
"is_hidden": false,
"is_public": false,
"video_url": "",
"created_at": "2026-03-16T08:06:47.787Z",
"flag_count": 0,
"is_trashed": false,
"model_name": "chirp-auk",
"play_count": 0,
"batch_index": 0,
"entity_type": "song_schema",
"display_name": "zafs8qv",
"upvote_count": 0,
"comment_count": 0,
"allow_comments": true,
"image_large_url": "https://cdn2.sonic.ai/image_large_a7737313-9815-438d-920d-ff29d07d064c.jpeg",
"is_contest_clip": false,
"avatar_image_url": "https://cdn1.sonic.ai/sAura5.jpg",
"is_handle_updated": false,
"major_model_version": "v4.5-all",
"is_following_creator": false
},
{...和上一条数据格式一致}
],
"created_at": "2026-03-16T08:06:45.000Z",
"updated_at": "2026-03-16T08:07:02.000Z"
}
]
任务生成完毕,audio_url 字段,可以下载最终的音频。
[
{
"status": "completed",
"task_id": "4f3acce5-eb32-46b4-9c96-9cc1e2b2c922",
"gen_params": {
"tags": "female vocal, pop, dream pop",
"lyrics": "[Verse 1]\nIn waves of ..."
},
"data": [
{
"status": "complete",
"title": "",
"play_count": 0,
"upvote_count": 0,
"allow_comments": true,
"id": "a7737313-9815-438d-920d-ff29d07d064c",
"entity_type": "song_schema",
"video_url": "",
"audio_url": "https://cdn1.sonic.ai/a7737313-9815-438d-920d-ff29d07d064c.mp3",
"image_url": "https://cdn2.sonic.ai/image_a7737313-9815-438d-920d-ff29d07d064c.jpeg",
"image_large_url": "https://cdn2.sonic.ai/image_large_a7737313-9815-438d-920d-ff29d07d064c.jpeg",
"major_model_version": "v4.5-all",
"model_name": "chirp-auk",
"metadata": {
"tags": "female vocal, pop, dream pop",
"prompt": "[Verse 1]\nIn waves of ...",
"type": "gen",
"duration": 149,
"refund_credits": false,
"stream": true,
"make_instrumental": false,
"task": "",
"can_remix": true,
"is_remix": false,
"priority": 0,
"has_stem": false,
"uses_latest_model": false,
"model_badges": {
"songrow": {...}
},
"is_mumble": false
},
"is_liked": false,
"user_id": "2dba1255-ebac-4e9b-a1d5-2b92d7a1fcb1",
"display_name": "zafs8qv",
"handle": "zafs8qv",
"is_handle_updated": false,
"avatar_image_url": "https://cdn1.sonic.ai/sAura5.jpg",
"is_trashed": false,
"is_hidden": false,
"created_at": "2026-03-16T08:06:47.787Z",
"is_public": false,
"is_following_creator": false,
"explicit": false,
"comment_count": 0,
"flag_count": 0,
"is_contest_clip": false,
"has_hook": false,
"batch_index": 0
},
{...和上一条数据格式一致}
]
可能由于超时或者提交任 务的参数有问题,最终导致任务失败。data字段会给出原因。
开发建议:只关注 streaming,completed 以及 failed状态,并且设置一个任务超时时间。
例如,生成任务从提交到拿到结果,通常不会超过 6 分钟,一旦大于这个时间阈值,便可以判定任务失败,从而防止无限轮询。
进阶
如果有 webhook 需求,我也乐于去开发,这样可以减轻使用者的开发工作量。