MCPcopy
hub / github.com/anomalyco/models.dev / buildPricingMap

Function buildPricingMap

packages/core/script/generate-digitalocean.ts:158–182  ·  view source on GitHub ↗
(entries: z.infer<typeof PricingEntry>[])

Source from the content-addressed store, hash-verified

156}
157
158function buildPricingMap(entries: z.infer<typeof PricingEntry>[]): Map<string, ModelPricing> {
159 const map = new Map<string, ModelPricing>();
160
161 for (const entry of entries) {
162 const displayName = normalizeDisplayName(entry.name);
163 const modelId = PRICING_NAME_MAP[displayName];
164 if (!modelId) continue;
165
166 const isInput = entry.name.toLowerCase().includes("input tokens");
167 const isOver200k = entry.prompt_tokens === ">200k";
168 // Round to avoid float noise (e.g. 0.9900000000000001)
169 const rate = Math.round(entry.price.rate * 10000) / 10000;
170
171 const existing = map.get(modelId) ?? ({} as ModelPricing);
172
173 if (isInput && isOver200k) existing.inputOver200k = rate;
174 else if (!isInput && isOver200k) existing.outputOver200k = rate;
175 else if (isInput) existing.input = rate;
176 else existing.output = rate;
177
178 map.set(modelId, existing);
179 }
180
181 return map;
182}
183
184// ---------------------------------------------------------------------------
185// Existing TOML shape (fields we read and may preserve)

Callers 1

mainFunction · 0.85

Calls 1

normalizeDisplayNameFunction · 0.85

Tested by

no test coverage detected