API 参考

余额与用量查询

GET https://api.flyrouter.ai/v1/dashboard/billing/subscription

GET https://api.flyrouter.ai/v1/dashboard/billing/usage

用 API Key 直接查询这个 Key 的额度和已用金额,格式兼容 OpenAI 旧版账单接口,许多客户端(如 CC-Switch、各类余额监控脚本)可以直接使用。金额单位为美元。

查询额度

终端
curl https://api.flyrouter.ai/v1/dashboard/billing/subscription \
  -H "Authorization: Bearer $FLYROUTER_API_KEY"
json
{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 20,
  "hard_limit_usd": 20,
  "system_hard_limit_usd": 20,
  "access_until": -1
}
字段说明
hard_limit_usd这个 Key 的总额度(剩余 + 已用),单位美元。Key 未设置额度上限时固定返回 100000000
access_untilKey 的过期时间(Unix 时间戳),-1 表示永不过期

查询已用金额

终端
curl https://api.flyrouter.ai/v1/dashboard/billing/usage \
  -H "Authorization: Bearer $FLYROUTER_API_KEY"
json
{
  "object": "list",
  "total_usage": 512.5
}

total_usage 是这个 Key 累计已用的金额,单位为美分(上例即 $5.125)。

计算剩余额度

balance.py
import os, requests

base = "https://api.flyrouter.ai"
headers = {"Authorization": f"Bearer {os.environ['FLYROUTER_API_KEY']}"}

total = requests.get(f"{base}/v1/dashboard/billing/subscription", headers=headers).json()["hard_limit_usd"]
used = requests.get(f"{base}/v1/dashboard/billing/usage", headers=headers).json()["total_usage"] / 100

if total >= 100000000:
    print(f"这个 Key 不限额度,已用 ${used:.2f}")
else:
    print(f"已用 ${used:.2f},剩余 ${total - used:.2f}")

这两个接口统计的是单个 Key。账户的总余额请在控制台查看;想让脚本能监控余额,可以给 Key 设置额度上限,再用上面的方法计算剩余额度。

FlyRouter

一个 Key,直飞全球大模型