Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/lib/ai-gateway-models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [];
Expand Down
8 changes: 8 additions & 0 deletions scripts/lib/ai-gateway-models.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 10 additions & 1 deletion scripts/lib/models-catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 20 additions & 0 deletions scripts/lib/models-catalog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }) },
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,11 @@ const ModelIndexView = ({ rows, variant = 'docs', filters, setFilters }) => {
</td>
<td className="py-4! pl-4! text-left! font-mono text-[.8125rem]! text-gray-new-30 dark:text-gray-new-80">
{row.costOutputLabel}
{row.costOutputImageLabel && (
<span className="mt-1 block text-xs leading-tight text-gray-new-40 dark:text-gray-new-60">
<span className="font-sans">image</span> {row.costOutputImageLabel}
</span>
)}
</td>
<td className="pr-4! text-left! text-[.8125rem]! whitespace-nowrap text-gray-new-40 dark:text-gray-new-60">
{row.openWeights ? 'Open weights' : '—'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<ModelIndexClient rows={[rows[0], imageOutput]} variant="landing" />);

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(<ModelIndexClient rows={rows} variant="landing" />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(' | ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Loading