1. 查询账户余额
GET /v1/balance
鉴权方式
Authorization: Bearer <API Key>
⚠️ 仅允许使用该账号的默认 API Key,其他 Key 将返回 403 Forbidden。
请求示例
curl -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
https://api.nonelinear.com/v1/balance
成功响应 (200)
{
"object": "balance",
"balance": 50.0000,
"currency": "RMB",
"note": "元(人民币)"
}
| 字段 | 类型 | 说明 |
|---|---|---|
object | string | 固定值 "balance" |
balance | number | 账户余额(元),保留 4 位小数 |
currency | string | 货币单位,"RMB" |
note | string | 备注说明 |
错误响应
| 状态码 | 说明 |
|---|---|
| 401 | API Key 缺失或无效 |
| 403 | API Key 有效但不是默认 Key |
2. 查询 API Key 费用信息
GET /v1/costofapikey
鉴权方式
Authorization: Bearer <API Key>
⚠️ 仅允许使用该账号的默认 API Key,其他 Key 将返回 403 Forbidden。
请求示例
curl -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
https://api.nonelinear.com/v1/costofapikey
成功响应 (200)
{
"object": "list",
"data": [
{
"apikey": "sk-f23118d4b*************************",
"name": "默认 API Key",
"cost": 0.000235,
"budget": 0,
"created_at": 1774081270,
"expiry_date": null,
"daily_limit": 0,
"monthly_limit": 0,
"cost_today": 0,
"cost_this_month": 0,
"input_price_limit": 0,
"output_price_limit": 0,
"group_id": "6a06f7db38b3bf1609a9c200",
"group_name": "生产环境"
}
]
}
| 字段 | 类型 | 说明 |
|---|---|---|
object | string | 固定值 "list" |
data | array | API Key 费用信息列表 |
data 数组中的字段
| 字段 | 类型 | 说明 |
|---|---|---|
apikey | string | API Key,仅显示前 10 位,其余用 * 掩盖 |
name | string | API Key 名称 |
cost | number | 累计费用(元) |
budget | number | 预算限额(0 表示无限制) |
created_at | number | 创建时间(Unix 时间戳) |
expiry_date | string / null | 有效期截止日期(YYYY-MM-DD),null 表示永不过期 |
daily_limit | number | 每日消费限额(元),0 表示无限制 |
monthly_limit | number | 每月消费限额(元),0 表示无限制 |
cost_today | number | 今日已消费金额。 |
cost_this_month | number | 本月已消费金额。 |
input_price_limit | number | 模型输入价格限额(元/M token),0 表示无限制 |
output_price_limit | number | 模型输出价格限额(元/M token),0 表示无限制 |
group_id | string / null | 该 API Key 所属分组的 ID,null 表示未分组 |
group_name | string / null | 该 API Key 所属分组的名称,null 表示未分组,空字符串表示分组已被删除 |
错误响应
| 状态码 | 说明 |
|---|---|
| 401 | API Key 缺失或无效 |
| 403 | API Key 有效但不是默认 Key |
Python 调用示例
import requests
BASE_URL = 'https://api.nonelinear.com'
def query_balance(apikey: str) -> dict:
resp = requests.get(
f'{BASE_URL}/v1/balance',
headers={'Authorization': f'Bearer {apikey}'}
)
resp.raise_for_status()
return resp.json()
def query_costofapikey(apikey: str) -> list:
resp = requests.get(
f'{BASE_URL}/v1/costofapikey',
headers={'Authorization': f'Bearer {apikey}'}
)
resp.raise_for_status()
return resp.json()['data']
if __name__ == '__main__':
API_KEY = '<你的默认APIKey>'
bal = query_balance(API_KEY)
print(f"余额: {bal['balance']} {bal['currency']}")
records = query_costofapikey(API_KEY)
for r in records:
group = r.get('group_name') or '未分组'
print(f" Key: {r['apikey']} 分组: {group} 费用: {r.get('cost', 0)}")