diff --git a/src/api/providers/openrouter.ts b/src/api/providers/openrouter.ts index 31300b868b..26019ce34a 100644 --- a/src/api/providers/openrouter.ts +++ b/src/api/providers/openrouter.ts @@ -48,8 +48,13 @@ interface CompletionUsage { } total_tokens?: number cost?: number + is_byok?: boolean } +// with bring your own key, OpenRouter charges 5% of what it normally would: https://openrouter.ai/docs/use-cases/byok +// so we multiply the cost reported by OpenRouter to get an estimate of what the request actually cost +const BYOK_COST_MULTIPLIER = 20 + export class OpenRouterHandler extends BaseProvider implements SingleCompletionHandler { protected options: ApiHandlerOptions private client: OpenAI @@ -164,7 +169,7 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH // and how to best support it. // cacheReadTokens: lastUsage.prompt_tokens_details?.cached_tokens, reasoningTokens: lastUsage.completion_tokens_details?.reasoning_tokens, - totalCost: lastUsage.cost || 0, + totalCost: (lastUsage.is_byok ? BYOK_COST_MULTIPLIER : 1) * (lastUsage.cost || 0), } } }