@@ -46,7 +46,7 @@ import {
4646 useOpenRouterModelProviders ,
4747 OPENROUTER_DEFAULT_PROVIDER_NAME ,
4848} from "@/components/ui/hooks/useOpenRouterModelProviders"
49-
49+ import { useOpenRouterKeyInfo } from "@/components/ui/hooks/useOpenRouterKeyInfo"
5050import { MODELS_BY_PROVIDER , PROVIDERS , AWS_REGIONS , VERTEX_REGIONS } from "./constants"
5151import { VSCodeButtonLink } from "../common/VSCodeButtonLink"
5252import { ModelInfoView } from "./ModelInfoView"
@@ -57,6 +57,23 @@ import { ApiErrorMessage } from "./ApiErrorMessage"
5757import { ThinkingBudget } from "./ThinkingBudget"
5858import { R1FormatSetting } from "./R1FormatSetting"
5959
60+ // Component to display OpenRouter API key balance
61+ const OpenRouterBalanceDisplay = ( { apiKey, baseUrl } : { apiKey : string ; baseUrl ?: string } ) => {
62+ const { data : keyInfo } = useOpenRouterKeyInfo ( apiKey , baseUrl )
63+
64+ if ( ! keyInfo || ! keyInfo . limit ) {
65+ return null
66+ }
67+
68+ const formattedBalance = ( keyInfo . limit - keyInfo . usage ) . toFixed ( 2 )
69+
70+ return (
71+ < VSCodeLink href = "https://openrouter.ai/settings/keys" className = "text-vscode-foreground hover:underline" >
72+ ${ formattedBalance }
73+ </ VSCodeLink >
74+ )
75+ }
76+
6077interface ApiOptionsProps {
6178 uriScheme : string | undefined
6279 apiConfiguration : ApiConfiguration
@@ -274,7 +291,15 @@ const ApiOptions = ({
274291 onInput = { handleInputChange ( "openRouterApiKey" ) }
275292 placeholder = { t ( "settings:placeholders.apiKey" ) }
276293 className = "w-full" >
277- < label className = "block font-medium mb-1" > { t ( "settings:providers.openRouterApiKey" ) } </ label >
294+ < div className = "flex justify-between items-center mb-1" >
295+ < label className = "block font-medium" > { t ( "settings:providers.openRouterApiKey" ) } </ label >
296+ { apiConfiguration ?. openRouterApiKey && (
297+ < OpenRouterBalanceDisplay
298+ apiKey = { apiConfiguration . openRouterApiKey }
299+ baseUrl = { apiConfiguration . openRouterBaseUrl }
300+ />
301+ ) }
302+ </ div >
278303 </ VSCodeTextField >
279304 < div className = "text-sm text-vscode-descriptionForeground -mt-2" >
280305 { t ( "settings:providers.apiKeyStorageNotice" ) }
0 commit comments