Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1jehuang Jcode syncModelPrices

From Leeroopedia
Knowledge Sources
Domains Telemetry, Data_Normalization
Last Updated 2026-10-18 00:00 GMT

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

Name Type Required Description
env.DB D1 Yes /// Cloudflare D1 binding
CATALOG_URL const Yes /// https://models.dev/api.json

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.
Principle
Implementation
Heuristic
Environment