Skip to content

Commit 1a9e7ca

Browse files
authored
Handle Roo provider pricing correctly (#8802)
1 parent 485b551 commit 1a9e7ca

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/api/providers/fetchers/roo.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RooModelsResponseSchema } from "@roo-code/types"
22

33
import type { ModelRecord } from "../../../shared/api"
4+
import { parseApiPrice } from "../../../shared/cost"
45

56
import { 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,

src/api/providers/roo.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import { DEFAULT_HEADERS } from "./constants"
1212
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
1313
import { 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+
1521
export 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
}

0 commit comments

Comments
 (0)