| name | ylsusage |
| description | Use when the user asks about YLS Codex API usage, quota, token consumption, package status, or account balance. Triggers on keywords like ylsusage, codex info, quota check, token usage, package remaining. |
YLS Codex Usage
Query YLS Codex account usage, quota, and package status via API.
Behavior Rule
When triggered, output ONLY the final formatted result. No intermediate text.
- ❌ Do NOT say "let me fetch..." / "querying..." / "here's your usage" / any greeting or explanation
- ❌ Do NOT show raw JSON, API calls, or tool execution process
- ❌ Do NOT add any text before or after the formatted result
- ✅ Fetch data silently, then output the Display Format template directly as your only response
API Endpoint
GET https://codex.ylsagi.com/codex/info
Authorization: Bearer <API_KEY>
Authentication
Read API key from ~/.codex/auth.json:
{
"auth_mode": "apikey",
"OPENAI_API_KEY": "<key>"
}
Use the OPENAI_API_KEY value as Bearer token.
Platform-Specific Usage
macOS
KEY=$(plutil -extract OPENAI_API_KEY raw ~/.codex/auth.json 2>/dev/null || jq -r '.OPENAI_API_KEY' ~/.codex/auth.json)
curl -s -H "Authorization: Bearer $KEY" https://codex.ylsagi.com/codex/info -o /tmp/yls_info.json
jq . /tmp/yls_info.json
Linux
KEY=$(jq -r '.OPENAI_API_KEY' ~/.codex/auth.json)
curl -s -H "Authorization: Bearer $KEY" https://codex.ylsagi.com/codex/info -o /tmp/yls_info.json
jq . /tmp/yls_info.json
Windows (PowerShell)
$auth = Get-Content "$env:USERPROFILE\.codex\auth.json" | ConvertFrom-Json
$headers = @{ Authorization = "Bearer $($auth.OPENAI_API_KEY)" }
Invoke-RestMethod -Uri "https://codex.ylsagi.com/codex/info" -Headers $headers | ConvertTo-Json
IMPORTANT: On all platforms, always save response to file first. The API returns valid JSON but some terminals display it as TypeScript-style type hints on stdout.
Response Structure
| Field | Description |
|---|
state.user | User info: uid, email |
state.toDay | Current date (server) |
state.package.total_quota | Monthly total quota |
state.package.weeklyQuota | Weekly total quota |
state.package.package_level | Package level (2 = Pro) |
state.package.packages[] | Active package details: type, quota, expiry |
state.userPackgeUsage | Monthly usage stats |
state.userPackgeUsage_week | Weekly usage stats |
state.userAccountInfo | Account balance info |
Key Usage Fields
Monthly (userPackgeUsage) / Weekly (userPackgeUsage_week):
| Field | Meaning |
|---|
input_tokens | Total input tokens |
input_tokens_cached | Cached input tokens |
output_tokens | Output tokens |
output_tokens_reasoning | Reasoning tokens |
total_cost | Total cost ($) |
input_cost / output_cost / cache_read_cost | Cost breakdown |
request_count | Number of requests |
total_quota | Quota cap |
remaining_quota | Remaining quota |
used_percentage | Usage percentage string |
Quick Check
macOS / Linux
KEY=$(jq -r '.OPENAI_API_KEY' ~/.codex/auth.json)
curl -s -H "Authorization: Bearer $KEY" https://codex.ylsagi.com/codex/info -o /tmp/yls_info.json
jq '{package: .state.package.packages[0].package_type, level: "Lv" + (.state.package.package_level|tostring), expires: .state.package.packages[0].expires_at[:10], monthly: {remaining: .state.userPackgeUsage.remaining_quota, total: .state.userPackgeUsage.total_quota, used: .state.userPackgeUsage.used_percentage + "%", requests: .state.userPackgeUsage.request_count, cost: .state.userPackgeUsage.total_cost}, weekly: {remaining: .state.userPackgeUsage_week.remaining_quota, total: .state.userPackgeUsage_week.total_quota, used: .state.userPackgeUsage_week.used_percentage + "%", requests: .state.userPackgeUsage_week.request_count, cost: .state.userPackgeUsage_week.total_cost}}' /tmp/yls_info.json
Windows (PowerShell)
$auth = Get-Content "$env:USERPROFILE\.codex\auth.json" | ConvertFrom-Json
$r = Invoke-RestMethod -Uri "https://codex.ylsagi.com/codex/info" -Headers @{ Authorization = "Bearer $($auth.OPENAI_API_KEY)" }
$m = $r.state.userPackgeUsage; $w = $r.state.userPackgeUsage_week; $p = $r.state.package
Write-Host "Package: $($p.packages[0].package_type) (Lv$($p.package_level)) Expires: $($p.packages[0].expires_at.Substring(0,10))"
Write-Host "Monthly: `$$($m.remaining_quota) / `$$($m.total_quota) ($($m.used_percentage)%) Requests: $($m.request_count) Cost: `$$($m.total_cost)"
Write-Host "Weekly: `$$($w.remaining_quota) / `$$($w.total_quota) ($($w.used_percentage)%) Requests: $($w.request_count) Cost: `$$($w.total_cost)"
Display Format
Format the response concisely with emojis. Match the user's conversation language — if they've been speaking Chinese, reply in Chinese; English, reply in English.
Template
✨ {package_type} Lv{package_level} · 🎀 到期 {expires_at}
───────────────
📋 今日用量
📊 进度 [████████░░░░░░░░░░] {used_percentage}%
💰 余额 ${remaining} / ${total}
📨 请求 {requests} 次
💸 花费 $${cost}
📥 输入 {input_tokens:,} tokens
📤 输出 {output_tokens:,} tokens
🧠 推理 {reasoning_tokens:,} tokens
───────────────
📋 周度用量
📊 进度 [████████░░░░░░░░░░] {used_percentage}%
💰 余额 ${remaining} / ${total}
📨 请求 {requests} 次
💸 花费 $${cost}
📥 输入 {input_tokens:,} tokens
📤 输出 {output_tokens:,} tokens
🧠 推理 {reasoning_tokens:,} tokens
───────────────
💧 缓存命中 {cache_rate}%
🍵 今日推理 {reasoning_tokens:,} tokens
Rules
- Progress bar: 20 chars,
█ filled + ░ empty
- Token numbers: comma-separated
- Costs: 2 decimal places
- Usage warning: >80% append 🔴, 50-80% append ⚠️
- Cache hit rate =
input_tokens_cached / input_tokens
- Use
userPackgeUsage as today's data, userPackgeUsage_week as weekly data
- Omit
userAccountInfo section entirely unless user asks for balance
- Keep each metric on its own line with emoji prefix, aligned consistently
Common Mistakes
- Don't pipe curl directly to jq — save with
-o first, then parse the file.
- Don't hardcode the API key — always read from
~/.codex/auth.json.
- Field name typo: The API uses
userPackgeUsage (missing 'a' in Package) — this is intentional, not a typo.