mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
Keep model pricing automatic instead of hand-coding new models. The bundler now layers three sources in priority order: LiteLLM (broad list prices), hand-curated MANUAL_ENTRIES overrides, then a separate last-resort fallback file gap-filled from models.dev first-party makers (official direct prices) and OpenRouter (resale backstop). New models such as MiniMax-M3 ($0.6/$2.4) now price correctly with no per-model code. The fallback is written to its own pricing-fallback.json and consulted only case-insensitively as the final step in getModelCosts, so a reseller variant name can never shadow a canonical or aliased match. Fixes surfaced while building and verifying this: - Alias precedence: LiteLLM ships snowflake/claude-4-opus ($5), which the bundler strips to a bare claude-4-opus key that shadowed the curated alias to claude-opus-4 ($15 official). An explicit alias for a bare name now wins over a coincidental stripped reseller key; the prefixed gateway price is still returned for the fully-qualified id. - Zero-stub guard: LiteLLM [0,0] price stubs (e.g. GigaChat-2-Max) are excluded from the case-insensitive index so a case-mismatched query stays null and keeps firing the unknown-model warning instead of silently reporting $0. - Negative-sentinel guard: OpenRouter returns -1 for variable/BYOK-priced models. The bundler now rejects any non-positive rate pair (and strips the sentinel from cache fields) so a negative per-token cost can never ship and subtract from spend totals. Bundler hardening: bareKey strips @pin and date suffixes to match the runtime canonical form, seen-set dedupes on both full and bare key shapes, and it logs MANUAL_ENTRIES now covered upstream plus models.dev allowlist drift. Extracted buildCosts so the cache-cost heuristics live in one place. Added a data-hygiene test that fails CI if a rebundle reintroduces negative, free, or unreachable fallback entries.
58 lines
2.4 KiB
TypeScript
58 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import { getModelCosts, getShortModelName } from '../src/models.js'
|
|
|
|
// Verifies MiniMax pricing loaded from FALLBACK_PRICING (no network call).
|
|
// pricingCache stays null until loadPricing() runs, so getModelCosts falls
|
|
// through to FALLBACK_PRICING which is what we want to validate here.
|
|
|
|
describe('MiniMax model pricing', () => {
|
|
it('returns pricing for MiniMax-M2.7', () => {
|
|
const costs = getModelCosts('MiniMax-M2.7')
|
|
expect(costs).not.toBeNull()
|
|
expect(costs!.inputCostPerToken).toBe(0.3e-6)
|
|
expect(costs!.outputCostPerToken).toBe(1.2e-6)
|
|
expect(costs!.cacheReadCostPerToken).toBe(0.06e-6)
|
|
expect(costs!.cacheWriteCostPerToken).toBe(0.375e-6)
|
|
expect(costs!.fastMultiplier).toBe(1)
|
|
})
|
|
|
|
it('returns pricing for MiniMax-M2.7-highspeed', () => {
|
|
const costs = getModelCosts('MiniMax-M2.7-highspeed')
|
|
expect(costs).not.toBeNull()
|
|
expect(costs!.inputCostPerToken).toBe(0.6e-6)
|
|
expect(costs!.outputCostPerToken).toBe(2.4e-6)
|
|
expect(costs!.cacheReadCostPerToken).toBe(0.06e-6)
|
|
expect(costs!.cacheWriteCostPerToken).toBe(0.375e-6)
|
|
expect(costs!.fastMultiplier).toBe(1)
|
|
})
|
|
|
|
it('returns official pricing for MiniMax-M3', () => {
|
|
// M3 is gap-filled automatically (LiteLLM, with models.dev first-party as
|
|
// the cross-check): $0.6/$2.4 per M, the official MiniMax direct price - not
|
|
// a discounted reseller rate (e.g. OpenRouter's $0.3/$1.2).
|
|
const costs = getModelCosts('MiniMax-M3')
|
|
expect(costs).not.toBeNull()
|
|
expect(costs!.inputCostPerToken).toBe(0.6e-6)
|
|
expect(costs!.outputCostPerToken).toBe(2.4e-6)
|
|
})
|
|
|
|
it('highspeed pricing is distinct from base model pricing', () => {
|
|
const base = getModelCosts('MiniMax-M2.7')
|
|
const fast = getModelCosts('MiniMax-M2.7-highspeed')
|
|
expect(fast!.inputCostPerToken).toBeGreaterThan(base!.inputCostPerToken)
|
|
expect(fast!.outputCostPerToken).toBeGreaterThan(base!.outputCostPerToken)
|
|
})
|
|
|
|
it('returns short name for MiniMax-M2.7', () => {
|
|
expect(getShortModelName('MiniMax-M2.7')).toBe('MiniMax M2.7')
|
|
})
|
|
|
|
it('returns short name for MiniMax-M2.7-highspeed', () => {
|
|
expect(getShortModelName('MiniMax-M2.7-highspeed')).toBe('MiniMax M2.7 Highspeed')
|
|
})
|
|
|
|
it('handles MiniMax model ID with date suffix', () => {
|
|
expect(getShortModelName('MiniMax-M2.7-20260101')).toBe('MiniMax M2.7')
|
|
})
|
|
})
|