Skip to content

查询余额与用量

查询账户额度和使用情况,兼容 OpenAI Billing API 格式。

接口地址

GET https://foxapi.chat/v1/dashboard/billing/subscription
GET https://foxapi.chat/v1/dashboard/billing/usage

前置条件

拥有一个 FoxAPI Key(获取教程

查询账户信息

curl

bash
curl https://foxapi.chat/v1/dashboard/billing/subscription \
  -H "Authorization: Bearer sk-你的Key"

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-你的Key",
    base_url="https://foxapi.chat/v1"
)

subscription = client.billing.subscription()
print(subscription)

返回示例

json
{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 100000000,
  "hard_limit_usd": 100000000,
  "system_hard_limit_usd": 100000000,
  "access_until": 0
}
字段说明
has_payment_method账户是否有效(true = 正常可用)
soft_limit_usd软限额(系统默认值,无需关注)
hard_limit_usd硬限额(系统默认值,无需关注)
access_until会员到期时间(0 = 无限制)

查询已用额度

curl

bash
curl "https://foxapi.chat/v1/dashboard/billing/usage?start_date=2026-06-01&end_date=2026-06-07" \
  -H "Authorization: Bearer sk-你的Key"

Python

python
from openai import OpenAI
from datetime import datetime, timedelta

client = OpenAI(
    api_key="sk-你的Key",
    base_url="https://foxapi.chat/v1"
)

# 查询最近 7 天用量
end = datetime.now()
start = end - timedelta(days=7)

usage = client.billing.usage(
    start_date=start.strftime("%Y-%m-%d"),
    end_date=end.strftime("%Y-%m-%d")
)
print(f"已用额度: ${usage.total_usage}")

请求参数

参数类型必填格式说明
start_datestringYYYY-MM-DD查询起始日期
end_datestringYYYY-MM-DD查询结束日期

返回示例

json
{
  "object": "list",
  "total_usage": 0.199
}
字段说明
total_usage该时间段内的总消耗(美元)

计算剩余可用额度

接口本身不直接返回剩余可用额度,需要客户端自行计算:

剩余可用 = 充值总额 - total_usage

💡 查看充值总额

登录 FoxAPI 控制台 → 个人中心 → 余额

Python 完整示例

python
from openai import OpenAI
from datetime import datetime, timedelta

client = OpenAI(
    api_key="sk-你的Key",
    base_url="https://foxapi.chat/v1"
)

# 查询本月用量
now = datetime.now()
start = now.replace(day=1)
usage = client.billing.usage(
    start_date=start.strftime("%Y-%m-%d"),
    end_date=now.strftime("%Y-%m-%d")
)

print(f"本月已用: ${usage.total_usage:.4f}")
# 剩余可用 = 你的充值总额 - usage.total_usage

常见问题

返回 401 / Invalid token

Key 不正确或已失效,到控制台检查 Key 状态。

total_usage 返回 0

  • 检查日期范围是否正确
  • 确认 Key 在该时间段内有使用记录
  • 日期格式必须是 YYYY-MM-DD

和 OpenAI 官方接口的区别

  • soft_limit_usd / hard_limit_usd 返回的是系统默认值,不是你的实际额度
  • total_usage 是所有模型的总消耗,不按模型分类
  • 如需详细用量明细,请登录 FoxAPI 控制台 查看

© 2026 FoxAPI. All rights reserved.