Skip to content

suno音乐模型 使用指南

请求地址

https://www.dmxapi.cn

模型列表

  • chirp-v4
  • chirp-v3-5

示例代码

python
# 导入所需模块
import http.client  # 用于发送 HTTP 请求
import json  # 用于处理 JSON 数据

# 创建 HTTPS 连接到 dmxapi 服务器
conn = http.client.HTTPSConnection("www.dmxapi.cn")

# 构建请求体,包含音乐生成所需的参数
payload = json.dumps({
   # prompt: 歌词内容,包含verse标记来划分段落(prompt 3000字符内)
   "prompt": "[Verse]\nWalking down the streets\nBeneath the city lights\nNeon signs flickering\nLighting up the night\nHeart beating faster\nLike a drum in my chest\nI'm alive in this moment\nFeeling so blessed\n\nStilettos on the pavement\nStepping with grace\nSurrounded by the people\nMoving at their own pace\nThe rhythm of the city\nIt pulses in my veins\nLost in the energy\nAs my worries drain\n\n[Verse 2]\nConcrete jungle shining\nWith its dazzling glow\nEvery corner hiding secrets that only locals know\nA symphony of chaos\nBut it's music to my ears\nThe hustle and the bustle\nWiping away my fears",

   "tags": "emotional punk",  # 音乐风格标签(tags 200字符)

   "mv": "chirp-v4",  # 使用的模型版本 (chirp-v4/chirp-v3-5)

   "title": "City Lights",  # 歌曲标题

   "make_instrumental": True,  #True 为生成纯音乐,

})

# 设置请求头
headers = {
   'Authorization': 'Bearer sk-******************************',  # API 认证令牌
   'Content-Type': 'application/json'  # 指定请求体格式为 JSON
}

# 发送 POST 请求到 Suno 音乐生成接口
conn.request("POST", "/suno/submit/music", payload, headers)

# 获取响应
res = conn.getresponse()

# 读取响应数据
data = res.read()

# 打印响应结果(解码为 UTF-8 字符串)
print(data.decode("utf-8"))

返回示例

json
{"code":"success","data":"fcaae939-a503-491c-a6f0-28f681809b7d","message":""}

生成数据读取

python
# 导入所需模块
import http.client  # 用于发送 HTTP 请求
import json  # 用于处理 JSON 数据

# 创建 HTTPS 连接到 dmxapi 服务器
conn = http.client.HTTPSConnection("www.dmxapi.cn")

# 要查询的任务 ID
task_id = "fcaae939-a503-491c-a6f0-28f681809b7d"

# 设置请求头
headers = {
   'Authorization': 'Bearer sk-******************************',  # API 认证令牌
   'Content-Type': 'application/json'  # 指定请求体格式为 JSON
}

# 发送 GET 请求查询任务结果
conn.request("GET", f"/suno/fetch/{task_id}", headers=headers)

# 获取响应
res = conn.getresponse()

# 读取响应数据
data = res.read()

# 解析 JSON 响应
result = json.loads(data.decode("utf-8"))

# 检查请求是否成功
if result.get("code") == "success":
    task_data = result.get("data", {})
    status = task_data.get("status", "UNKNOWN")
    progress = task_data.get("progress", "0%")

    print(f"任务状态: {status}")
    print(f"生成进度: {progress}")

    # 如果生成成功,显示音频 URL
    if status == "SUCCESS":
        print("\n" + "=" * 50)
        print("生成完成!音频下载地址:")
        print("=" * 50)
        songs = task_data.get("data", [])
        for i, song in enumerate(songs, 1):
            title = song.get("title", "未知")
            duration = song.get("duration", 0)
            audio_url = song.get("audio_url", "")
            image_url = song.get("image_url", "")

            minutes = int(duration // 60)
            seconds = int(duration % 60)

            print(f"\n【歌曲 {i}{title}")
            print(f"  时长: {minutes}{seconds}秒")
            print(f"  音频: {audio_url}")
            print(f"  封面: {image_url}")
    else:
        print(f"\n任务进行中,请稍后再查询...")
else:
    print(f"查询失败: {result.get('message', '未知错误')}")

返回示例

json
任务状态: SUCCESS
生成进度: 100%

==================================================
生成完成!音频下载地址:
==================================================

【歌曲 1】City Lights
  时长: 329
  音频: https://cdn1.suno.ai/e99d7164-9d07-431e-95f3-a9b482c9c15a.mp3
  封面: https://cdn2.suno.ai/image_e99d7164-9d07-431e-95f3-a9b482c9c15a.jpeg

【歌曲 2】City Lights
  时长: 353
  音频: https://cdn1.suno.ai/0dceac36-e44b-42e0-8041-0b59a60f9be1.mp3
  封面: https://cdn2.suno.ai/image_0dceac36-e44b-42e0-8041-0b59a60f9be1.jpeg

API 密钥安全

⚠️ 重要:示例代码中的 API 密钥仅供演示,请务必:

  • 使用您自己的 API 密钥
  • 不要将密钥硬编码在代码中
  • 建议通过环境变量管理密钥
  • 不要将包含真实密钥的代码提交到公开仓库

© 2025 DMXAPI suno音乐模型

一个 Key 用全球大模型