聊天方式:生成歌曲
简洁描述:使用 Suno 聊天接口生成歌曲文本内容。
概览
- 请求方法:
POST - 路径:
/v1/chat/completions - 内容类型:
application/json
认证方式
- Header:
Authorization: Bearer <token> - Header:
Content-Type: application/json
请求示例
Header
| Header | 示例 | 必填 |
|---|---|---|
| Content-Type | application/json | 是 |
| Authorization | Bearer sk-xxxx | 是 |
请求体参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 是 | 模型名称,可选 suno-v3 或 suno-v3.5 |
| messages | array | 是 | 消息列表,包含 role 和 content |
| stream | boolean | 否 | 是否开启流式输出,推荐 true |
curl 示例
bash
curl -X POST "https://api.gpt.ge/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxx" \
-d '{
"model": "suno-v3.5",
"messages": [
{
"role": "user",
"content": "生成一首欢快的中文歌曲"
}
],
"stream": true
}'JavaScript (fetch) 示例
javascript
fetch('https://api.gpt.ge/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxx'
},
body: JSON.stringify({
model: 'suno-v3.5',
messages: [
{ role: 'user', content: '生成一首欢快的中文歌曲' }
],
stream: true
})
}).then(r => r.json()).then(console.log);Python (requests) 示例
python
import requests
response = requests.post(
'https://api.gpt.ge/v1/chat/completions',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxx'
},
json={
'model': 'suno-v3.5',
'messages': [
{ 'role': 'user', 'content': '生成一首欢快的中文歌曲' }
],
'stream': True
}
)
print(response.json())返回示例(200)
json
{
"id": "chatcmpl-1234567890",
"object": "chat.completion",
"created": 1712345678,
"model": "suno-v3.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "这里是一首欢快的中文歌曲歌词...",
"refusal": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 50,
"completion_tokens": 120,
"total_tokens": 170
},
"system_fingerprint": "abc123xyz"
}注意:此接口适用于 Suno 系列音乐创作场景,支持与其他聊天模型通用的接口格式。