アカウント残高照会 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を使うため、ユーザーの誤解を避けられます。