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 }) => { {row.costOutputLabel} + {row.costOutputImageLabel && ( + + image {row.costOutputImageLabel} + + )} {row.openWeights ? 'Open weights' : '—'} diff --git a/src/components/pages/doc/ai-gateway-model-index/model-index-client.test.jsx b/src/components/pages/doc/ai-gateway-model-index/model-index-client.test.jsx index fe4dbd2bbf0..3860264f204 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-index-client.test.jsx +++ b/src/components/pages/doc/ai-gateway-model-index/model-index-client.test.jsx @@ -231,6 +231,23 @@ describe('ModelIndexClient', () => { expect(getVisibleModelNames()).toHaveLength(3); }); + it('shows the image output price under the text output price only for models that have one', () => { + const imageOutput = createRow({ + id: 'image-output-model', + name: 'Image output model', + costOutput: 12, + costOutputLabel: '$12', + costOutputImageLabel: '$120', + }); + render(); + + const row = (name) => screen.getByRole('link', { name }).closest('tr'); + + expect(row('Image output model')).toHaveTextContent('$12'); + expect(row('Image output model')).toHaveTextContent('image $120'); + expect(row('New image model')).not.toHaveTextContent('image $'); + }); + it('navigates to the model detail page when a row is clicked', () => { render(); diff --git a/src/components/pages/doc/ai-gateway-model-index/model-markdown.js b/src/components/pages/doc/ai-gateway-model-index/model-markdown.js index 86fe0de500a..1d21a995c90 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-markdown.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-markdown.js @@ -51,7 +51,11 @@ const renderModelTableRows = (rows) => escapeTableCell(row.releaseLabel), row.reasoning ? 'Yes' : '—', escapeTableCell(row.costInputLabel), - escapeTableCell(row.costOutputLabel), + escapeTableCell( + row.costOutputImageLabel + ? `${row.costOutputLabel} (image ${row.costOutputImageLabel})` + : row.costOutputLabel + ), escapeTableCell(row.endpoints.join(' · ') || '—'), row.openWeights ? 'Open weights' : '—', ].join(' | ') diff --git a/src/components/pages/doc/ai-gateway-model-index/model-markdown.test.js b/src/components/pages/doc/ai-gateway-model-index/model-markdown.test.js index aee9a4ed481..32987be98e7 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-markdown.test.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-markdown.test.js @@ -64,6 +64,20 @@ describe('AI Gateway model Markdown index', () => { ); }); + it('shows the image output price next to the text output price only when there is one', () => { + const markdown = renderAiGatewayModelIndex([ + createRow({ id: 'text-model', inputs: ['text'], isImageCapable: false }), + { + ...createRow({ id: 'image-output-model', inputs: ['text'], isImageCapable: false }), + costOutputLabel: '$12', + costOutputImageLabel: '$120', + }, + ]); + + expect(markdown).toContain('| $1 | $2 | openai/responses |'); + expect(markdown).toContain('| $1 | $12 (image $120) | openai/responses |'); + }); + it('gives embedding models their own section, out of Text and Other', () => { const embeddingRow = { ...createRow({ id: 'qwen3-embedding-0-6b', inputs: [], isImageCapable: false }), diff --git a/src/components/pages/doc/ai-gateway-model-index/model-rows.js b/src/components/pages/doc/ai-gateway-model-index/model-rows.js index c424d2e8d08..def2223c1b8 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-rows.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-rows.js @@ -111,6 +111,7 @@ const toRow = (model, capability) => { const contextWindow = model.limit?.context; const costInput = model.cost?.input; const costOutput = model.cost?.output; + const costOutputImage = model.cost?.output_image; return { id: model.id, name: model.name, @@ -127,6 +128,7 @@ const toRow = (model, capability) => { costOutput, costInputLabel: formatPrice(costInput), costOutputLabel: formatPrice(costOutput), + costOutputImageLabel: costOutputImage === undefined ? null : formatPrice(costOutputImage), knowledge: model.knowledge || null, releaseDate: model.release_date || null, releaseLabel: formatDate(model.release_date), diff --git a/src/components/pages/doc/ai-gateway-model-index/model-rows.test.js b/src/components/pages/doc/ai-gateway-model-index/model-rows.test.js index 50209e6f159..babe6dd809f 100644 --- a/src/components/pages/doc/ai-gateway-model-index/model-rows.test.js +++ b/src/components/pages/doc/ai-gateway-model-index/model-rows.test.js @@ -127,6 +127,25 @@ describe('AI Gateway model rows', () => { expect(row.costOutputLabel).toBe('—'); }); + it('labels a separately billed image output rate and leaves text-only models without one', () => { + const [row] = buildRows( + { + models: { + 'example-image': { + id: 'example-image', + name: 'Example Image', + cost: { input: 2, output: 12, output_image: 120 }, + }, + }, + }, + { models: [] } + ); + + expect(row.costOutputLabel).toBe('$12'); + expect(row.costOutputImageLabel).toBe('$120'); + expect(rows.find(({ id }) => id === 'gpt-5-4').costOutputImageLabel).toBeNull(); + }); + it('keeps sub-cent digits and reports a decision model context window', () => { const row = rows.find(({ id }) => id === 'typesafeai-jev-1-14-0');