narev-update-llm-pricing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Update LLM pricing in the local repo

更新本地仓库中的LLM价格

This skill is not a second API spec — it describes what you can implement using the listing API that
lookup-llm-pricing
documents (
GET https://www.narev.ai/api/models/pricing
): paginate, map each row to your schema, and write a committed file. For path/query/body contracts,
402
/
404
, and
POST
calculate
, use
lookup-llm-pricing
. You do not need the Narev SDK or Vercel AI SDK — any HTTP client and file I/O in the repo's language is enough.
该技能不是第二个API规范——它描述了如何使用
lookup-llm-pricing
文档中介绍的列表API(
GET https://www.narev.ai/api/models/pricing
)来实现功能:分页查询,将每一行映射到你的 schema,并写入一个已提交的文件。关于路径/查询/请求体约定、
402
/
404
状态码以及**
POST
计算功能,请使用
lookup-llm-pricing
。你
不需要**Narev SDK或Vercel AI SDK——只需仓库所用语言中的任意HTTP客户端和文件I/O即可。

When to use this skill

何时使用该技能

  • "Update LLM model price snapshot present in your project"
  • "Refresh committed pricing registry with the latest rates (find where the project stores rates, or add a file or script if nothing exists yet)."
If the user only needs how the API works or cost for one call (
POST
calculate), point them at
lookup-llm-pricing
.
  • "更新项目中现有的LLM模型价格快照"
  • "用最新费率刷新已提交的定价注册表(查找项目存储费率的位置,如果尚未存在则添加文件或脚本)。"
如果用户仅需要了解API的工作方式单次调用的成本
POST
计算),请引导他们使用
lookup-llm-pricing

Inputs you need

所需输入

The Narev pricing API is public. No API key or bearer token is required.
  • Target file path and format (TypeScript object, JSON, YAML, Python module, etc.). Confirm before overwriting.
  • Scope: which
    provider
    values to refresh (API slugs), or the full catalog. Use the
    provider
    query parameter; omit it to fetch everything (paginate until
    page > meta.total_pages
    ).
  • Local units: the API returns USD per token. Some codebases store USD per million tokens — multiply by
    1_000_000
    only when writing that shape, and document it in the script.
Narev定价API是公开的,不需要API密钥或Bearer令牌。
  • 目标文件路径格式(TypeScript对象、JSON、YAML、Python模块等)。覆盖前请确认。
  • 范围:要刷新的
    provider
    值(API别名),或完整目录。使用
    provider
    查询参数;省略该参数则获取所有内容(分页直到
    page > meta.total_pages
    )。
  • 本地单位:API返回的是每令牌美元价格。有些代码库存储的是每百万令牌美元价格——仅当需要写入这种格式时才乘以
    1_000_000
    ,并在脚本中记录这一点。

API response shape (what you read)

API响应结构(读取内容)

Paginate with
page
,
limit
(max
1000
), and optional
provider
,
model_id
,
search
,
subprovider
. Response:
{ data: ModelPricingEntry[], meta: { total_pages, ... } }
.
Each row has
model_id
,
provider
,
subprovider
, and
pricing
. When
pricing
is
null
, skip the row (enterprise-only or unavailable).
Useful
pricing
fields (snake_case, USD per unit unless noted):
FieldMeaning
price_prompt
Input token
price_completion
Output token
price_input_cache_read
/
price_input_cache_write
Cached input tokens
price_internal_reasoning
Reasoning tokens
pricing_request
Flat per request
price_web_search
Per web-search invocation
pricing_discount
Fraction
0
1
, not a percent
price_image
,
price_audio
,
price_input_audio_cache
, etc. may appear — carry them through only if your local registry supports them.
使用
page
limit
(最大值
1000
)以及可选的
provider
model_id
search
subprovider
进行分页。响应格式:
{ data: ModelPricingEntry[], meta: { total_pages, ... } }
每一行包含
model_id
provider
subprovider
pricing
。当
pricing
null
时,跳过该行(仅限企业版或不可用)。
实用的
pricing
字段(蛇形命名法,除非特别说明,否则单位为每令牌美元):
字段含义
price_prompt
输入令牌
price_completion
输出令牌
price_input_cache_read
/
price_input_cache_write
缓存输入令牌
price_internal_reasoning
推理令牌
pricing_request
每次请求固定费用
price_web_search
每次网页搜索调用费用
pricing_discount
折扣比例
0
1
,不是百分比
可能会出现
price_image
price_audio
price_input_audio_cache
等字段——仅当本地注册表支持时才保留这些字段。

Mapping to your registry (default path)

映射到你的注册表(默认路径)

  1. Inspect the repo: find the existing pricing map or config and match key style (
    model_id
    only vs
    provider/model_id
    ), units (per token vs per 1M tokens), and which fields the app reads.
  2. Implement a script in the project's language (
    scripts/update-pricing.ts
    ,
    scripts/update_pricing.py
    , etc.) that:
    • Loops pages until done.
    • Optionally filters by one or more
      provider
      query values per run (or omit for full catalog).
    • Merges or replaces according to product needs: common pattern is merge — keep unrelated providers in file, overwrite keys returned by this fetch.
    • Writes a generated-file banner when the format allows.
    • Exits non-zero on HTTP errors so CI can fail visibly.
  3. Document the run command in a comment or README snippet (
    pnpm tsx scripts/...
    ,
    uv run python scripts/...
    , etc.).
  1. 检查仓库:找到现有的定价映射或配置,匹配键样式(仅
    model_id
    vs
    provider/model_id
    )、单位(每令牌 vs 每百万令牌)以及应用读取的字段
  2. 用项目所用语言实现一个脚本(
    scripts/update-pricing.ts
    scripts/update_pricing.py
    等),该脚本需:
    • 循环分页直到完成。
    • 可选地按每次运行的一个或多个
      provider
      查询值进行过滤(或省略以获取完整目录)。
    • 根据产品需求进行合并替换:常见模式是合并——保留文件中无关的提供商,覆盖此次获取返回的键。
    • 若格式允许,写入生成文件的注释头。
    • HTTP错误时返回非零退出码,以便CI可以明显地失败。
  3. 在注释或README片段中记录运行命令(
    pnpm tsx scripts/...
    uv run python scripts/...
    等)。

Reference pattern: merge into an existing TS registry (strip + regenerate block)

参考模式:合并到现有TS注册表(剥离并重新生成块)

Repos like Mission Control sometimes keep
MODEL_PRICING
in TypeScript with
inputPerMTok
/
outputPerMTok
. Adapt paths and regex to the real file:
  • Fetch with
    provider
    repeated per catalog you care about, or no
    provider
    for full catalog.
  • Convert API per-token rates to per-million:
    inputPerMTok = price_prompt * 1_000_000
    , same for completion.
  • Key both
    'model_id'
    and
    'provider/model_id'
    if the app resolves either style.
  • Parse the existing block, merge new rows into the dict, sort keys if you want stable diffs, replace the block with
    String.replace
    , write the file.
This is illustrative — match the project's exact types and formatting.
像Mission Control这样的仓库有时会在TypeScript中保留
MODEL_PRICING
,包含
inputPerMTok
/
outputPerMTok
。根据实际文件调整路径和正则表达式:
  • 按你关心的每个目录重复使用
    provider
    进行获取,或不指定
    provider
    以获取完整目录。
  • 将API的每令牌费率转换为每百万令牌:
    inputPerMTok = price_prompt * 1_000_000
    ,完成令牌同理。
  • 如果应用支持两种解析方式,同时使用
    'model_id'
    'provider/model_id'
    作为键。
  • 解析现有块,将新行合并到字典中,若需要稳定的差异则对键排序,用
    String.replace
    替换块,写入文件。
这只是示例——请匹配项目的确切类型和格式。

Reference pattern:
@ai-billing/core
offline resolver (optional)

参考模式:
@ai-billing/core
离线解析器(可选)

If the user already uses the Narev SDK,
createObjectPriceResolver
expects
ModelPricing
in USD per token
(do not multiply to per-million for the SDK map). Map API → SDK like this:
Narev API (
PricingData
)
SDK (
ModelPricing
)
price_prompt
promptTokens
price_completion
completionTokens
price_input_cache_read
inputCacheReadTokens
price_input_cache_write
inputCacheWriteTokens
price_internal_reasoning
internalReasoningTokens
pricing_request
request
price_web_search
webSearch
pricing_discount
discount
Output
Record<string, ModelPricing>
keyed by how the app resolves models (see multi-provider note below). Then:
ts
import { createObjectPriceResolver } from "@ai-billing/core";
import { pricing } from "./pricing";

export const priceResolver = createObjectPriceResolver(pricing);
如果用户已经在使用Narev SDK,
createObjectPriceResolver
期望的是以每令牌美元为单位的
ModelPricing
(不要为SDK映射乘以百万)。按如下方式将API映射到SDK:
Narev API (
PricingData
)
SDK (
ModelPricing
)
price_prompt
promptTokens
price_completion
completionTokens
price_input_cache_read
inputCacheReadTokens
price_input_cache_write
inputCacheWriteTokens
price_internal_reasoning
internalReasoningTokens
pricing_request
request
price_web_search
webSearch
pricing_discount
discount
输出以应用解析模型的方式为键的
Record<string, ModelPricing>
(见下文多提供商说明)。然后:
ts
import { createObjectPriceResolver } from "@ai-billing/core";
import { pricing } from "./pricing";

export const priceResolver = createObjectPriceResolver(pricing);

Workflow (agent checklist)

工作流程(代理检查清单)

1. Confirm scope and target file

1. 确认范围和目标文件

Providers, model subset (if any), output path, and whether units are per token or per 1M in the file.
确认提供商、模型子集(如有)、输出路径,以及文件中的单位是每令牌还是每百万令牌。

2. Add or update a snapshot script

2. 添加或更新快照脚本

Use the repo's language and dependencies (
fetch
/
httpx
/
requests
/
urllib
). Paginate
GET https://www.narev.ai/api/models/pricing
. Transform into the local schema. Prefer idempotent writes and small, reviewable diffs.
使用仓库的语言和依赖(
fetch
/
httpx
/
requests
/
urllib
)。分页调用
GET https://www.narev.ai/api/models/pricing
。转换为本地schema。优先使用幂等写入和易于审核的小差异。

3. Run it

3. 运行脚本

Use the project's package runner. Do not assume
pnpm
or
tsx
— check
package.json
,
pyproject.toml
, etc. Inspect the diff before committing.
使用项目的包运行器。不要假设使用
pnpm
tsx
——检查
package.json
pyproject.toml
等。提交前检查差异。

4. Wire into the app (only if applicable)

4. 接入应用(仅适用于相关场景)

For custom registries, point the app at the updated file or import. For
@ai-billing/core
, swap
createNarevPriceResolver
for
createObjectPriceResolver
as above.
对于自定义注册表,将应用指向更新后的文件或导入。对于
@ai-billing/core
,按上述方式将
createNarevPriceResolver
替换为
createObjectPriceResolver

5. Schedule refreshes (optional)

5. 定期刷新(可选)

CI on a schedule that runs the script and opens a PR keeps rates fresh with human review.
通过CI定期运行脚本并创建PR,可以在人工审核的前提下保持费率更新。

Constraints and edge cases

约束和边缘情况

  • Multi-provider models share a
    model_id
    .
    If you need per-provider rates, key with
    provider/model_id
    (and align lookup). Otherwise last write wins for bare
    model_id
    .
  • Skip
    pricing: null
    .
  • pricing_discount
    is a fraction
    (
    0.1
    = 10% off). Pass through if your registry supports it; many simple token maps ignore it.
  • API = USD per token. Scale to per-1M (or per-1K) only in your script when the destination format requires it — do not double-scale.
  • Snapshot drift. Re-run before releases that depend on accurate math.
  • Generated files. Banner comment + formatter ignore if needed.
  • 多提供商模型共享同一个
    model_id
    。如果需要按提供商区分费率,使用
    provider/model_id
    作为键(并对齐查找方式)。否则,最后写入的内容将覆盖裸
    model_id
    的条目。
  • 跳过
    pricing: null
    的行
  • pricing_discount
    是比例值
    0.1
    = 10%折扣)。如果你的注册表支持则保留;许多简单的令牌映射会忽略它。
  • API返回的是每令牌美元价格。仅当目标格式要求时才在脚本中转换为每百万(或每千)令牌价格——不要重复转换。
  • 快照偏差。在依赖准确计算的版本发布前重新运行脚本。
  • 生成文件。若需要,添加注释头并设置格式化工具忽略该文件。

Reference

参考资料

  • List pricing API:
    /platform/api-reference/endpoint/pricing/list-model-pricing
  • SDK overview (optional):
    /sdk/ai-billing/index
  • createObjectPriceResolver
    :
    /sdk/ai-billing/reference/core/typedoc/functions/createObjectPriceResolver
  • createNarevPriceResolver
    (live):
    /sdk/ai-billing/reference/core/typedoc/functions/createNarevPriceResolver
  • ModelPricing
    :
    /sdk/ai-billing/reference/core/typedoc/interfaces/ModelPricing
  • 列表定价API:
    /platform/api-reference/endpoint/pricing/list-model-pricing
  • SDK概述(可选):
    /sdk/ai-billing/index
  • createObjectPriceResolver
    /sdk/ai-billing/reference/core/typedoc/functions/createObjectPriceResolver
  • createNarevPriceResolver
    (实时):
    /sdk/ai-billing/reference/core/typedoc/functions/createNarevPriceResolver
  • ModelPricing
    /sdk/ai-billing/reference/core/typedoc/interfaces/ModelPricing