New API Usage Query
Query quota and usage from a new-api deployment with explicit inputs.
Safety Rules
- - Require explicit
--base-url and --key; never auto-read local config or keychain. - Never print the full API key in output.
- Only perform read-only GET requests to usage endpoints.
- If the endpoint is unknown, ask user to confirm before querying.
Usage
CODEBLOCK0
Options
| Option | Description |
|---|
| INLINECODE2 | Required. new-api base URL, e.g. INLINECODE3 |
| INLINECODE4 |
Required. API key |
|
--today | Only keep today's records (default) |
|
--all-records | Disable today's filter |
|
--limit N | Number of records shown in table (default: 100) |
|
--by-model | Show grouped usage by model |
|
--quota-only | Only show quota/balance |
|
--json | Print raw JSON payload |
|
--timeout | HTTP timeout seconds (default: 15) |
API Endpoints
- - INLINECODE12
- INLINECODE13
Notes
- - Quota conversion in script uses
500000 quota = $1. - INLINECODE15 uses local timezone date boundaries.
新 API 使用查询
通过显式输入查询新 API 部署的配额和使用情况。
安全规则
- - 要求显式提供 --base-url 和 --key;绝不自动读取本地配置或密钥链。
- 绝不在输出中打印完整的 API 密钥。
- 仅对使用情况端点执行只读 GET 请求。
- 如果端点未知,在查询前要求用户确认。
使用方法
bash
摘要(仅今日记录)
uv run python scripts/query_usage.py \
--base-url https://your-new-api.example.com \
--key sk-xxxxx
仅配额
uv run python scripts/query_usage.py \
--base-url https://your-new-api.example.com \
--key sk-xxxxx \
--quota-only
按模型聚合所有记录
uv run python scripts/query_usage.py \
--base-url https://your-new-api.example.com \
--key sk-xxxxx \
--all-records \
--by-model
选项
| 选项 | 描述 |
|---|
| --base-url | 必填。新 API 基础 URL,例如 https://xxx.com |
| --key |
必填。API 密钥 |
| --today | 仅保留今日记录(默认) |
| --all-records | 禁用今日筛选 |
| --limit N | 表中显示的记录数(默认:100) |
| --by-model | 按模型显示分组使用情况 |
| --quota-only | 仅显示配额/余额 |
| --json | 打印原始 JSON 数据 |
| --timeout | HTTP 超时秒数(默认:15) |
API 端点
- - GET /api/usage/token/
- GET /api/log/token?key={api_key}
备注
- - 脚本中的配额换算使用 500000 配额 = $1。
- --today 使用本地时区的日期边界。