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 或錯誤訊息傳給我們,我們來查。