帳戶餘額查詢 API
介面說明
帳戶餘額查詢用於讓使用者透過自己的 API Key 查詢 New API 帳戶餘額。該介面只查詢餘額,不會觸發生成任務,也不會扣費。
介面位址: GET /api/user/balance
計費: 免費。
餘額單位: yuan。介面中 effective_amount 已按 quota_per_unit 換算為使用者可理解的元金額。
請求參數
Headers
| 參數名 | 型別 | 必填 | 說明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer YOUR_API_KEY |
Query 參數
無。
請求範例
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"];
?>
回應結果
{
"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"
}
}
}
欄位說明
| 欄位 | 型別 | 說明 |
|---|---|---|
balance.user_quota |
number | 使用者帳戶剩餘額度原始值 |
balance.token_quota |
number | 目前 API Key 剩餘額度原始值;無限額度 key 按使用者餘額返回 |
balance.effective_quota |
number | 目前 API Key 實際可用額度原始值 |
balance.effective_amount |
number | 已換算後的可實際使用金額 |
balance.amount_unit |
string | 固定為 yuan |
balance.formatted_effective_amount |
string | 可直接展示給使用者看的餘額字串 |
display.quota_per_unit |
number | 原始額度換算單位,金額 = quota / quota_per_unit |
說明
- 本介面使用的 API Key 和生成介面相同。
- 當 API Key 餘額耗盡時,仍允許查詢餘額。
- 停用或過期的 API Key 不能查詢。
- 介面不返回 USD、CNY、
$或¥,統一使用yuan,避免使用者理解偏差。