API 参考

音乐

这个接口能用的模型(1)

在工作台试一下
POST/v1/music/generations
GET/v1/music/tasks/{task_id}
GET/v1/music/tasks/{task_id}/content

一个接口做 Suno 歌曲、歌词和 32 个工具。每次调用立刻返回 task_id;轮询任务(或用 webhook)直到完成,然后读取文件。

#请求参数

  • modelstring必填

    模型页上的音乐模型 ID:suno。

  • operationstring可选

    要做什么:music(默认)生成歌曲,lyrics 写歌词,下面的工具用来编辑、续写、分析或导出歌曲。

  • promptstring可选

    灵感模式:歌曲内容描述,最多 3000 字。自定义模式:歌词,最多 5000 字。自定义模式的纯音乐可以不填。lyrics 时:写歌词的要求。

  • customboolean可选

    false(默认):灵感模式,prompt 描述歌曲。true:自定义模式,prompt 是歌词,title、style、negative_tags、auto_lyrics、persona_id、duration 和 max_mode 生效。

  • instrumentalboolean可选

    true:不要人声。

  • versionstring可选

    v6(默认)、v6-wild 或 v6-mini。设置了 custom_model_id 时不要传。

  • titlestring可选

    歌名,最多 80 字。自定义模式。

  • stylestring可选

    风格标签,如曲风、情绪、乐器,最多 1000 字。自定义模式。也可以用 tags。

  • negative_tagsstring可选

    不想要的风格。自定义模式。

  • vocal_genderstring可选

    Male(男声)或 Female(女声)。

  • auto_lyricsboolean可选

    true:创意改写给定的歌词。自定义模式。

  • style_weightnumber可选

    0 到 1:歌曲贴合风格的程度。0 也是有效值。

  • weirdness_constraintnumber可选

    0 到 1:歌曲的大胆程度。

  • audio_weightnumber可选

    0 到 1:参考录音的影响程度。

  • varietystring可选

    off、normal、high、extra 或 max:结果之间的差异程度。

  • max_modeboolean可选

    true:Max 模式,质量更高,价格翻倍。自定义模式。

  • audio_formatstring可选

    mp3, m4a or wav.

  • durationinteger可选

    目标时长(秒),10 到 360。自定义模式;成品时长可能不同。

  • persona_idstring可选

    用 persona 工具做出的歌手 Persona。自定义模式;不能和 custom_model_id 同时用。

  • custom_model_idstring可选

    用 create-model 训练的模型。替代 version;不能和 persona_id 同时用。

  • parametersobject可选

    工具自己的字段(见下方「工具」),例如所处理歌曲的 task_id 和 audio_index。

  • webhook_urlstring可选

    任务进入终态后回调的 HTTPS 地址。

  • webhook_secretstring可选

    设置后,回调带 X-Xiaoxiang-Signature: sha256=hex(HMAC-SHA256(body, secret))。

两种写歌方式

灵感模式(custom false):在 prompt 里描述歌曲,歌词会自动写好。自定义模式(custom true):prompt 放你的歌词,style、title 等自定义字段决定歌曲样子。先只用 prompt 开始。

#处理你做过的歌

处理歌曲的工具要传 task_id(本接口返回的、做出这首歌的任务)和 audio_index(这首歌在该任务里的位置:第一首是 1,第二首是 2)。只能用你自己已完成的 Suno 任务。

要从你自己的录音开始,先用 upload 导入,或者用 upload-cover、upload-extend,它们直接接收 audio_url。add-vocals、add-instrumental 和 sample 只接受导入的录音。

#工具

把工具名放在 operation,字段放在 parameters。必填字段已标出;价格是一首歌价格的倍数。

Create

  • inspoInspiration references×1.36可开 Max 模式

    Generate a new song from 1–4 public audio references.

    audio_urls*tags

  • soundsSound effects×0.192

    Generate a sound effect from a text description.

    prompt*type

  • upsample-tagsEnhance style tags×0.08

    Expand and refine music style tags.

    tags*

  • mashupMashup×1可开 Max 模式

    Create a mashup from exactly two platform tasks.

    task_ids*audio_indexestags

Start from your own audio

  • uploadImport audio×0.08

    Import external audio for use in later studio operations.

    audioFilePath*

  • upload-coverCover your audio×1可开 Max 模式

    Upload audio and remake it in a new style in one step.

    audio_url*customtagspromptinstrumental

  • upload-extendExtend your audio×1可开 Max 模式

    Upload audio and continue it from a chosen second.

    audio_url*continue_at*prompttags

  • add-vocalsAdd vocals×1可开 Max 模式

    Layer vocals onto your uploaded instrumental or song.

    task_id*audio_indexcustomprompttags

  • add-instrumentalAdd instrumental×1可开 Max 模式

    Layer an instrumental onto your uploaded vocals or song.

    task_id*audio_indextags

  • sampleSample to song×1可开 Max 模式

    Generate a new song from an existing song or sample.

    task_id*audio_indexstart_s*end_s*instrumentaltags

Edit a song

  • extendExtend song×1可开 Max 模式

    Continue and extend an existing song from a specified time.

    task_id*audio_indexcontinue_at*prompttags

  • concatAssemble full song×0.08

    Assemble existing segments into a complete song.

    task_id*audio_index

  • coverStyle cover×1可开 Max 模式

    Rearrange an existing song in a new musical style.

    task_id*audio_indextags

  • replaceReplace section×1可开 Max 模式

    Regenerate the music within a specified time range.

    task_id*audio_indexstart_s*end_s*infill_lyrics

  • remove-sectionRemove section×0.16

    Remove a specified time range from a song.

    task_id*audio_indexstart_s*end_s*

  • cropCrop audio×0.16

    Keep only the specified time range.

    task_id*audio_indexstart_s*end_s*

  • fade-inFade in×0.16

    Add a fade-in effect to the beginning of a song.

    task_id*audio_indexduration_s*

  • fade-outFade out×0.16

    Add a fade-out effect to the end of a song.

    task_id*audio_indexduration_s*

  • adjust-speedAdjust speed×0.48

    Change playback speed without changing pitch.

    task_id*audio_indexspeed*keep_pitch

  • remasterRemaster×1

    Improve the clarity, loudness, and overall texture of a song.

    task_id*audio_indexvariation_category

  • add-stemAdd a stem×1可开 Max 模式

    Layer a new stem onto an existing song.

    task_id*audio_indextags

Stems, voices and models

  • stemsExtract a stem×2

    Extract a selected stem from a song.

    task_id*audio_indexstem_type

  • stems-allSeparate all stems×4.8

    Separate every available stem in a song.

    task_id*audio_index

  • personaCreate Persona×0.08

    Create a singer Persona from a song or Vox result.

    task_id*audio_indexname*describestyles

  • create-voiceCreate voice×0.32

    Create a reusable voice from a public audio URL.

    audio_url*

  • create-modelTrain a custom model×19.2

    Train a model on 6–24 of your own tracks, then use it as custom_model_id. Training can take about 20 minutes.

    name*audio_urls*

  • voxExtract Vox×0.08已弃用

    Deprecated: make a Persona straight from a song instead.

    task_id*audio_indexvocal_start_svocal_end_s

Export and analyse

  • downloadDownload audio×0.032

    Get a song as MP3, M4A or WAV files.

    task_id*audio_indexformats

  • generate-mp4Generate music video×0.08

    Render a song as an MP4 music video.

    task_id*audio_index

  • midiGenerate MIDI×1

    Convert a song into a MIDI result.

    task_id*audio_index

  • aligned-lyricsLyrics timeline×0.016

    Generate a line-aligned lyrics timeline.

    task_id*audio_index

  • bpmAnalyze BPM×0.016

    Analyze the tempo of a song.

    task_id*audio_index

* 为必填。在工作台的「工具」里,可以为你做过的歌自动填好这些字段。

#价格

一首歌按目录价收费,每次请求出两首。工具按这个价格乘以它的倍数收费,支持的工具开 max_mode 价格翻倍。报价和预扣按这些倍数计算,任务按实际费用结算,失败的任务全额退回。

#结果

GET /v1/music/tasks/{task_id} 随时可查;GET /v1/music/tasks/{task_id}/content 在任务完成后返回第一首歌的音频文件(之前是 400)。完成的任务包含:

  • url

    第一首歌的音频。

  • assets

    任务做出的每个文件:type(audio、video、image、midi、archive 或 file)和 url。

  • data.music

    各首歌的 audio_url,按顺序。

  • data.lyrics

    歌词:text 和 title。

  • data.result

    工具自己的结果:music[](audio_id、title、lyrics、tags、duration、audio_url、image_url)、persona_id、model_id、upsampled_tags、avg_bpm、files、videoUrl、alignment 等。

  • billing

    任务结算后的费用。

请下载你需要的文件:文件保留 3 天。

#相关错误码

  • 400 invalid_request缺少操作需要的字段(task_id_required、continue_at_required …)或超出范围(style_weight_out_of_range、duration_out_of_range、max_mode_requires_custom …)。不扣费。
  • 400 source_task_not_foundtask_id 不是你已完成的 Suno 任务;任务还在跑时返回 source_task_not_ready。
  • 410 media_expired任务的文件已在 3 天后删除。任务还没完成就读取 /content 会返回 400:请改为轮询任务。
  • 404 not_found路径不存在、模型名不存在,或 task_id 已过期 / 不属于当前账号。
  • 401Bearer 令牌无效或缺失。这条路径不带 error.code,请按状态码判断。
  • 402 insufficient_user_quota钱包余额不足以覆盖预扣估算。
  • 429账号请求频率上限(默认每分钟 500 次模型请求)。请退避后重试,有 Retry-After 时按它等待。若 429 带有 insufficient_user_quota,那是每日消费上限,不是限流。
  • 503 model_not_found模型名不存在,或当前没有健康渠道可以服务它。

完整错误码表 →

#请求示例

# a song: describe it
curl https://apiking.ai/v1/music/generations \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "suno", "prompt": "a warm cinematic piano theme", "instrumental": true}'

# or write the lyrics yourself
curl https://apiking.ai/v1/music/generations \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "suno", "custom": true, "title": "Neon Rain",
       "prompt": "[Verse]\nCity lights in the rain\n[Chorus]\nWe run till dawn",
       "style": "synthwave, female vocal"}'

# poll every 5s until completed
curl https://apiking.ai/v1/music/tasks/$TASK_ID -H "Authorization: Bearer sk-YOUR_KEY"

# a tool on the second song: extend it from 0:60
curl https://apiking.ai/v1/music/generations \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "suno", "operation": "extend",
       "parameters": {"task_id": "'$TASK_ID'", "audio_index": 2, "continue_at": 60}}'

#响应

response.json
// POST — submit accepted
{"id": "task_xxx", "task_id": "task_xxx", "object": "music.task", "model": "suno", "status": "queued"}

// GET /v1/music/tasks/{task_id}
{
  "task_id": "task_xxx",
  "object": "music.task",
  "operation": "music",
  "status": "completed",
  "progress": "100%",
  "url": "https://…/audio/task_xxx",
  "assets": [
    {"type": "audio", "url": "https://…"},
    {"type": "audio", "url": "https://…"},
    {"type": "image", "url": "https://…"}
  ],
  "data": {
    "music": [{"audio_url": "https://…"}],
    "lyrics": {"title": "Neon Rain", "text": "[Verse] …"},
    "result": {"music": [{"audio_id": "…", "title": "Neon Rain", "duration": 182.4, "audio_url": "https://…", "image_url": "https://…"}]}
  },
  "billing": {"…": "…"}
}

还是没解决?

把请求 ID 或报错信息发给我们,我们来查。