qianwen-usage
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQianWen Usage
QianWen 使用指南
Query QianWen usage, free tier quota, Token Plan status, and pay-as-you-go billing.
查询QianWen的使用情况、免费额度、Token Plan状态以及按需付费账单。
Prerequisites
前提条件
- QianWen CLI must be installed. Verify with:
bash
qianwen versionIf not installed, run:
bash
npm install -g @qianwenai/qianwen-cliNode.js >= 18 required.
- Authentication: No configuration needed on first use. The CLI handles non-TTY detection and safe login automatically (see Authentication Flow below).
- 必须安装 QianWen CLI。可通过以下命令验证:
bash
qianwen version若未安装,请运行:
bash
npm install -g @qianwenai/qianwen-cli需要Node.js版本 >= 18。
- 认证:首次使用无需配置。CLI会自动处理非TTY环境检测并安全完成登录(详见下方认证流程)。
Environment Variables
环境变量
| Variable | Description |
|---|---|
| Set to |
| Override file-based credential directory (default: |
| 变量名称 | 描述 |
|---|---|
| 设置为 |
| 覆盖基于文件的凭证存储目录(默认路径: |
Authentication Flow (for Agents)
认证流程(适用于Agent)
The CLI auto-detects non-TTY environments and degrades safely — no wrapper script needed.
CLI会自动检测非TTY环境并安全降级处理——无需包装脚本。
TL;DR — 3-step auth path
快速概述——三步认证流程
- →
qianwen auth status --format json→ skip to commandsauthenticated: true - → extract
qianwen auth login --init-only --format json→ open in browserverification_url - → poll until
qianwen auth login --complete --format jsoneventsuccess
- → 返回
qianwen auth status --format json→ 直接执行后续命令authenticated: true - → 提取
qianwen auth login --init-only --format json→ 在浏览器中打开verification_url - → 轮询直到出现
qianwen auth login --complete --format json事件success
Quick check: already logged in?
快速检查:是否已登录?
bash
qianwen auth status --format jsonIf and token is not expired, skip login entirely.
authenticated: truebash
qianwen auth status --format json若返回且令牌未过期,可直接跳过登录步骤。
authenticated: trueRecommended: Two-phase login
推荐:两阶段登录
Works in all environments (desktop, headless, remote container).
Step 1 — Initialize login (non-blocking):
bash
qianwen auth login --init-only --format jsonExits immediately. Parse the stdout JSON array:
events- → user is logged in, skip to commands
already_authenticated - → extract
device_codeand present it to the userverification_url
On desktop environments with a browser, open the URL for the user:
bash
open "$VERIFICATION_URL" # macOS
xdg-open "$VERIFICATION_URL" # Linux
start "" "$VERIFICATION_URL" # WindowsStep 2 — IMMEDIATELY start polling (do NOT wait for user confirmation):
bash
qianwen auth login --complete --format jsonParse the stdout JSON array:
events- → login complete, proceed to commands
success - → device code expired, go back to Step 1
expired - → report failure
error
适用于所有环境(桌面、无头环境、远程容器)。
步骤1 — 初始化登录(非阻塞):
bash
qianwen auth login --init-only --format json命令立即退出。解析标准输出的JSON 数组:
events- → 用户已登录,直接执行后续命令
already_authenticated - → 提取
device_code并展示给用户verification_url
在带有浏览器的桌面环境中,可为用户自动打开该链接:
bash
open "$VERIFICATION_URL" # macOS
xdg-open "$VERIFICATION_URL" # Linux
start "" "$VERIFICATION_URL" # Windows步骤2 — 立即启动轮询(请勿等待用户确认):
bash
qianwen auth login --complete --format json解析标准输出的JSON 数组:
events- → 登录完成,执行后续命令
success - → 设备码已过期,返回步骤1重新操作
expired - → 报告登录失败
error
TTY environments (interactive terminal)
TTY环境(交互式终端)
If the agent is running in a TTY (e.g., user's terminal), simply run:
bash
qianwen auth loginThe CLI will automatically open the browser and poll until authorization completes.
若Agent运行在TTY环境(如用户终端),只需运行:
bash
qianwen auth loginCLI会自动打开浏览器并轮询直到授权完成。
JSON event structure
JSON事件结构
Both and output a single JSON document:
--init-only--completejson
{
"events": [
{"event": "device_code", "verification_url": "...", "expires_in": 300},
{"event": "success", "authenticated": true, "user": {"aliyunId": "..."}}
]
}Event types: , , , , , .
already_authenticateddevice_codesuccessexpirederrorpending--init-only--completejson
{
"events": [
{"event": "device_code", "verification_url": "...", "expires_in": 300},
{"event": "success", "authenticated": true, "user": {"aliyunId": "..."}}
]
}事件类型:、、、、、。
already_authenticateddevice_codesuccessexpirederrorpendingNEVER:
禁止操作:
- ❌ Ask the user "Have you completed authorization?" before running
--complete - ❌ Wait for user confirmation before polling — run immediately after presenting the URL
--complete - ❌ Re-run without completing (this creates a new device code and invalidates the previous one)
--init-only
- ❌ 在运行前询问用户“是否已完成授权?”
--complete - ❌ 在展示链接后等待用户确认再启动轮询——展示链接后立即运行
--complete - ❌ 未完成当前流程就重新运行——这会生成新的设备码并使旧码失效
--init-only
Usage
使用方法
All commands support for structured, machine-parseable output (recommended default), and for clean plaintext output.
--format json--format textFor agent use, always prefer and parse the JSON response. Only fall back to when the user explicitly requests human-readable plaintext.
--format json--format textNever parse format programmatically — it contains ANSI codes and Unicode borders.
table所有命令均支持以获取结构化、可机器解析的输出(推荐默认使用),以及以获取简洁的纯文本输出。
--format json--format text对于Agent使用,**始终优先使用**并解析JSON响应。仅当用户明确要求人类可读的纯文本时,才使用。
--format json--format text请勿以编程方式解析格式输出——它包含ANSI代码和Unicode边框。
tableAuth Commands
认证命令
qianwen auth statusbash
qianwen auth status --format jsonqianwen auth logoutbash
qianwen auth logoutqianwen auth statusbash
qianwen auth status --format jsonqianwen auth logoutbash
qianwen auth logoutUsage Commands
使用情况查询命令
qianwen usage summarybash
qianwen usage summary # Current month
qianwen usage summary --period last-month # Last month
qianwen usage summary --from 2026-03-01 --to 2026-03-31
qianwen usage summary --format json # JSON outputPeriod presets: , , , (default), , , ,
todayyesterdayweekmonthlast-monthquarteryearYYYY-MMqianwen usage breakdownbash
qianwen usage breakdown --model qwen3.6-plus --days 7
qianwen usage breakdown --model qwen3.5-plus --period 2026-03
qianwen usage breakdown --model qwen-plus --period 2026-03 --granularity month
qianwen usage breakdown --model qwen3.6-plus --format jsonqianwen usage free-tierbash
qianwen usage free-tier
qianwen usage free-tier --format jsonqianwen usage paygbash
qianwen usage payg
qianwen usage payg --format jsonqianwen usage summarybash
qianwen usage summary # 当前月份
qianwen usage summary --period last-month # 上月
qianwen usage summary --from 2026-03-01 --to 2026-03-31
qianwen usage summary --format json # JSON格式输出时间周期预设值:、、、(默认)、、、、
todayyesterdayweekmonthlast-monthquarteryearYYYY-MMqianwen usage breakdownbash
qianwen usage breakdown --model qwen3.6-plus --days 7
qianwen usage breakdown --model qwen3.5-plus --period 2026-03
qianwen usage breakdown --model qwen-plus --period 2026-03 --granularity month
qianwen usage breakdown --model qwen3.6-plus --format jsonqianwen usage free-tierbash
qianwen usage free-tier
qianwen usage free-tier --format jsonqianwen usage paygbash
qianwen usage payg
qianwen usage payg --format jsonBreakdown Parameters: How to Think About Them
细分参数说明:如何选择参数
Three independent dimensions — combine them freely:
--modelModel scope:
- — single model (e.g.
--model <id>); required for breakdownqwen3.5-plus
Date range — three patterns, pick by how the user described the period:
| Pattern | When to use | How it works |
|---|---|---|
| User names a specific month ("March", "last April") | Exact calendar month, start to end |
| User describes a relative period | |
| User says "last N days" | Rolling window backwards from today, crosses month boundaries naturally |
| User gives explicit dates or a named quarter/range | Full control, use when other patterns don't fit |
Granularity — determines the grouping of results, not the range:
- (default) — one row per day; good for spotting usage spikes
day - — one row per calendar month; good for multi-month trends
month - — one row per quarter; good for Q-over-Q comparison
quarter
Classic examples:
bash
undefined三个独立维度——可自由组合:
--model模型范围:
- — 指定单个模型(如
--model <id>);细分查询时必填qwen3.5-plus
日期范围——三种模式,根据用户描述的周期选择:
| 模式 | 使用场景 | 说明 |
|---|---|---|
| 用户指定具体月份(如“三月”、“去年四月”) | 精确的日历月,从月初到月末 |
| 用户描述相对周期 | |
| 用户提及“过去N天” | 从今日起向后滚动的时间窗口,自然跨月 |
| 用户提供明确日期或指定季度/范围 | 完全自定义,当其他模式不适用时使用 |
粒度——决定结果的分组方式,而非时间范围:
- (默认) — 按天分组;适合识别使用量峰值
day - — 按日历月分组;适合查看多月趋势
month - — 按季度分组;适合季度对比
quarter
典型示例:
bash
undefinedSingle model, single month, daily detail
单个模型、单个月份、每日详情
qianwen usage breakdown --model qwen3.5-plus --period 2026-03
qianwen usage breakdown --model qwen3.5-plus --period 2026-03
Single model, last 3 months, monthly summary
单个模型、过去3个月、月度汇总
qianwen usage breakdown --model qwen3.5-plus --days 90 --granularity month
qianwen usage breakdown --model qwen3.5-plus --days 90 --granularity month
Single model, specific quarter, quarterly rollup
单个模型、指定季度、季度汇总
qianwen usage breakdown --model qwen3.5-plus --from 2026-01-01 --to 2026-03-31 --granularity quarter
qianwen usage breakdown --model qwen3.5-plus --from 2026-01-01 --to 2026-03-31 --granularity quarter
Single model, this month, daily breakdown
单个模型、当前月份、每日细分
qianwen usage breakdown --model qwen3.6-plus --period month
undefinedqianwen usage breakdown --model qwen3.6-plus --period month
undefinedOutput and Agent Display Rules
输出与Agent展示规则
CLI commands return JSON by default in agent/pipe environments ( format: TTY → table, pipe → json).
JSON is the primary output mode for agents — always pass explicitly, parse the structured response, then present a human-readable summary to the user.
auto--format json在Agent/管道环境中,CLI命令默认返回JSON(格式:TTY环境→表格,管道环境→json)。
JSON是Agent的主要输出模式——始终显式传递,解析结构化响应后,再向用户展示人类可读的汇总内容。
auto--format jsonJSON output example (--format json
)
--format jsonJSON输出示例(--format json
)
--format jsonbash
qianwen usage summary --period month --format jsonReturns structured JSON with three sections:
json
{
"period": { "from": "2026-04-01", "to": "2026-04-24" },
"free_tier": [
{ "model_id": "qwen3.6-plus", "quota": { "remaining": 850000, "total": 1000000, "unit": "tokens", "used_pct": 15 } }
],
"coding_plan": {
"subscribed": true,
"plan": "PRO",
"windows": {
"per_5h": { "remaining": 4800, "total": 6000, "used_pct": 20 },
"weekly": { "remaining": 38200, "total": 45000, "used_pct": 15 },
"monthly": { "remaining": 82500, "total": 90000, "used_pct": 8 }
}
},
"pay_as_you_go": {
"models": [
{ "model_id": "qwen3.6-plus", "usage": { "tokens_total": 480000 }, "cost": 0.38, "currency": "USD" },
{ "model_id": "qwen-plus", "usage": { "tokens_total": 460000 }, "cost": 0.13, "currency": "USD" }
],
"total": { "cost": 0.51, "currency": "USD" }
}
}bash
qianwen usage summary --period month --format json返回包含三个部分的结构化JSON:
json
{
"period": { "from": "2026-04-01", "to": "2026-04-24" },
"free_tier": [
{ "model_id": "qwen3.6-plus", "quota": { "remaining": 850000, "total": 1000000, "unit": "tokens", "used_pct": 15 } }
],
"coding_plan": {
"subscribed": true,
"plan": "PRO",
"windows": {
"per_5h": { "remaining": 4800, "total": 6000, "used_pct": 20 },
"weekly": { "remaining": 38200, "total": 45000, "used_pct": 15 },
"monthly": { "remaining": 82500, "total": 90000, "used_pct": 8 }
}
},
"pay_as_you_go": {
"models": [
{ "model_id": "qwen3.6-plus", "usage": { "tokens_total": 480000 }, "cost": 0.38, "currency": "USD" },
{ "model_id": "qwen-plus", "usage": { "tokens_total": 460000 }, "cost": 0.13, "currency": "USD" }
],
"total": { "cost": 0.51, "currency": "USD" }
}
}Text output example (--format text
)
--format text文本输出示例(--format text
)
--format textbash
qianwen usage summary --period month --format textplaintext
Usage Summary · 2026-04-10
-- Free Tier Quota -------------------------------------------------------
Model Remaining Total Progress
qwen3.6-plus 850K tokens 1M tokens 85% left
wan2.6-t2i 38 images 50 images 76% left
--------------------------------------------------------------------------
-- Token Plan · Token Plan Team Edition - Standard Seat · 生效中-------
Usage: 25K / 25K Credits
Quota Left: 100%
Status: 生效中
Resets: 2026-06-01
--------------------------------------------------------------------------
-- Pay-as-you-go · 2026-04-01 → 2026-04-10 -------------------------------
Model Usage Cost
qwen3.6-plus 480K tok $0.38
qwen-plus 460K tok $0.13
--------------------------------------------------------------------------
Total — $0.51bash
qianwen usage summary --period month --format textplaintext
Usage Summary · 2026-04-10
-- Free Tier Quota -------------------------------------------------------
Model Remaining Total Progress
qwen3.6-plus 850K tokens 1M tokens 85% left
wan2.6-t2i 38 images 50 images 76% left
--------------------------------------------------------------------------
-- Token Plan · Token Plan Team Edition - Standard Seat · 生效中-------
Usage: 25K / 25K Credits
Quota Left: 100%
Status: 生效中
Resets: 2026-06-01
--------------------------------------------------------------------------
-- Pay-as-you-go · 2026-04-01 → 2026-04-10 -------------------------------
Model Usage Cost
qwen3.6-plus 480K tok $0.38
qwen-plus 460K tok $0.13
--------------------------------------------------------------------------
Total — $0.51⚠️ CRITICAL: How to present output to the user
⚠️ 重要提示:如何向用户展示输出
When using (recommended for agents):
--format json- Parse the JSON and extract the relevant data for the user's question
- Present a human-readable summary — do not dump raw JSON to the user
- Add analysis AFTER the summary — clearly separated with
---
When using :
--format text- Display CLI output EXACTLY AS-IS — no modification, no reformatting
- Preserve all formatting — alignment, spacing, progress bars, separators
- Add analysis AFTER output only — clearly separated with
---
NEVER:
- ❌ Dump raw JSON to the user without interpretation
- ❌ Reformat or summarize text/table output
- ❌ Add prefixes like "Here's your usage:"
- ❌ Convert text/table output to bullet points
✅ CORRECT (JSON mode):
Your QianWen usage for April:
**Free Tier**: qwen3.6-plus has 85% remaining (850K / 1M tokens), wan2.6-t2i has 76% remaining (38 / 50 images).
**Token Plan (PRO)**: 8% used this month (82.5K / 90K requests).
**Pay-as-you-go**: $0.51 total — qwen3.6-plus $0.38, qwen-plus $0.13.
---
**💡 Analysis**: Your qwen3.6-plus free tier is 85% remaining...✅ CORRECT (Text mode):
[CLI text output - exactly as-is]
---
**💡 Analysis**: Your qwen3.6-plus free tier is 85% remaining...❌ WRONG:
Here's your usage:
- qwen3.6-plus: 850K tokens remaining (85% left)当使用(Agent推荐模式):
--format json- 解析JSON并提取与用户问题相关的数据
- 展示人类可读的汇总内容——不要直接向用户输出原始JSON
- 在汇总后添加分析内容——用清晰分隔
---
当使用:
--format text- 完全原样展示CLI输出——不修改、不重新格式化
- 保留所有格式——对齐方式、间距、进度条、分隔线
- 仅在输出后添加分析内容——用清晰分隔
---
禁止操作:
- ❌ 不做解释直接向用户输出原始JSON
- ❌ 重新格式化或汇总文本/表格输出
- ❌ 添加类似“这是你的使用情况:”的前缀
- ❌ 将文本/表格输出转换为项目符号列表
✅ 正确示例(JSON模式):
你4月份的QianWen使用情况:
**免费额度**:qwen3.6-plus剩余85%(85万 / 100万tokens),wan2.6-t2i剩余76%(38 / 50张图片)。
**Token Plan(PRO版)**:本月已使用8%(8.25万 / 9万次请求)。
**按需付费**:总计0.51美元——qwen3.6-plus花费0.38美元,qwen-plus花费0.13美元。
---
**💡 分析**:你的qwen3.6-plus免费额度剩余85%...✅ 正确示例(文本模式):
[CLI文本输出——完全原样]
---
**💡 分析**:你的qwen3.6-plus免费额度剩余85%...❌ 错误示例:
这是你的使用情况:
- qwen3.6-plus:剩余85万tokens(85%)Exit Codes
退出码
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General/usage error |
| 2 | Authentication error |
| 3 | Network error |
| 4 | Configuration error |
| 130 | Interrupted |
| 代码 | 含义 |
|---|---|
| 0 | 成功 |
| 1 | 通用/使用错误 |
| 2 | 认证错误 |
| 3 | 网络错误 |
| 4 | 配置错误 |
| 130 | 操作被中断 |
CLI Update Check
CLI版本检查
When the user explicitly asks to check for cli updates (e.g. "check for cli updates", "check cli version", "is there a new version cli"):
- Run:
qianwen version --check - Report the result.
The QianWen CLI handles update notifications natively; no additional stderr signal handling is required in this skill.
当用户明确要求检查CLI更新时(例如“检查CLI更新”、“查看CLI版本”、“CLI有新版本吗”):
- 运行:
qianwen version --check - 向用户报告结果。
QianWen CLI原生支持更新通知;本技能无需额外处理stderr信号。
Implementation Notes
实现说明
- Pay-as-you-go: API returns total usage only (no input/output split)
- Token Plan: Aggregate request counts at plan level (no per-model breakdown)
- logout: Revokes server-side session and clears local credentials (keychain + file). Server-side call is best-effort — local logout always succeeds.
- Authentication: Uses OAuth 2.0 Device Authorization Grant with PKCE. Credentials stored in OS keychain when available, with encrypted file fallback.
- breakdown --model is required: Unlike the previous Python implementation, the CLI requires for breakdown. To query all models' usage, use
--modelinstead.qianwen usage summary
- 按需付费:API仅返回总使用量(不区分输入/输出)
- Token Plan:按计划级别汇总请求次数(无模型级细分)
- logout:吊销服务器端会话并清除本地凭证(钥匙串+文件)。服务器端调用为尽力而为——本地登出始终成功。
- 认证:采用OAuth 2.0设备授权码流程+PKCE。凭证优先存储在操作系统钥匙串中, fallback到加密文件存储。
- breakdown必须指定--model:与之前的Python实现不同,CLI的细分查询必须指定。若要查询所有模型的使用情况,请使用
--model。qianwen usage summary