API 参考入门读者更新于
GET/v1/user/balance
余额查询 API
通过 API Key 查询账户余额和套餐用量,适合接入你自己的脚本或监控系统。
端点与认证
text
GET https://api.icodeeasy.cc/v1/user/balance
不带 /v1 前缀的 https://api.icodeeasy.cc/user/balance 同样可用。
使用你自己的 API Key 认证,以下三种请求头任选其一:
text
Authorization: Bearer <你的API Key>
X-Api-Key: <你的API Key>
x-goog-api-key: <你的API Key>
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
is_active | boolean | 账号是否启用 |
balance | number | 可用余额 |
unit | string | 余额和额度使用的币种,固定为 CNY(人民币元) |
plan_type | string | 按量计费为 paygo。月卡值以 monthly_ 开头,例如 monthly_2、monthly_limit_5、monthly_gpt_5 |
daily_limit | number | 月卡每日额度 |
daily_used | number | 今日已用月卡额度 |
daily_remaining | number | 有效月卡今日剩余额度。无有效月卡时为 0 |
plan_expires_at | string/null | 套餐到期时间(ISO 8601),无月卡为 null |
请求示例
curl:
bash
curl https://api.icodeeasy.cc/v1/user/balance \
-H "Authorization: Bearer <你的API Key>"
响应示例:
json
{
"is_active": true,
"balance": 80.28,
"unit": "CNY",
"plan_type": "paygo",
"daily_limit": 0,
"daily_used": 0,
"daily_remaining": 0,
"plan_expires_at": null
}
Python:
python
import requests
resp = requests.get(
"https://api.icodeeasy.cc/v1/user/balance",
headers={"Authorization": "Bearer <你的API Key>"},
timeout=10,
)
resp.raise_for_status()
data = resp.json()
print(f"余额: ¥{data['balance']:.2f} ({data['unit']})")
说明
查询不消耗额度,余额为 0 时也可以查询。月卡覆盖范围外的调用可直接从账户余额扣费。
HTTP 401 表示 API Key 缺失或无效。遇到连接问题,可查阅连接排查。