360 Secure SkillHub
360 安全技能中心

new-api-usage

通过显式 --base-url 与 --key 调用用户指定的 new-api 部署,只读查询配额余额与 token 用量记录,可选择仅看今日或全部记录,按模型聚合,支持表格与原始 JSON 输出;脚本不自动读取本地配置,也不打印完整密钥。

wang48
wang48
热度 62.19
最近更新 2026-05-11 17:29:11
分类:数据依赖:代码执行 / 第三方 API应用场景:报告撰写 / 数据处理 / API 集成

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add new-api-usage
Metadata
name
new-api-usage
description
Query usage statistics and quota from a user-specified new-api endpoint. Use when the user asks to check API quota, usage records, token consumption, model-level usage, or remaining balance. Requires explicit --base-url and --key input.

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

# Summary (today's records only)
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 \
  --quota-only

# Model aggregation with all records
uv run python scripts/query_usage.py \
  --base-url https://your-new-api.example.com \
  --key sk-xxxxx \
  --all-records \
  --by-model

Options

Option Description
--base-url Required. new-api base URL, e.g. https://xxx.com
--key 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

  • GET /api/usage/token/
  • GET /api/log/token?key={api_key}

Notes

  • Quota conversion in script uses 500000 quota = $1.
  • --today uses local timezone date boundaries.