Overview
Concrete tool for syncing model prices from the models.dev catalog to the D1 database, run nightly via cron to keep newly observed model labels priced.
Description
The syncModelPrices function fetches the models.dev catalog JSON, iterates over observed model labels in telemetry, normalizes each label to candidate canonical IDs, matches them against the catalog, and inserts per-model input/output/cache pricing into the D1 model_prices table. The CACHE_INCLUSIVE_PROVIDERS set marks providers whose reported input tokens already include cache reads, preventing double-billing.
Usage
- Automatic: Runs nightly via Cloudflare Workers cron trigger.
- Manual: Run via
scripts/sync-model-prices.mjs.
Code Reference
Source Location
- Repository: jcode
- File: telemetry-worker/src/worker.js (cron handler), telemetry-worker/scripts/sync-model-prices.mjs (manual)
Signature
async function syncModelPrices(env)
// Manual script (sync-model-prices.mjs):
async function runWranglerFile(sqlText, label)
async function queryRows(sql)
async function main()
Import
// Internal worker function, called from scheduled handler.
// Manual: node telemetry-worker/scripts/sync-model-prices.mjs
I/O Contract
Inputs
Outputs
| Name |
Type |
Description
|
| model_prices |
D1 table /// Per-model input/output/cache pricing
|
Usage Examples
Manual Price Sync
# Run the sync script manually
node telemetry-worker/scripts/sync-model-prices.mjs
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.