Skip to content

Commit e0a3740

Browse files
chrarnoldusdrakonenEamonNerbonne
authored
OpenRouter BYOK cost correction (#671)
Co-authored-by: Johan Otten <[email protected]> Co-authored-by: Eamon Nerbonne <[email protected]>
1 parent ce9c9c3 commit e0a3740

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/rotten-insects-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
OpenRouter bring-your-own-key models now have much more accurate cost estimates.

src/api/providers/openrouter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ interface CompletionUsage {
4848
}
4949
total_tokens?: number
5050
cost?: number
51+
is_byok?: boolean // kilocode_change
5152
}
5253

54+
const BYOK_COST_MULTIPLIER = 20 // kilocode_change
55+
5356
export class OpenRouterHandler extends BaseProvider implements SingleCompletionHandler {
5457
protected options: ApiHandlerOptions
5558
private client: OpenAI
@@ -169,7 +172,7 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
169172
// and how to best support it.
170173
// cacheReadTokens: lastUsage.prompt_tokens_details?.cached_tokens,
171174
reasoningTokens: lastUsage.completion_tokens_details?.reasoning_tokens,
172-
totalCost: lastUsage.cost || 0,
175+
totalCost: (lastUsage.is_byok ? BYOK_COST_MULTIPLIER : 1) * (lastUsage.cost || 0), // kilocode_change byok
173176
}
174177
}
175178
}

0 commit comments

Comments
 (0)