Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/api/providers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
Loading