|
|
@@ -46,7 +46,7 @@ import {
|
|
|
useOpenRouterModelProviders,
|
|
|
OPENROUTER_DEFAULT_PROVIDER_NAME,
|
|
|
} from "@/components/ui/hooks/useOpenRouterModelProviders"
|
|
|
-
|
|
|
+import { useOpenRouterKeyInfo } from "@/components/ui/hooks/useOpenRouterKeyInfo"
|
|
|
import { MODELS_BY_PROVIDER, PROVIDERS, AWS_REGIONS, VERTEX_REGIONS } from "./constants"
|
|
|
import { VSCodeButtonLink } from "../common/VSCodeButtonLink"
|
|
|
import { ModelInfoView } from "./ModelInfoView"
|
|
|
@@ -57,6 +57,23 @@ import { ApiErrorMessage } from "./ApiErrorMessage"
|
|
|
import { ThinkingBudget } from "./ThinkingBudget"
|
|
|
import { R1FormatSetting } from "./R1FormatSetting"
|
|
|
|
|
|
+// Component to display OpenRouter API key balance
|
|
|
+const OpenRouterBalanceDisplay = ({ apiKey, baseUrl }: { apiKey: string; baseUrl?: string }) => {
|
|
|
+ const { data: keyInfo } = useOpenRouterKeyInfo(apiKey, baseUrl)
|
|
|
+
|
|
|
+ if (!keyInfo || !keyInfo.limit) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ const formattedBalance = (keyInfo.limit - keyInfo.usage).toFixed(2)
|
|
|
+
|
|
|
+ return (
|
|
|
+ <VSCodeLink href="https://openrouter.ai/settings/keys" className="text-vscode-foreground hover:underline">
|
|
|
+ ${formattedBalance}
|
|
|
+ </VSCodeLink>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
interface ApiOptionsProps {
|
|
|
uriScheme: string | undefined
|
|
|
apiConfiguration: ApiConfiguration
|
|
|
@@ -274,7 +291,15 @@ const ApiOptions = ({
|
|
|
onInput={handleInputChange("openRouterApiKey")}
|
|
|
placeholder={t("settings:placeholders.apiKey")}
|
|
|
className="w-full">
|
|
|
- <label className="block font-medium mb-1">{t("settings:providers.openRouterApiKey")}</label>
|
|
|
+ <div className="flex justify-between items-center mb-1">
|
|
|
+ <label className="block font-medium">{t("settings:providers.openRouterApiKey")}</label>
|
|
|
+ {apiConfiguration?.openRouterApiKey && (
|
|
|
+ <OpenRouterBalanceDisplay
|
|
|
+ apiKey={apiConfiguration.openRouterApiKey}
|
|
|
+ baseUrl={apiConfiguration.openRouterBaseUrl}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</VSCodeTextField>
|
|
|
<div className="text-sm text-vscode-descriptionForeground -mt-2">
|
|
|
{t("settings:providers.apiKeyStorageNotice")}
|