API truy vấn số dư tài khoản
Mô tả endpoint
Truy vấn số dư tài khoản cho phép người dùng kiểm tra số dư tài khoản New API bằng khóa API của mình. Endpoint này chỉ truy vấn số dư; không tạo tác vụ tạo nhạc và không tính phí.
Endpoint: GET /api/user/balance
Tính phí: Miễn phí.
Đơn vị số dư: yuan. Trong phản hồi, effective_amount đã được quy đổi qua quota_per_unit thành số tiền nhân dân tệ mà người dùng hiểu được.
Tham số yêu cầu
Headers
| Tham số | Kiểu | Bắt buộc | Ghi chú |
|---|---|---|---|
| Authorization | string | có | Bearer YOUR_API_KEY |
Tham số query
Không có.
Ví dụ yêu cầu
cURL
curl -X GET https://www.suno-api.io/api/user/balance \
-H "Authorization: Bearer YOUR_API_KEY"
Python
import requests
api_key = "YOUR_API_KEY"
response = requests.get(
"https://www.suno-api.io/api/user/balance",
headers={"Authorization": f"Bearer {api_key}"},
timeout=30,
)
response.raise_for_status()
result = response.json()
balance = result["data"]["balance"]
print(balance["formatted_effective_amount"])
Node.js
const apiKey = "YOUR_API_KEY";
const response = await fetch("https://www.suno-api.io/api/user/balance", {
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const result = await response.json();
console.log(result.data.balance.formatted_effective_amount);
PHP
<?php
$apiKey = "YOUR_API_KEY";
$ch = curl_init("https://www.suno-api.io/api/user/balance");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $apiKey
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
$result = json_decode($response, true);
echo $result["data"]["balance"]["formatted_effective_amount"];
?>
Phản hồi
{
"success": true,
"message": "",
"data": {
"object": "user_balance",
"user": {
"id": 123,
"username": "example",
"quota": 207900000,
"used_quota": 0,
"request_count": 10,
"group": "default",
"status": 1
},
"token": {
"id": 456,
"name": "default",
"group": "default",
"status": 1,
"remain_quota": 207900000,
"used_quota": 0,
"unlimited_quota": true,
"model_limits_enabled": false,
"model_limits": {}
},
"balance": {
"user_quota": 207900000,
"token_quota": 207900000,
"effective_quota": 207900000,
"user_amount": 415.8,
"token_amount": 415.8,
"effective_amount": 415.8,
"amount_unit": "yuan",
"formatted_effective_amount": "415.80 yuan"
},
"display": {
"quota_per_unit": 500000,
"amount_unit": "yuan"
}
}
}
Tham chiếu trường
| Trường | Kiểu | Ghi chú |
|---|---|---|
balance.user_quota |
number | Giá trị gốc số dư còn lại của tài khoản người dùng |
balance.token_quota |
number | Giá trị gốc số dư còn lại của khóa API hiện tại; khóa không giới hạn sẽ trả về số dư người dùng |
balance.effective_quota |
number | Giá trị gốc số dư thực tế khả dụng cho khóa API hiện tại |
balance.effective_amount |
number | Số tiền thực tế khả dụng sau khi quy đổi |
balance.amount_unit |
string | Cố định là yuan |
balance.formatted_effective_amount |
string | Chuỗi số dư có thể hiển thị trực tiếp cho người dùng |
display.quota_per_unit |
number | Đơn vị quy đổi số dư gốc; số tiền = quota / quota_per_unit |
Lưu ý
- Endpoint này dùng cùng khóa API như các endpoint tạo nhạc.
- Khi số dư của khóa API đã cạn, việc truy vấn số dư vẫn được phép.
- Khóa API bị vô hiệu hóa hoặc hết hạn không thể truy vấn.
- Endpoint không trả về USD, CNY,
$hay¥, mà luôn dùngyuanđể tránh hiểu nhầm.
Lấy khóa API
Tạo khóa API trong bảng điều khiển sau khi đăng ký. Mỗi lần tạo tốn 0,6 ¥ và trả về 2 bản nhạc, tải xuống không giới hạn và không cần số điện thoại.
Lấy khóa API Quay lại tổng quan