360 Secure SkillHub
360 安全技能中心

OpenRouter Usage

通过 OpenRouter 的 /auth/key 与 /activity 接口,获取今日/本周/本月的实时用量总额、余额以及近 7 天按模型的花费明细,并以文本形式输出报告。主路径执行 python3 scripts/stats.py,无 Python 时可用 curl 直接请求接口。

rosseyre
rosseyre
热度 90.01
最近更新 2026-05-11 16:27:50
分类:数据依赖:代码执行 / 第三方 API / 读写文件应用场景:报告撰写 / 财务 / 数据处理 / API 集成

安装技能

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

执行命令安装此 skill: npx secure-skills-cli add openrouter-usage
Metadata
name
openrouter-usage
description
Fetch real-time OpenRouter usage totals and historical per-model spend. Use when the user asks for usage, spend, cost breakdown, or OpenRouter stats. Not for system health or non-LLM metrics.
license
Apache-2.0
compatibility
Requires internet access. Primary path uses python3. Optional fallback uses curl (+ jq if available).
required-env-vars
["OPENROUTER_API_KEY"]
optional-env-vars
["OPENROUTER_MGMT_KEY"]
primary-credential
OPENROUTER_API_KEY
credential-description
OpenRouter API key
metadata
{"author":"Arkology Studio","version":"1.1"}
allowed-tools
Bash(python3:*) Bash(curl:*) Bash(jq:*) Read

OpenRouter Usage Monitor

What this skill does

Retrieves OpenRouter usage and cost data via:

  • Live totals (Today / Week / Month) from /auth/key
  • Historical per-model breakdown from /activity (completed UTC days only)

How to run (recommended)

Set environment variables (recommended) or create a credentials.env file:

export OPENROUTER_API_KEY=your_key_here
export OPENROUTER_MGMT_KEY=your_mgmt_key_here  # optional, enables model breakdown

Then execute: python3 scripts/stats.py

Alternatively, create credentials.env in the skill directory:

OPENROUTER_API_KEY=your_key_here
OPENROUTER_MGMT_KEY=your_mgmt_key_here

Fallback method (no Python)

If Python is unavailable, query endpoints directly:

Live totals curl -sS -H "Authorization: Bearer $OPENROUTER_API_KEY" https://openrouter.ai/api/v1/auth/key

Per-model activity (7d) curl -sS -H "Authorization: Bearer $OPENROUTER_MGMT_KEY" https://openrouter.ai/api/v1/activity

Configuration

Required:

  • OPENROUTER_API_KEY - Required for real-time usage totals and balance

Optional:

  • OPENROUTER_MGMT_KEY - Enables per-model spend breakdown from activity endpoint

Credentials can be provided via:

  1. Environment variables (recommended for security)
  2. credentials.env file in skill directory (fallback)

Output format

💰 OpenRouter Usage Today: $X.XX* | Week: $X.XX | Month: $X.XX Balance: $X.XX / $X.XX

Recent Models (7d): • model-name: $X.XX (N) ... * indicates live totals that may not yet appear in model breakdowns.

Edge cases

  • /activity only returns completed UTC days.
  • Today’s spend may appear in totals but not per-model data until next UTC rollover.
  • Invalid keys → 401/403.
  • Rate limiting → 429.
  • Network failures should be retried or surfaced.