正式价格 API
把 GrokCode 聚合的官方价 + OpenRouter 目录价以 NewAPI / Sub2API 可直接消费的格式公开, 方便中转站一键同步倍率。数据只读、无需 Key、支持 CORS。
能力边界 · 正式价格 API对外提供 NewAPI/Sub2API 可同步的公开价格 JSON。
能做什么
- GET /api/pricing 兼容 NewAPI type2
- GET /api/ratio_config 倍率 map
- LiteLLM 风格 model_prices JSON
- CORS 公开读
不能 / 不是
- 不保证与所有厂商官网实时一致
- 不是你站点的实际售价
- 动态/负价模型已过滤
结果怎么读
- model_ratio = 输入$/M ÷ 2
- 合并源:官方优先 + OpenRouter 补全
- 缓存约 5 分钟
数据与额度边界
- 公开接口无 Key
- 滥用可能限流
可信度:同步格式正确;价格为聚合参考。
一分钟接入 NewAPI
- 打开 NewAPI 管理后台 → 设置 / 倍率设置 / 上游倍率同步
- 新增上游:
- Base URL:
https://www.grokcode.cn - Endpoint:
/api/pricing(默认即可) - 无需填写 API Key(公开接口)
- Base URL:
- 拉取后勾选需要的模型,写入本地 ModelRatio / CompletionRatio
- 公式对齐 NewAPI:
model_ratio = 输入$/M ÷ 2(ratio=1 → $2/M 输入) ,completion_ratio = 输出价 ÷ 输入价
# 验证 curl -sS https://www.grokcode.cn/api/pricing | head -c 400 curl -sS https://www.grokcode.cn/api/ratio_config | head -c 400
接入 Sub2API
- Sub2API 默认从 LiteLLM 风格 JSON 同步模型单价(input/output per token)
- 将远程价格地址配置为:
https://www.grokcode.cn/api/model_prices_and_context_window.json - 或使用短路径
https://www.grokcode.cn/api/v1/model_prices - 重启 / 触发价格刷新后,后台渠道定价会按该表作为默认价(渠道自定义价仍优先)
# 验证 LiteLLM 键 curl -sS https://www.grokcode.cn/api/model_prices_and_context_window.json | head -c 500
接口一览
| 路径 | 用途 | 说明 |
|---|---|---|
/api/pricing | NewAPI 上游倍率同步 | NewAPI 价格列表(推荐) 与 NewAPI GET /api/pricing 同构(success + data[] + group_ratio)。控制台上游同步默认 Endpoint。 |
/api/ratio_config | NewAPI 上游同步 · Endpoint 改为 /api/ratio_config | NewAPI 倍率 Map type1:data.model_ratio / completion_ratio / cache_ratio 字典,适合批量覆盖本地倍率。 |
/api/model_prices_and_context_window.json | Sub2API MODEL_PRICES_URL 或等价配置 | LiteLLM / Sub2API 价格表 model → input_cost_per_token / output_cost_per_token 等,兼容 Sub2API 远程价格仓库格式。 |
/api/v1/model_prices | Sub2API / 自建脚本 | LiteLLM 短路径 与上一项相同内容的短别名。 |
/api/v1/prices | 二次开发 / 监控 | GrokCode 原生 JSON 同时给出 USD/M 与 NewAPI model_ratio,带 endpoints 索引,适合自研对接。 |
查询参数
?source=merged(默认)官方库优先覆盖,OpenRouter 补全?source=official仅站内官方 API 报价?source=openrouter仅 OpenRouter 公开目录价
缓存约 5 分钟(CDN/浏览器 s-maxage=300)。价格为公开目录价,不构成交易报价;中转实际扣费以站点账单为准。
响应示例(节选)
// GET /api/pricing
{
"success": true,
"data": [
{
"model_name": "gpt-4o",
"quota_type": 0,
"model_ratio": 1.25,
"completion_ratio": 4,
"model_price": 0,
"enable_groups": ["default"],
"grokcode": { "input_usd_per_m": 2.5, "output_usd_per_m": 10 }
}
],
"group_ratio": { "default": 1 },
"usable_group": { "default": "default" }
}
// GET /api/ratio_config
{
"success": true,
"data": {
"model_ratio": { "gpt-4o": 1.25 },
"completion_ratio": { "gpt-4o": 4 }
}
}관련 도구
Clavue CLI / imux IDE / clavue-2.1
Clavue · CLI 与 Agent 平台
CLI / GUI Agent 运行时、设备登录、会员额度与 OpenAI 兼容 API(api.clavue.com)。开发脚本、CI 与本地工具一条链路。
打开 Clavue ↗imux · 原生 macOS AI IDE
Clavue 平台的原生 IDE:多 Agent 分屏、Ghostty 级终端、Agent Chat、浏览器自动化与 Supervisor——不是又一个 Electron 壳。
了解 imux ↗Clavue 2.1 · 产品级大模型
旗舰模型 clavue-2.1(及 fast / pro / rev):适合复杂推理与长程 Agent 循环。Chat、imux、API 共用会员额度。
查看模型 ↗