@@ -26,8 +26,8 @@ import { useStore } from '../store/useStore';
2626import { formatCurrency } from '../utils/formatNumber' ;
2727import { formatDateShort } from '../utils/formatDate' ;
2828import { ChartFrame } from '../components/shared/ChartFrame' ;
29- import { getAnalyticsCosts } from '../api/client' ;
30- import type { AnalyticsCostsResponse } from '../types' ;
29+ import { getAnalyticsCosts , getCostSummary , getCostByModel } from '../api/client' ;
30+ import type { AnalyticsCostsResponse , CostSummaryResponse , CostByModelResponse } from '../types' ;
3131import { BudgetProgressBar } from '../components/shared/BudgetProgressBar' ;
3232import { SpendSummary } from '../components/cost/SpendSummary' ;
3333import { ForecastChart } from '../components/cost/ForecastChart' ;
@@ -166,12 +166,20 @@ export default function CostPage() {
166166 const [ isLoading , setIsLoading ] = useState ( true ) ;
167167 const [ dataError , setDataError ] = useState < string | null > ( null ) ;
168168 const [ timeRange , setTimeRange ] = useState < TimeRange > ( '30d' ) ;
169+ const [ costSummary , setCostSummary ] = useState < CostSummaryResponse | null > ( null ) ;
170+ const [ costByModel , setCostByModel ] = useState < CostByModelResponse | null > ( null ) ;
169171 const sseConnected = useStore ( ( s ) => s . sseConnected ) ;
170172
171173 const fetchData = useCallback ( async ( ) => {
172174 try {
173- const data = await getAnalyticsCosts ( ) ;
174- setCostData ( data ) ;
175+ const [ data , summary , byModel ] = await Promise . allSettled ( [
176+ getAnalyticsCosts ( ) ,
177+ getCostSummary ( ) . catch ( ( ) => null ) ,
178+ getCostByModel ( ) . catch ( ( ) => null ) ,
179+ ] ) ;
180+ if ( data . status === 'fulfilled' ) setCostData ( data . value ) ;
181+ if ( summary . status === 'fulfilled' && summary . value ) setCostSummary ( summary . value ) ;
182+ if ( byModel . status === 'fulfilled' && byModel . value ) setCostByModel ( byModel . value ) ;
175183 setDataError ( null ) ;
176184 } catch ( err ) {
177185 setDataError ( err instanceof Error ? err . message : 'Failed to load cost data' ) ;
@@ -375,19 +383,24 @@ export default function CostPage() {
375383 < div className = "mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between" >
376384 < h2 className = "text-lg font-medium text-[var(--color-text-primary)]" >
377385 Cost Analytics
386+ { costSummary ?. burnRateUsdPerHour && costSummary . burnRateUsdPerHour > 0 && (
387+ < span className = "ml-3 text-sm font-normal text-[var(--color-accent-cyan)]" >
388+ { formatCurrency ( costSummary . burnRateUsdPerHour ) } /hr burn rate
389+ </ span >
390+ ) }
378391 </ h2 >
379392 < TimeRangePicker value = { timeRange } onChange = { setTimeRange } />
380393 </ div >
381394
382395 { /* Burn rate β full width */ }
383396 < div className = "mb-4" >
384- < BurnRateChart />
397+ < BurnRateChart data = { dailyData . map ( d => ( { date : d . date , cost : d . estimatedCostUsd } ) ) } />
385398 </ div >
386399
387400 { /* Token breakdown + Cost by model β side by side */ }
388401 < div className = "grid grid-cols-1 gap-4 lg:grid-cols-2" >
389402 < TokenBreakdownChart />
390- < CostByModelChart />
403+ < CostByModelChart data = { costByModel ?. models . map ( m => ( { model : m . model , cost : m . estimatedCostUsd } ) ) } />
391404 </ div >
392405 </ section >
393406
0 commit comments