mcpField
O
openrouter-trending-models

openrouter-trending-models

github.com/madappgangAgent 工作流287173 次安装36 周前更新
代码仓库

关于 openrouter-trending-models

此 Agent skill 通过脚本获取 OpenRouter 编程模型趋势榜,并整理模型使用量、上下文长度和价格等数据,供模型选择与开发工作流参考。

主要功能

  1. 01获取编程模型趋势榜前 9 名
  2. 02整理模型 ID 与名称
  3. 03提供用量、上下文和价格
  4. 04生成提供商及价格统计
  5. 05输出结构化 JSON

适用场景

  1. 01为多模型评审选择模型
  2. 02比较模型上下文长度与成本
  3. 03更新 Agent 工作流中的模型建议
  4. 04刷新插件文档中的模型列表

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/madappgang/claude-code --skill openrouter-trending-models

安装后在 Claude Code 中输入/openrouter-trending-models确认已加载。

详细介绍

OpenRouter 热门模型技能

概述

此技能可获取 OpenRouter 公开排行榜中当前热门的编程模型。它会运行一个 Bun 脚本,抓取、解析并整理使用量最高的 9 个编程 AI 模型的数据。

你将获得:

  • 模型 ID 和名称(例如,x-ai/grok-code-fast-1)
  • Token 使用量统计(上周趋势)
  • 上下文窗口大小(输入容量)
  • 定价信息(按 Token 计价及每 1M 个 Token 的价格)
  • 汇总统计(顶级提供商、价格区间、平均值)

数据来源:

**更新频率:**每周(OpenRouter 每周更新排行榜)


何时使用此技能

在以下情况下使用此技能:

  1. 为多模型评审选择模型

    • 计划评审者需要当前热门模型
    • 用户询问“我应该使用哪些模型进行评审?”
    • 更新 Agent 工作流中的模型建议
  2. 研究 AI 编码趋势

    • 开发者想了解最受欢迎的编码模型
    • 比较模型能力(上下文、定价、使用量)
    • 为特定任务寻找“性价比最高”的模型
  3. 更新插件文档

    • 刷新 README 文件中的模型列表
    • 确保 Agent 提示词与热门模型保持同步
    • 文档维护工作流
  4. 优化成本

    • 寻找上下文容量足够且价格最低的模型
    • 比较热门模型的定价
    • 规划 AI 辅助开发的预算
  5. 模型推荐

    • 用户询问“X 任务最适合用什么模型?”
    • 提供基于数据的建议,而不是硬编码列表
    • 根据需求提供替代方案

快速开始

运行脚本

基本用法:

bun run scripts/get-trending-models.ts

输出到文件:

bun run scripts/get-trending-models.ts > trending-models.json

美化输出:

bun run scripts/get-trending-models.ts | jq '.'

帮助:

bun run scripts/get-trending-models.ts --help
预期输出

脚本会将结构化 JSON 输出到 stdout:

{
  "metadata": {
    "fetchedAt": "2025-11-14T10:30:00.000Z",
    "weekEnding": "2025-11-10",
    "category": "programming",
    "view": "trending"
  },
  "models": [
    {
      "rank": 1,
      "id": "x-ai/grok-code-fast-1",
      "name": "Grok Code Fast",
      "tokenUsage": 908664328688,
      "contextLength": 131072,
      "maxCompletionTokens": 32768,
      "pricing": {
        "prompt": 0.0000005,
        "completion": 0.000001,
        "promptPer1M": 0.5,
        "completionPer1M": 1.0
      }
    }
    // ... 8 more models
  ],
  "summary": {
    "totalTokens": 4500000000000,
    "topProvider": "x-ai",
    "averageContextLength": 98304,
    "priceRange": {
      "min": 0.5,
      "max": 15.0,
      "unit": "USD per 1M tokens"
    }
  }
}
执行时间

典型执行时间:2-5 秒

  • 获取排行榜:约 1 秒
  • 获取模型详情:约 1-2 秒(并行请求)
  • 解析和格式化:<1 秒

输出格式

元数据对象
{
  fetchedAt: string;        // ISO 8601 timestamp of when data was fetched
  weekEnding: string;       // YYYY-MM-DD format, end of ranking week
  category: "programming";  // Fixed category
  view: "trending";         // Fixed view type
}
模型数组(9 项)

每个模型包含:

{
  rank: number;             // 1-9, position in trending list
  id: string;               // OpenRouter model ID (e.g., "x-ai/grok-code-fast-1")
  name: string;             // Human-readable name (e.g., "Grok Code Fast")
  tokenUsage: number;       // Total tokens used last week
  contextLength: number;    // Maximum input tokens
  maxCompletionTokens: number; // Maximum output tokens
  pricing: {
    prompt: number;         // Per-token input cost (USD)
    completion: number;     // Per-token output cost (USD)
    promptPer1M: number;    // Input cost per 1M tokens (USD)
    completionPer1M: number; // Output cost per 1M tokens (USD)
  }
}
汇总对象
{
  totalTokens: number;      // Sum of token usage across top 9 models
  topProvider: string;      // Most represented provider (e.g., "x-ai")
  averageContextLength: number; // Average context window size
  priceRange: {
    min: number;            // Lowest prompt price per 1M tokens
    max: number;            // Highest prompt price per 1M tokens
    unit: "USD per 1M tokens";
  }
}

集成示例

示例 1:在 Agent 中动态选择模型

**场景:**计划评审者需要当前热门模型进行多模型评审

# In plan-reviewer agent workflow

STEP 1: Fetch trending models
- Execute: Bash("bun run scripts/get-trending-models.ts > /tmp/trending-models.json")
- Read: /tmp/trending-models.json

STEP 2: Parse and present to user
- Extract top 3-5 models from models array
- Display with context and pricing info
- Let user select preferred model(s)

STEP 3: Use selected model for review
- Pass model ID to Claudish proxy

实现:

// Agent reads output
const data = JSON.parse(bashOutput);

// Extract top 5 models
const topModels = data.models.slice(0, 5);

// Present to user
const modelList = topModels.map((m, i) =>
  `${i + 1}. **${m.name}** (\`${m.id}\`)
   - Context: ${m.contextLength.toLocaleString()} tokens
   - Pricing: $${m.pricing.promptPer1M}/1M input
   - Usage: ${(m.tokenUsage / 1e9).toFixed(1)}B tokens last week`
).join('\n\n');

// Ask user to select
const userChoice = await AskUserQuestion(`Select model for review:\n\n${modelList}`);
示例 2:寻找性价比最高的模型

**场景:**用户想要成本最低的长上下文模型

# Fetch models and filter with jq
bun run scripts/get-trending-models.ts | jq '
  .models
  | map(select(.contextLength > 100000))
  | sort_by(.pricing.promptPer1M)
  | .[:3]
  | .[] | {
      name,
      id,
      contextLength,
      price: .pricing.promptPer1M
    }
'

输出:

{
  "name": "Gemini 2.5 Flash",
  "id": "google/gemini-2.5-flash",
  "contextLength": 1000000,
  "price": 0.075
}
{
  "name": "Grok Code Fast",
  "id": "x-ai/grok-code-fast-1",
  "contextLength": 131072,
  "price": 0.5
}
示例 3:更新插件文档

**场景:**每周自动更新 README 中的模型建议

# Fetch models
bun run scripts/get-trending-models.ts > trending.json

# Extract top 5 model names and IDs
jq -r '.models[:5] | .[] | "- `\(.id)` - \(.name) (\(.contextLength / 1024)K context, $\(.pricing.promptPer1M)/1M)"' trending.json

# Output (ready for README):
# - `x-ai/grok-code-fast-1` - Grok Code Fast (128K context, $0.5/1M)
# - `anthropic/claude-4.5-sonnet-20250929` - Claude 4.5 Sonnet (200K context, $3.0/1M)
# - `google/gemini-2.5-flash` - Gemini 2.5 Flash (976K context, $0.075/1M)
示例 4:检查是否有新晋热门模型

**场景:**识别是否有新模型进入前 9 名

# Save current trending models
bun run scripts/get-trending-models.ts | jq '.models | map(.id)' > current.json

# Compare with previous week (saved as previous.json)
diff <(jq -r '.[]' previous.json | sort) <(jq -r '.[]' current.json | sort)

# Output shows new entries (>) and removed entries (<)

故障排除

问题:脚本无法获取排行榜

错误消息:

✗ Error: Failed to fetch rankings: fetch failed

可能原因:

  1. 没有互联网连接
  2. OpenRouter 网站宕机
  3. 防火墙阻止访问 openrouter.ai
  4. URL 结构已更改

解决方案:

  1. 测试连接:
curl -I https://openrouter.ai/rankings
# Should return HTTP 200
  1. 在浏览器中检查 URL:

    • 访问 https://openrouter.ai/rankings
    • 确认页面可以加载并显示编程排行榜
    • 如果 URL 重定向,请更新脚本中的 RANKINGS_URL 常量
  2. 检查防火墙/代理:

# Test from command line
curl "https://openrouter.ai/rankings?category=programming&view=trending&_rsc=2nz0s"
# Should return HTML with embedded JSON
  1. 使用备用数据:
    • 保留上次成功的输出作为备用数据
    • 如果缓存的 trending-models.json 不超过 14 天,则使用该文件
问题:解析错误(RSC 格式无效)

错误消息:

✗ Error: Failed to extract JSON from RSC format

原因: OpenRouter 更改了其页面结构

解决方案:

  1. 检查原始 HTML:
curl "https://openrouter.ai/rankings?category=programming&view=trending&_rsc=2nz0s" | head -200
  1. 查找数据模式:

    • 在输出中搜索 "data":[{
    • 检查行是否以不同的前缀开头(不是 1b:)
    • 验证 JSON 结构是否符合预期格式
  2. 更新脚本中的正则表达式:

    • 编辑 scripts/get-trending-models.ts
    • 修改 fetchRankings() 函数中的正则表达式
    • 使用新模式进行测试
  3. 报告问题:

    • 在插件仓库中提交问题
    • 附上原始 HTML 示例(前 500 个字符)
    • 说明错误从何时开始出现
问题:未找到模型详情

警告消息:

Warning: Model x-ai/grok-code-fast-1 not found in API, using defaults

原因: 排名中的模型 ID 与 API 不匹配

影响: 模型的上下文和定价值将为 0

解决方案:

  1. 确认模型是否存在于 API 中:
curl "https://openrouter.ai/api/v1/models" | jq '.data[] | select(.id == "x-ai/grok-code-fast-1")'
  1. 检查 ID 是否不匹配:

    • 排名可能使用不同的 ID 格式
    • API 中的模型可能使用了其他名称
    • 模型可能是新模型,尚未收录到 API 中
  2. 手动修正:

    • 编辑输出 JSON 文件
    • 从 OpenRouter 网站添加正确的详情
    • 记录差异,以便日后修复
问题:数据过时警告

症状: 与 OpenRouter 网站相比,模型似乎已过时

检查数据时效:

jq '.metadata.fetchedAt' trending-models.json
# Compare with current date

解决方案:

  1. 重新运行脚本:
bun run scripts/get-trending-models.ts > trending-models.json
  1. 设置每周刷新:

    • 添加到 cron:0 0 * * 1 cd /path/to/repo && bun run scripts/get-trending-models.ts > skills/openrouter-trending-models/trending-models.json
    • 或使用 GitHub Actions(参见自动化部分)
  2. 在 Agent 中添加过时检查:

const data = JSON.parse(readFile("trending-models.json"));
const fetchedDate = new Date(data.metadata.fetchedAt);
const daysSinceUpdate = (Date.now() - fetchedDate.getTime()) / (1000 * 60 * 60 * 24);

if (daysSinceUpdate > 7) {
  console.warn("Data is over 7 days old, consider refreshing");
}

最佳实践

数据时效性

建议的更新计划:

  • 每周:理想(与 OpenRouter 的更新周期一致)
  • 每两周:数据稳定期间可接受
  • 每月:生产环境使用的最低频率

过时程度指南:

  • 0-7 天:新鲜(绿色)
  • 8-14 天:稍有过时(黄色)
  • 15-30 天:过时(橙色)
  • 30 天以上:非常过时(红色)
缓存策略

何时缓存:

  • 多个 Agent 需要相同的数据
  • 频繁进行模型选择工作流
  • 避免触发速率限制

如何缓存:

  1. 运行一次脚本:bun run scripts/get-trending-models.ts > trending-models.json
  2. 提交到仓库(放在 skills/openrouter-trending-models/ 下)
  3. Agent 从文件读取数据,而不是重新运行脚本
  4. 每周通过手动运行或自动化刷新

缓存失效:

# Check if cache is stale (> 7 days)
if [ $(find trending-models.json -mtime +7) ]; then
  echo "Cache is stale, refreshing..."
  bun run scripts/get-trending-models.ts > trending-models.json
fi
Agent 中的错误处理

优雅降级模式:

1. Try to fetch fresh data
   - Run: bun run scripts/get-trending-models.ts
   - If succeeds: Use fresh data
   - If fails: Continue to step 2

2. Try cached data
   - Check if trending-models.json exists
   - Check if < 14 days old
   - If valid: Use cached data
   - If not: Continue to step 3

3. Fallback to hardcoded models
   - Use known good models from agent prompt
   - Warn user data may be outdated
   - Suggest manual refresh
集成模式

模式 1:按需获取(新鲜数据)

# Run before each use
bun run scripts/get-trending-models.ts > /tmp/models.json
# Read from /tmp/models.json

模式 2:缓存(快速访问)

# Check cache age first
CACHE_FILE="skills/openrouter-trending-models/trending-models.json"
if [ ! -f "$CACHE_FILE" ] || [ $(find "$CACHE_FILE" -mtime +7) ]; then
  bun run scripts/get-trending-models.ts > "$CACHE_FILE"
fi
# Read from cache

模式 3:后台刷新(非阻塞)

# Start refresh in background (don't wait)
bun run scripts/get-trending-models.ts > trending-models.json &

# Continue with workflow
# Use cached data if available
# Fresh data will be ready for next run

更新日志

v1.0.0(2025-11-14)
  • 首次发布
  • 从 OpenRouter 获取排名前 9 的热门编程模型
  • 解析 RSC 流式格式
  • 包含上下文长度、定价和 Token 使用量
  • 零依赖(仅使用 Bun 内置 API)
  • 全面的错误处理
  • 汇总统计(Token 总数、顶级提供商、价格范围)

后续增强

计划中的功能
  • 类别选择(编程、创意、分析等)
  • 历史趋势跟踪(按周比较)
  • 提供商筛选(聚焦特定提供商)
  • 成本计算器(估算工作流成本)
研究方向
  • 分析排名与模型性能基准之间的关联
  • 找出「性价比最高」的模型(性能/价格比)
  • 预测即将成为热门的模型
  • 多类别分析

技能版本: 1.0.0 上次更新: 2025 年 11 月 14 日 维护: 建议每周刷新 依赖项: Bun 运行时、互联网连接

评论

支持 Markdown