📄 SKILL.md

← 返回目录


name: qianwen-usage description: "[QianWen] Manage account auth and query usage/billing. Use for: login, logout, check usage, view billing, free tier quota, Token Plan status, pay-as-you-go costs. Skip for: model browsing, non-account tasks."

QianWen Usage

Query QianWen usage, free tier quota, Token Plan status, and pay-as-you-go billing.

Prerequisites

- QianWen CLI must be installed. Verify with:

qianwen version

If not installed, run:

npm install -g @qianwenai/qianwen-cli

Node.js >= 18 required.

- Authentication: No configuration needed on first use. The CLI handles non-TTY detection and safe login automatically (see Authentication Flow below).

Environment Variables

| Variable | Description | |---------------------------|----------------------------------------------------------------------------------------------| | QIANWEN_KEYRING | Set to plaintext, no, 0, false, or off to opt out of OS keychain credential storage. | | QIANWEN_CREDENTIALS_DIR | Override file-based credential directory (default: ~/.qianwen/credentials). |

Authentication Flow (for Agents)

The CLI auto-detects non-TTY environments and degrades safely — no wrapper script needed.

TL;DR — 3-step auth path

1. qianwen auth status --format jsonauthenticated: true → skip to commands 2. qianwen auth login --init-only --format json → extract verification_url → open in browser 3. qianwen auth login --complete --format json → poll until success event

Quick check: already logged in?

qianwen auth status --format json

If authenticated: true and token is not expired, skip login entirely.

Recommended: Two-phase login

Works in all environments (desktop, headless, remote container).

Step 1 — Initialize login (non-blocking):

qianwen auth login --init-only --format json
Exits immediately. Parse the stdout JSON events array:
open "$VERIFICATION_URL"          # macOS
xdg-open "$VERIFICATION_URL"      # Linux
start "" "$VERIFICATION_URL"      # Windows

Step 2 — IMMEDIATELY start polling (do NOT wait for user confirmation):

qianwen auth login --complete --format json
Parse the stdout JSON events array:
qianwen auth login
The CLI will automatically open the browser and poll until authorization completes.

JSON event structure

Both --init-only and --complete output a single JSON document:

{
  "events": [
    {"event": "device_code", "verification_url": "...", "expires_in": 300},
    {"event": "success", "authenticated": true, "user": {"aliyunId": "..."}}
  ]
}

Event types: already_authenticated, device_code, success, expired, error, pending.

NEVER:

- ❌ Ask the user "Have you completed authorization?" before running --complete

qianwen auth logout — Revoke session server-side and clear local credentials

qianwen auth logout

Usage Commands

qianwen usage summary — View usage summary (free tier, Token Plan, pay-as-you-go)

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 output

Period presets: today, yesterday, week, month (default), last-month, quarter, year, YYYY-MM

qianwen usage breakdown — View model usage breakdown

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 json

qianwen usage free-tier — View free tier quota details

qianwen usage free-tier
qianwen usage free-tier --format json

qianwen usage payg — View pay-as-you-go billing details

qianwen usage payg
qianwen usage payg --format json

Breakdown Parameters: How to Think About Them

Three independent dimensions — combine them freely:

--model (required) + date range + granularity

Model scope:

|---|---|---| | --period YYYY-MM | User names a specific month ("March", "last April") | Exact calendar month, start to end | | --period | User describes a relative period | last-month = previous full month; month = this month so far; quarter = this calendar quarter so far | | --days N | User says "last N days" | Rolling window backwards from today, crosses month boundaries naturally | | --from YYYY-MM-DD --to YYYY-MM-DD | 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:

- day (default) — one row per day; good for spotting usage spikes

Single model, single month, daily detail

qianwen usage breakdown --model qwen3.5-plus --period 2026-03

Single model, last 3 months, monthly summary

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

Single model, this month, daily breakdown

qianwen usage breakdown --model qwen3.6-plus --period month

Output and Agent Display Rules

CLI commands return JSON by default in agent/pipe environments (auto format: TTY → table, pipe → json). JSON is the primary output mode for agents — always pass --format json explicitly, parse the structured response, then present a human-readable summary to the user.

JSON output example (--format json)

qianwen usage summary --period month --format json

Returns structured JSON with three sections:

{
  "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)

qianwen usage summary --period month --format text

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 --format json (recommended for agents):

1. Parse the JSON and extract the relevant data for the user's question 2. Present a human-readable summary — do not dump raw JSON to the user 3. Add analysis AFTER the summary — clearly separated with ---

When using --format text:

1. Display CLI output EXACTLY AS-IS — no modification, no reformatting 2. Preserve all formatting — alignment, spacing, progress bars, separators 3. Add analysis AFTER output only — clearly separated with ---

NEVER:

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)

Exit Codes

| Code | Meaning | |------|----------------------| | 0 | Success | | 1 | General/usage error | | 2 | Authentication error | | 3 | Network error | | 4 | Configuration error | | 130 | Interrupted |

CLI Update Check

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"):

1. Run: qianwen version --check 2. Report the result.

The QianWen CLI handles update notifications natively; no additional stderr signal handling is required in this skill.

Implementation Notes

- Pay-as-you-go: API returns total usage only (no input/output split)