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"
  }
}