77import { getTranslations } from 'next-intl/server'
88import { cache } from 'react'
99import type { Locale } from '@/i18n/config'
10+ import { getPrimaryTokenPricingOffer , hasCurrentSingleTierPricing } from '@/lib/model-pricing'
11+ import type { ManifestTokenPricing , ModelLifecycle } from '@/types/manifests'
1012import { SITE_CONFIG } from '../config'
1113import {
1214 type ArticleSchemaOptions ,
@@ -100,11 +102,8 @@ export interface ModelData {
100102 vendor : string
101103 vendorUrl ?: string
102104 websiteUrl ?: string
103- tokenPricing ?: {
104- input ?: number
105- output ?: number
106- cache ?: number
107- }
105+ lifecycle ?: ModelLifecycle
106+ tokenPricing ?: ManifestTokenPricing
108107}
109108
110109/**
@@ -123,21 +122,28 @@ export const generateModelDetailSchema = cache(
123122 async ( options : ModelDetailSchemaOptions ) : Promise < SchemaProduct > => {
124123 const { model } = options
125124
126- // Transform token pricing to pricing tiers
125+ // Only publish unambiguous current, single-tier prices as Schema.org offers.
127126 const pricing : PricingTierData [ ] = [ ]
128- if ( model . tokenPricing ?. input ) {
127+ const offer = model . tokenPricing ? getPrimaryTokenPricingOffer ( model . tokenPricing ) : null
128+ const rates =
129+ model . lifecycle !== 'deprecated' &&
130+ model . tokenPricing &&
131+ hasCurrentSingleTierPricing ( model . tokenPricing )
132+ ? offer ?. tiers [ 0 ] ?. rates
133+ : null
134+ if ( offer && rates ?. input !== null && rates ?. input !== undefined ) {
129135 pricing . push ( {
130136 name : 'Input Tokens' ,
131- value : model . tokenPricing . input ,
132- currency : 'USD' ,
137+ value : rates . input ,
138+ currency : offer . currency ,
133139 per : 'million tokens' ,
134140 } )
135141 }
136- if ( model . tokenPricing ?. output ) {
142+ if ( offer && rates ?. output !== null && rates ?. output !== undefined ) {
137143 pricing . push ( {
138144 name : 'Output Tokens' ,
139- value : model . tokenPricing . output ,
140- currency : 'USD' ,
145+ value : rates . output ,
146+ currency : offer . currency ,
141147 per : 'million tokens' ,
142148 } )
143149 }
0 commit comments