ToAPIsToAPIs
帳戶查詢

查詢帳戶餘額

使用系統存取權杖讀取目前帳戶的資料

GET
/api/v1/account/balance

中國大陸用戶請注意: 中國大陸用戶請使用 https://toapis.cn 作為接口地址 (Base URL). 文檔示例中的 https://toapis.com 請替換為 https://toapis.cn.

驗證, 分頁及錯誤處理請參閱接入說明.

使用說明

balance_kind=account_balance 為帳戶餘額, subaccount_budget 為子帳戶自身預算, 不讀取父帳戶金額. remaining_* 及 used_* 來自同一快照, 以回傳的 credits_per_usd 換算.

驗證

Authorizationstring請求頭必填

使用系統存取權杖, 格式為 Bearer YOUR_SYSTEM_ACCESS_TOKEN. 此介面不接受模型 API Key, 不需要 X-User-Id.

請求參數

此介面不接受路徑或查詢參數, 不需要請求主體.

請求示例

curl --request GET \
  --url 'https://toapis.com/api/v1/account/balance' \
  --header 'Authorization: Bearer YOUR_SYSTEM_ACCESS_TOKEN'
import requests

response = requests.get(
    "https://toapis.com/api/v1/account/balance",
    headers={"Authorization": "Bearer YOUR_SYSTEM_ACCESS_TOKEN"},
    timeout=30,
)
response.raise_for_status()
print(response.json())
const url = new URL("https://toapis.com/api/v1/account/balance");

const response = await fetch(url, {
  headers: { Authorization: "Bearer YOUR_SYSTEM_ACCESS_TOKEN" },
  signal: AbortSignal.timeout(30_000),
});

if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.json());

回應欄位

範例使用虛構資料, 並假設 credits_per_usd="100". 實際換算請以回應為準.

codeinteger

業務狀態碼, 成功時為 0.

messagestring

回應訊息, 成功時為空字串. 錯誤訊息依請求語言回傳.

dataobject

本次查詢的結果物件.

data.remaining_creditsstring

剩餘額度, 單位為 credits. 以十進位字串回傳以保留精度.

data.used_creditsstring

已用額度, 單位為 credits. 以十進位字串回傳以保留精度.

data.remaining_usdstring

剩餘額度換算的 USD 金額. 以十進位字串回傳以保留精度.

data.used_usdstring

已用額度換算的 USD 金額. 以十進位字串回傳以保留精度.

data.credits_per_usdstring

每 1 USD 對應的 credits 數量. 請以此值換算. 以十進位字串回傳以保留精度.

data.balance_kindstring

account_balance 為帳戶餘額, subaccount_budget 為子帳戶自身預算, 不含父帳戶餘額.

響應示例

{
  "code": 0,
  "message": "",
  "data": {
    "remaining_credits": "1000",
    "remaining_usd": "10",
    "used_credits": "100",
    "used_usd": "1",
    "credits_per_usd": "100",
    "balance_kind": "account_balance"
  }
}