diff --git a/scripts/lib/ai-gateway-models.mjs b/scripts/lib/ai-gateway-models.mjs index 35ad8e0445e..0d9d3669a33 100644 --- a/scripts/lib/ai-gateway-models.mjs +++ b/scripts/lib/ai-gateway-models.mjs @@ -49,6 +49,7 @@ const isDecision = (item) => item.dialects?.includes('systemone') === true; function toCost(item, committedCost = {}) { const cost = rates(item.pricing); + if (item.pricing.image_output != null) cost.output_image = perMillion(item.pricing.image_output); if (item.model_type === 'embedding' || isDecision(item)) delete cost.output; if (committedCost.input_audio != null) cost.input_audio = committedCost.input_audio; const overrides = item.pricing.overrides ?? []; diff --git a/scripts/lib/ai-gateway-models.test.js b/scripts/lib/ai-gateway-models.test.js index 9d329253978..4994d188f9e 100644 --- a/scripts/lib/ai-gateway-models.test.js +++ b/scripts/lib/ai-gateway-models.test.js @@ -161,6 +161,14 @@ describe('toCatalogEntry', () => { }; expect(toCatalogEntry(item).cost).toEqual({ input: 0.2, output: 0.12, cache_read: 0.005 }); }); + + it('maps the image output rate of a model that bills image tokens separately', () => { + const item = { + ...GPT, + pricing: { prompt: '0.000002', completion: '0.000012', image_output: '0.00012' }, + }; + expect(toCatalogEntry(item).cost).toEqual({ input: 2, output: 12, output_image: 120 }); + }); }); describe('buildCatalog', () => { diff --git a/scripts/lib/models-catalog.mjs b/scripts/lib/models-catalog.mjs index 545917c9cdf..878f1dabe5b 100644 --- a/scripts/lib/models-catalog.mjs +++ b/scripts/lib/models-catalog.mjs @@ -99,10 +99,14 @@ const STATUSES = new Set(['alpha', 'beta', 'deprecated']); /** Nested rate blocks, keyed by the condition under which they apply. */ const NESTED_COST_KEYS = new Set(['context_over_200k']); const ISO_DATE = /^\d{4}-\d{2}(-\d{2})?$/; -/** Rate keys a `[cost]` block may carry, besides the `tiers` array. */ +/** + * Rate keys a `[cost]` block may carry, besides the `tiers` array. `output_image` (image output + * tokens, billed apart from text output) is ours: models.dev's cost schema has no image rate. + */ const COST_RATE_KEYS = new Set([ 'input', 'output', + 'output_image', 'cache_read', 'cache_write', 'input_audio', @@ -134,6 +138,11 @@ function canonical(value) { function comparable(model) { const picked = {}; for (const key of COMPARE_KEYS) if (model[key] !== undefined) picked[key] = model[key]; + // The mirror cannot carry `output_image` (see COST_RATE_KEYS), so it is not drift. + if (picked.cost) { + const { output_image: _outputImage, ...mirroredCost } = picked.cost; + picked.cost = mirroredCost; + } return canonical(picked); } diff --git a/scripts/lib/models-catalog.test.js b/scripts/lib/models-catalog.test.js index 5e8ccaf3e69..f28ed2c4b8c 100644 --- a/scripts/lib/models-catalog.test.js +++ b/scripts/lib/models-catalog.test.js @@ -114,6 +114,15 @@ describe('classifyDrift', () => { expect(drift.inSync).toBe(true); }); + it('does not count an image output rate models.dev cannot carry as drift', () => { + const drift = classifyDrift( + { a: model({ cost: { input: 2, output: 12, output_image: 120 } }) }, + { a: model({ cost: { input: 2, output: 12 } }) } + ); + + expect(drift.inSync).toBe(true); + }); + it('ignores key order within a compared field', () => { const drift = classifyDrift( { a: model({ cost: { input: 1, output: 2 } }) }, @@ -281,6 +290,17 @@ describe('validateCatalog', () => { expect(errors).toEqual([expect.stringContaining('a.cost.per_wish is not a known rate')]); }); + it('accepts an image output rate and holds it to the same rules as other rates', () => { + const priced = (outputImage) => + validateCatalog( + catalog({ a: model({ cost: { input: 2, output: 12, output_image: outputImage } }) }) + ); + + expect(priced(120)).toEqual([]); + expect(priced('120')).toEqual([expect.stringContaining('a.cost.output_image')]); + expect(priced(-1)).toEqual([expect.stringContaining('a.cost.output_image')]); + }); + it('rejects a malformed or duplicated tier descriptor', () => { const bad = validateCatalog( catalog({ diff --git a/src/components/pages/doc/ai-gateway-model-index/model-detail-data.js b/src/components/pages/doc/ai-gateway-model-index/model-detail-data.js index 479ff70cb38..2a825c2fa5b 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-detail-data.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-detail-data.js @@ -44,6 +44,9 @@ const getSections = (row) => { title: 'Released', id: 'released', value: row.releaseLabel }, { title: 'Input /M', id: 'input-m', value: row.costInputLabel }, { title: 'Output /M', id: 'output-m', value: row.costOutputLabel }, + ...(row.costOutputImageLabel + ? [{ title: 'Image output /M', id: 'image-output-m', value: row.costOutputImageLabel }] + : []), ]; const getModelDetailPageData = (row) => { diff --git a/src/components/pages/doc/ai-gateway-model-index/model-detail-data.test.js b/src/components/pages/doc/ai-gateway-model-index/model-detail-data.test.js index c361b36e4f9..25350f0254c 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-detail-data.test.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-detail-data.test.js @@ -36,6 +36,28 @@ describe('getModelDetailPageData', () => { ]); }); + it('adds the image output price after the text output price when the model has one', () => { + const { content, tableOfContents } = getModelDetailPageData({ + id: 'example-image-model', + name: 'Example Image Model', + labName: 'Example Lab', + providerName: 'Example Provider', + endpoints: [], + inputsLabel: 'text, image', + contextLabel: '66K', + releaseLabel: 'Nov 2025', + costInputLabel: '$2', + costOutputLabel: '$12', + costOutputImageLabel: '$120', + }); + + expect(content).toContain('## Output /M\n\n$12\n\n## Image output /M\n\n$120'); + expect(tableOfContents.slice(-2).map(({ title, id }) => ({ title, id }))).toEqual([ + { title: 'Output /M', id: 'output-m' }, + { title: 'Image output /M', id: 'image-output-m' }, + ]); + }); + // No Inputs, Context, or Output /M — those describe chat completion behavior, not a fixed // vector length, and there is no completion to charge for. it('reports Dimensions instead of the chat-shaped sections for an embedding model', () => { diff --git a/src/components/pages/doc/ai-gateway-model-index/model-index-client.jsx b/src/components/pages/doc/ai-gateway-model-index/model-index-client.jsx index f1d249ac769..685270eba50 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-index-client.jsx +++ b/src/components/pages/doc/ai-gateway-model-index/model-index-client.jsx @@ -727,6 +727,11 @@ const ModelIndexView = ({ rows, variant = 'docs', filters, setFilters }) => {