🔀 OpenRouter Toolkit
The definitive OpenRouter skill for OpenClaw agents. Intelligent model routing, cost tracking, fallback chains, and model comparison — all in one toolkit.
Features
- - Smart Routing — Automatically pick the best model for code, reasoning, creative, fast, or cheap tasks
- Cost Tracking — Log every API call with cost, track daily/weekly/monthly spend
- Fallback Chains — If primary model fails or times out, auto-retry with fallbacks
- Model Comparison — Send the same prompt to N models, compare quality and cost side-by-side
- Budget Alerts — Set spending limits and get warned before you blow your budget
- Live Model Data — Pulls real pricing and capabilities from OpenRouter's API
Requirements
- -
OPENROUTER_API_KEY — Your OpenRouter API key - Python 3.10+ with
requests (included in most environments)
Usage
Smart Routing
CODEBLOCK0
Model Comparison
CODEBLOCK1
Fallback Chain
CODEBLOCK2
Cost Tracking
CODEBLOCK3
Budget Alerts
CODEBLOCK4
List Models
CODEBLOCK5
How Smart Routing Works
The router scores models based on task type using these heuristics:
| Task | Prioritizes | Example Models |
|---|
| code | High context, code benchmarks | Claude Opus, GPT-4o |
| reasoning |
Thinking/reasoning capability | Claude Opus, o1 |
| creative | Creative writing quality | Claude Sonnet, GPT-4o |
| fast | Low latency, good enough quality | Claude Haiku, GPT-4o-mini |
| cheap | Lowest cost per token | Gemini Flash, GPT-4o-mini |
Data Storage
Cost logs are stored in SQLite at {baseDir}/data/openrouter_costs.db.
Credits
Built by
M. Abidi |
agxntsix.ai
YouTube |
GitHub
Part of the
AgxntSix Skill Suite for OpenClaw agents.
📅 Need help setting up OpenClaw for your business? Book a free consultation
🔀 OpenRouter 工具包
面向 OpenClaw 智能体的终极 OpenRouter 技能。智能模型路由、成本追踪、回退链和模型对比——一应俱全。
功能特性
- - 智能路由 — 自动为代码、推理、创意、快速或低成本任务选择最佳模型
- 成本追踪 — 记录每次 API 调用的成本,追踪日/周/月支出
- 回退链 — 若主模型失败或超时,自动使用备用模型重试
- 模型对比 — 向 N 个模型发送相同提示,并排比较质量和成本
- 预算提醒 — 设置支出限额,在超支前收到警告
- 实时模型数据 — 从 OpenRouter API 获取实时定价和功能信息
前提条件
- - OPENROUTERAPIKEY — 你的 OpenRouter API 密钥
- Python 3.10+ 并安装 requests(大多数环境已预装)
使用方法
智能路由
bash
python3 {baseDir}/scripts/openrouter_toolkit.py route --task code
python3 {baseDir}/scripts/openrouter_toolkit.py route --task reasoning
python3 {baseDir}/scripts/openrouter_toolkit.py route --task creative
python3 {baseDir}/scripts/openrouter_toolkit.py route --task fast
python3 {baseDir}/scripts/openrouter_toolkit.py route --task cheap
模型对比
bash
python3 {baseDir}/scripts/openrouter_toolkit.py compare --prompt 解释递归 --models anthropic/claude-sonnet-4,openai/gpt-4o-mini
回退链
bash
python3 {baseDir}/scripts/openrouter_toolkit.py fallback --prompt 你好 --chain anthropic/claude-opus-4,anthropic/claude-sonnet-4,openai/gpt-4o-mini
成本追踪
bash
python3 {baseDir}/scripts/openrouter_toolkit.py cost --period daily
python3 {baseDir}/scripts/openrouter_toolkit.py cost --period weekly
python3 {baseDir}/scripts/openrouter_toolkit.py cost --period monthly
预算提醒
bash
python3 {baseDir}/scripts/openrouter_toolkit.py budget --set 50.00
python3 {baseDir}/scripts/openrouter_toolkit.py budget --check
列出模型
bash
python3 {baseDir}/scripts/openrouter_toolkit.py models --top 20
python3 {baseDir}/scripts/openrouter_toolkit.py models --search claude
python3 {baseDir}/scripts/openrouter_toolkit.py models --best code
智能路由工作原理
路由器根据任务类型使用以下启发式方法对模型进行评分:
| 任务 | 优先级 | 示例模型 |
|---|
| 代码 | 高上下文、代码基准测试 | Claude Opus, GPT-4o |
| 推理 |
思考/推理能力 | Claude Opus, o1 |
| 创意 | 创意写作质量 | Claude Sonnet, GPT-4o |
| 快速 | 低延迟、足够好的质量 | Claude Haiku, GPT-4o-mini |
| 低成本 | 每 token 最低成本 | Gemini Flash, GPT-4o-mini |
数据存储
成本日志存储在 SQLite 数据库中,路径为 {baseDir}/data/openrouter_costs.db。
致谢
由
M. Abidi 构建 |
agxntsix.ai
YouTube |
GitHub
属于面向 OpenClaw 智能体的
AgxntSix 技能套件 的一部分。
📅 需要为你的业务设置 OpenClaw? 预约免费咨询