Model Pricing Calculator
A skill for fetching AI model pricing data from configured platform APIs and computing
standardized pricing ratios (model ratio, completion ratio, group ratio).
When to Use
- - Fetching model pricing information from AI API aggregation platforms
- Computing model ratios, completion ratios, and group ratios from raw pricing data
- Unifying pricing across multiple platforms using a consistent model ratio + group ratio scheme
- Reverse-calculating ratio configurations from target input/output prices
- Adding new pricing source URLs to the configuration
Core Concepts
Pricing Formula
CODEBLOCK0
Reverse Calculation
CODEBLOCK1
Workflow
Step 1: Check and Update URL Configuration
Read references/pricing_urls.json to verify configured platform URLs. To add a new
platform, append a new entry with name, pricing_page, and api_endpoint fields.
The API endpoints typically follow the pattern {base_url}/api/pricing for platforms
built on New API / One API systems.
Step 2: Fetch and Calculate Ratios
Run the calculation script:
CODEBLOCK2
Options:
- -
--urls-file <path> — custom URL config file path - INLINECODE6 — save results as separate JSON files to the specified directory
- INLINECODE7 — print a price verification table showing actual prices per group
- INLINECODE8 — skip snapshot saving and diff comparison
- INLINECODE9 — filter by model names, comma-separated, supports wildcard
* (e.g. gpt-4*,claude-*) - INLINECODE12 — filter by group names, comma-separated, supports wildcard
* (e.g. default,aws*) - INLINECODE15 — filter by data source name, comma-separated, supports wildcard
* (e.g. PackyAPI or 12AI,Packy*). Names correspond to name field in INLINECODE20
The script will:
- 1. Fetch pricing data from each configured API endpoint
- Extract model ratios, completion ratios, and group ratios
- Unify duplicate models across platforms (first-source wins for ratios)
- Apply
--models / --groups filters if specified (supports wildcard *) - Output results in three standardized JSON blocks
- Compare with previous snapshot (if exists, skipped in filter mode) and report any additions, removals, or value changes
- Save current data as
data/latest_snapshot.json (skipped in filter mode to avoid partial data overwriting full snapshot)
Filter Examples
Query specific models only:
CODEBLOCK3
Query specific groups only:
CODEBLOCK4
Combine both filters:
CODEBLOCK5
Query from a specific data source only:
CODEBLOCK6
Combine source, model and group filters:
CODEBLOCK7
Note: When --models, --groups, or --source is used, snapshot saving and diff comparison are automatically skipped to prevent partial data from overwriting the complete snapshot.
Step 3: Review Output Format
The output strictly follows this exact structure with 3 JSON blocks:
CODEBLOCK8
Step 4: Snapshot and Diff
Each run automatically:
- - Loads the previous snapshot from
data/latest_snapshot.json (if it exists) - Compares current results with the previous snapshot
- Reports all differences: added models, removed models, and changed values
- Overwrites the snapshot with the latest data
The diff report format:
CODEBLOCK9
Use --no-snapshot to skip this behavior.
Step 5: Cross-Platform Unification Strategy
When the same model appears on multiple platforms:
- - Model ratio and completion ratio remain identical across platforms
- Price differences are controlled through group ratios assigned to each platform/channel
- Each platform's pricing channel corresponds to a specific group in the
group_ratio map
For detailed pricing rules and formulas, refer to references/pricing_rules.md.
Bundled Resources
| Resource | Purpose |
|---|
| INLINECODE32 | Main script for data fetching, ratio calculation, snapshot and diff |
| INLINECODE33 |
Platform URL configuration (add new sources here) |
|
references/pricing_rules.md | Detailed pricing calculation rules and output format spec |
|
data/latest_snapshot.json | Auto-generated snapshot of the latest run (created after first run) |
模型定价计算器
用于从配置的平台API获取AI模型定价数据,并计算标准化定价比率(模型倍率、补全倍率、分组倍率)的技能。
使用场景
- - 从AI API聚合平台获取模型定价信息
- 根据原始定价数据计算模型倍率、补全倍率和分组倍率
- 使用一致的模型倍率+分组倍率方案统一多个平台的定价
- 根据目标输入/输出价格反向计算倍率配置
- 向配置中添加新的定价来源URL
核心概念
定价公式
基础价格:$0.002 / 1K tokens(1美元 = 500,000额度)
模式1 - 基于倍率(按token计费):
费用 = (输入Token数 + 输出Token数 × 补全倍率) × 模型倍率 × 分组倍率
模式2 - 固定价格(按调用计费,优先级更高):
费用 = 模型价格(美元) × 500,000 × 分组倍率
反向计算
模型倍率 = 每1K输入价格 / 0.002
补全倍率 = 每1K输出价格 / 每1K输入价格
工作流程
步骤1:检查并更新URL配置
读取 references/pricingurls.json 以验证已配置的平台URL。要添加新平台,请追加包含 name、pricingpage 和 api_endpoint 字段的新条目。
对于基于New API / One API系统构建的平台,API端点通常遵循 {base_url}/api/pricing 的模式。
步骤2:获取并计算倍率
运行计算脚本:
bash
python scripts/fetchandcalculate.py
选项:
- - --urls-file <路径> — 自定义URL配置文件路径
- --output-dir <路径> — 将结果保存为单独的JSON文件到指定目录
- --verify — 打印显示每个分组实际价格的价格验证表
- --no-snapshot — 跳过快照保存和差异比较
- --models <模式> — 按模型名称过滤,逗号分隔,支持通配符 (例如 gpt-4,claude-)
- --groups <模式> — 按分组名称过滤,逗号分隔,支持通配符 (例如 default,aws)
- --source <模式> — 按数据源名称过滤,逗号分隔,支持通配符 (例如 PackyAPI 或 12AI,Packy*)。名称对应 pricing_urls.json 中的 name 字段
脚本将:
- 1. 从每个配置的API端点获取定价数据
- 提取模型倍率、补全倍率和分组倍率
- 统一跨平台的重复模型(倍率以首个来源为准)
- 如果指定了 --models / --groups 过滤器则应用(支持通配符 *)
- 以三个标准化的JSON块输出结果
- 与之前的快照比较(如果存在,过滤模式下跳过),并报告任何新增、删除或数值变化
- 将当前数据保存为 data/latest_snapshot.json(过滤模式下跳过,以避免部分数据覆盖完整快照)
过滤示例
仅查询特定模型:
bash
python scripts/fetchandcalculate.py --models gpt-4,claude-opus
仅查询特定分组:
bash
python scripts/fetchandcalculate.py --groups default,aws
组合两个过滤器:
bash
python scripts/fetchandcalculate.py --models gpt-4o --groups default,gemini
仅从特定数据源查询:
bash
python scripts/fetchandcalculate.py --source PackyAPI
组合数据源、模型和分组过滤器:
bash
python scripts/fetchandcalculate.py --source PackyAPI --models claude- --groups aws
注意:当使用 --models、--groups 或 --source 时,会自动跳过快照保存和差异比较,以防止部分数据覆盖完整快照。
步骤3:查看输出格式
输出严格遵循以下包含3个JSON块的精确结构:
(1)模型倍率
{
claude-haiku-4-5-20251001: 1,
claude-opus-4-5-20251101: 2.5,
claude-opus-4-6: 2.5
}
(2)模型补全倍率
{
claude-haiku-4-5-20251001: 5,
claude-opus-4-5-20251101: 5,
claude-opus-4-6: 5
}
(3)分组倍率
{
default: 1.2,
aws: 2,
gemini: 0.6,
gemini-1: 3
}
步骤4:快照与差异
每次运行自动:
- - 从 data/latest_snapshot.json 加载之前的快照(如果存在)
- 将当前结果与之前的快照进行比较
- 报告所有差异:新增模型、删除模型和数值变化
- 用最新数据覆盖快照
差异报告格式:
============================================================
与上次数据对比(上次保存时间: 2025-03-23 10:00:00)
============================================================
模型倍率:
【新增 2 项】
+ new-model-a: 1.5
+ new-model-b: 2.0
【删除 1 项】
- old-model-x: 0.8
【数值变化 1 项】
* gpt-5: 0.625 → 0.75
模型补全倍率: 无变化
分组倍率: 无变化
使用 --no-snapshot 跳过此行为。
步骤5:跨平台统一策略
当同一模型出现在多个平台上时:
- - 模型倍率和补全倍率在跨平台时保持一致
- 价格差异通过分配给每个平台/渠道的分组倍率来控制
- 每个平台的定价渠道对应 group_ratio 映射中的一个特定分组
有关详细的定价规则和公式,请参考 references/pricing_rules.md。
捆绑资源
| 资源 | 用途 |
|---|
| scripts/fetchandcalculate.py | 用于数据获取、倍率计算、快照和差异比较的主脚本 |
| references/pricing_urls.json |
平台URL配置(在此处添加新来源) |
| references/pricing_rules.md | 详细的定价计算规则和输出格式规范 |
| data/latest_snapshot.json | 自动生成的最近一次运行快照(首次运行后创建) |