Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

Resolve merge conflicts with main natively built Prompt Cache UI

diegosouzapw76e135077ba1
diff --cc open-sse/services/usage.ts
index c1f1114a2e,e112332b11..43024f627d
--- a/open-sse/services/usage.ts
+++ b/open-sse/services/usage.ts
@@@ -435,15 -461,83 +461,80 @@@ async function getGeminiUsage(accessTok
);
if (!response.ok) {
- // Quota API may not be accessible, return generic message
- return {
- message: "Gemini CLI uses Google Cloud quotas. Check Google Cloud Console for details.",
- };
+ return { plan, message: `Gemini CLI quota error (${response.status}).` };
}
- return { message: "Gemini CLI connected. Usage tracked via Google Cloud Console." };
+ const data = await response.json();
+ const quotas: Record<string, UsageQuota> = {};
+
+ if (Array.isArray(data.buckets)) {
+ for (const bucket of data.buckets) {
+ if (!bucket.modelId || bucket.remainingFraction == null) continue;
+
+ const remainingFraction = toNumber(bucket.remainingFraction, 0);
+ const remainingPercentage = remainingFraction * 100;
+ const QUOTA_NORMALIZED_BASE = 1000;
+ const total = QUOTA_NORMALIZED_BASE;
+ const remaining = Math.round(total * remainingFraction);
+ const used = Math.max(0, total - remaining);
+
+ quotas[bucket.modelId] = {
+ used,
+ total,
+ resetAt: parseResetTime(bucket.resetTime),
+ remainingPercentage,
+ unlimited: false,
+ };
+ }
+ }
+
+ return { plan, quotas };
} catch (error) {
- return { message: "Unable to fetch Gemini usage. Check Google Cloud Console." };
+ return { message: `Gemini CLI error: ${(error as Error).message}` };
+ }
+ }
+
+ /**
+ * Get Gemini CLI subscription info (cached, 5 min TTL)
+ */
+ async function getGeminiCliSubscriptionInfoCached(accessToken) {
+ const cacheKey = accessToken;
+ const cached = _geminiCliSubCache.get(cacheKey);
+
+ if (cached && Date.now() - cached.fetchedAt < GEMINI_CLI_CACHE_TTL_MS) {
+ return cached.data;
+ }
+
+ const data = await getGeminiCliSubscriptionInfo(accessToken);
+ _geminiCliSubCache.set(cacheKey, { data, fetchedAt: Date.now() });
+ return data;
+ }
+
+ /**
+ * Get Gemini CLI subscription info using correct headers.
+ */
+ async function getGeminiCliSubscriptionInfo(accessToken) {
+ try {
- const response = await fetch(
- "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
- {
- method: "POST",
- headers: {
- Authorization: `Bearer ${accessToken}`,
- "Content-Type": "application/json",
++ const response = await fetch("https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist", {
++ method: "POST",
++ headers: {
++ Authorization: `Bearer ${accessToken}`,
++ "Content-Type": "application/json",
++ },
++ body: JSON.stringify({
++ metadata: {
++ ideType: "IDE_UNSPECIFIED",
++ platform: "PLATFORM_UNSPECIFIED",
++ pluginType: "GEMINI",
+ },
- body: JSON.stringify({
- metadata: {
- ideType: "IDE_UNSPECIFIED",
- platform: "PLATFORM_UNSPECIFIED",
- pluginType: "GEMINI",
- },
- }),
- }
- );
++ }),
++ });
+
+ if (!response.ok) return null;
+
+ return await response.json();
+ } catch {
+ return null;
}
}
diff --cc src/app/(dashboard)/dashboard/providers/[id]/page.tsx
index 66488b657e,ca1a3a1f4b..c7fd8c35eb
--- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx
+++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx
@@@ -989,26 -987,7 +987,6 @@@ export default function ProviderDetailP
}
}, [loading, connections, loadConnProxies]);
- // Auto-open Add Connection modal when no connections exist (better UX)
- // Only fires once on initial load, not on HMR remounts or after user dismissal
- useEffect(() => {
- if (
- !loading &&
- connections.length === 0 &&
- providerInfo &&
- !isCompatible &&
- !hasAutoOpened.current &&
- !userDismissed.current
- ) {
- hasAutoOpened.current = true;
- if (isOAuth) {
- setShowOAuthModal(true);
- } else {
- setShowAddApiKeyModal(true);
- }
- }
- }, [loading]); // eslint-disable-line react-hooks/exhaustive-deps
--
const handleSetAlias = async (modelId, alias, providerAliasOverride = providerAlias) => {
const fullModel = `${providerAliasOverride}/${modelId}`;
try {
@@@ -1490,7 -1469,7 +1468,10 @@@
logs: [
t("foundModelsStartingImport", { count: newModels.length }),
...(newModels.length < fetchedModels.length
-- ? [t("skippingExistingModels", { count: fetchedModels.length - newModels.length }) || `Skipping ${fetchedModels.length - newModels.length} existing models`]
++ ? [
++ t("skippingExistingModels", { count: fetchedModels.length - newModels.length }) ||
++ `Skipping ${fetchedModels.length - newModels.length} existing models`,
++ ]
: []),
],
}));
diff --cc src/app/(dashboard)/dashboard/settings/page.tsx
index 445964dc08,9d0b261022..a6abd5e861
--- a/src/app/(dashboard)/dashboard/settings/page.tsx
+++ b/src/app/(dashboard)/dashboard/settings/page.tsx
@@@ -16,6 -16,9 +16,7 @@@ import CodexServiceTierTab from "./comp
import SystemPromptTab from "./components/SystemPromptTab";
import ModelAliasesTab from "./components/ModelAliasesTab";
import BackgroundDegradationTab from "./components/BackgroundDegradationTab";
-
-import CacheStatsCard from "./components/CacheStatsCard";
+ import CacheSettingsTab from "./components/CacheSettingsTab";
import ResilienceTab from "./components/ResilienceTab";
const tabs = [
@@@ -86,6 -89,8 +87,7 @@@ export default function SettingsPage()
<ThinkingBudgetTab />
<CodexServiceTierTab />
<SystemPromptTab />
- <CacheStatsCard />
+ <CacheSettingsTab />
</div>
)}
diff --cc src/app/api/providers/[id]/models/route.ts
index ef8a8d1a36,660076c6c6..d7e80d59a1
--- a/src/app/api/providers/[id]/models/route.ts
+++ b/src/app/api/providers/[id]/models/route.ts
@@@ -505,6 -493,73 +493,68 @@@ export async function GET
return buildResponse({ provider, connectionId, models });
}
+ if (provider === "gemini-cli") {
+ // Gemini CLI doesn't have a /models endpoint. Instead, query the quota
+ // endpoint to discover available models from the quota buckets.
+ if (!accessToken) {
+ return NextResponse.json(
+ { error: "No access token for Gemini CLI. Please reconnect OAuth." },
+ { status: 400 }
+ );
+ }
+
+ const psd = asRecord(connection.providerSpecificData);
- const projectId =
- connection.projectId || psd.projectId || null;
++ const projectId = connection.projectId || psd.projectId || null;
+
+ if (!projectId) {
+ return NextResponse.json(
+ { error: "Gemini CLI project ID not available. Please reconnect OAuth." },
+ { status: 400 }
+ );
+ }
+
+ try {
+ const quotaRes = await fetch(
+ "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota",
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ project: projectId }),
+ signal: AbortSignal.timeout(10000),
+ }
+ );
+
+ if (!quotaRes.ok) {
+ const errText = await quotaRes.text();
+ console.log(`[models] Gemini CLI quota fetch failed (${quotaRes.status}):`, errText);
+ return NextResponse.json(
+ { error: `Failed to fetch Gemini CLI models: ${quotaRes.status}` },
+ { status: quotaRes.status }
+ );
+ }
+
+ const quotaData = await quotaRes.json();
- const buckets: Array<{ modelId?: string; tokenType?: string }> =
- quotaData.buckets || [];
++ const buckets: Array<{ modelId?: string; tokenType?: string }> = quotaData.buckets || [];
+
+ const models = buckets
+ .filter((b) => b.modelId)
+ .map((b) => ({
+ id: b.modelId,
+ name: b.modelId,
+ owned_by: "google",
+ }));
+
+ return buildResponse({ provider, connectionId, models });
+ } catch (err: unknown) {
+ const msg = err instanceof Error ? err.message : String(err);
+ console.log("[models] Gemini CLI model fetch error:", msg);
- return NextResponse.json(
- { error: "Failed to fetch Gemini CLI models" },
- { status: 500 }
- );
++ return NextResponse.json({ error: "Failed to fetch Gemini CLI models" }, { status: 500 });
+ }
+ }
+
if (isAnthropicCompatibleProvider(provider)) {
let baseUrl = getProviderBaseUrl(connection.providerSpecificData);
if (!baseUrl) {