File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 11import { RooModelsResponseSchema } from "@roo-code/types"
22
33import type { ModelRecord } from "../../../shared/api"
4+ import { parseApiPrice } from "../../../shared/cost"
45
56import { DEFAULT_HEADERS } from "../constants"
67
@@ -71,10 +72,10 @@ export async function getRooModels(baseUrl: string, apiKey?: string): Promise<Mo
7172 const supportsImages = tags . includes ( "vision" )
7273
7374 // Parse pricing (API returns strings, convert to numbers)
74- const inputPrice = parseFloat ( pricing . input )
75- const outputPrice = parseFloat ( pricing . output )
76- const cacheReadPrice = pricing . input_cache_read ? parseFloat ( pricing . input_cache_read ) : undefined
77- const cacheWritePrice = pricing . input_cache_write ? parseFloat ( pricing . input_cache_write ) : undefined
75+ const inputPrice = parseApiPrice ( pricing . input )
76+ const outputPrice = parseApiPrice ( pricing . output )
77+ const cacheReadPrice = pricing . input_cache_read ? parseApiPrice ( pricing . input_cache_read ) : undefined
78+ const cacheWritePrice = pricing . input_cache_write ? parseApiPrice ( pricing . input_cache_write ) : undefined
7879
7980 models [ modelId ] = {
8081 maxTokens,
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ import { DEFAULT_HEADERS } from "./constants"
1212import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
1313import { getModels , flushModels , getModelsFromCache } from "../providers/fetchers/modelCache"
1414
15+ // Extend OpenAI's CompletionUsage to include Roo specific fields
16+ interface RooUsage extends OpenAI . CompletionUsage {
17+ cache_creation_input_tokens ?: number
18+ cost ?: number
19+ }
20+
1521export class RooHandler extends BaseOpenAiCompatibleProvider < string > {
1622 private authStateListener ?: ( state : { state : AuthState } ) => void
1723 private fetcherBaseURL : string
@@ -124,10 +130,14 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
124130 }
125131
126132 if ( chunk . usage ) {
133+ const usage = chunk . usage as RooUsage
127134 yield {
128135 type : "usage" ,
129- inputTokens : chunk . usage . prompt_tokens || 0 ,
130- outputTokens : chunk . usage . completion_tokens || 0 ,
136+ inputTokens : usage . prompt_tokens || 0 ,
137+ outputTokens : usage . completion_tokens || 0 ,
138+ cacheWriteTokens : usage . cache_creation_input_tokens ,
139+ cacheReadTokens : usage . prompt_tokens_details ?. cached_tokens ,
140+ totalCost : usage . cost ?? 0 ,
131141 }
132142 }
133143 }
You can’t perform that action at this time.
0 commit comments