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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix: apply PR review feedback for Gemini CLI quota
Chris Staleyc5d9b5f51d36
diff --git a/open-sse/services/usage.ts b/open-sse/services/usage.tsindex fcd547e47b..e112332b11 100644--- a/open-sse/services/usage.ts+++ b/open-sse/services/usage.ts@@ -417,7 +417,7 @@ function inferGitHubPlanName(data: JsonRecord, premiumQuota: UsageQuota | null):// ── Gemini CLI subscription info cache ──────────────────────────────────────// Prevents duplicate loadCodeAssist calls within the same quota cycle.-// Key: truncated accessToken → { data, fetchedAt }+// Key: accessToken → { data, fetchedAt }const _geminiCliSubCache = new Map();const GEMINI_CLI_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes@@ -427,6 +427,10 @@ const GEMINI_CLI_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes* so this follows the same pattern as getAntigravityUsage().*/async function getGeminiUsage(accessToken, providerSpecificData?, connectionProjectId?) {+ if (!accessToken) {+ return { plan: "Free", message: "Gemini CLI access token not available." };+ }+try {const subscriptionInfo = await getGeminiCliSubscriptionInfoCached(accessToken);const projectId =@@ -452,6 +456,7 @@ async function getGeminiUsage(accessToken, providerSpecificData?, connectionProj"Content-Type": "application/json",},body: JSON.stringify({ project: projectId }),+ signal: AbortSignal.timeout(10000),});@@ -471,7 +476,7 @@ async function getGeminiUsage(accessToken, providerSpecificData?, connectionProjconst QUOTA_NORMALIZED_BASE = 1000;const total = QUOTA_NORMALIZED_BASE;const remaining = Math.round(total * remainingFraction);- const used = total - remaining;+ const used = Math.max(0, total - remaining);quotas[bucket.modelId] = {used,@@ -493,7 +498,7 @@ async function getGeminiUsage(accessToken, providerSpecificData?, connectionProj* Get Gemini CLI subscription info (cached, 5 min TTL)*/async function getGeminiCliSubscriptionInfoCached(accessToken) {- const cacheKey = accessToken.substring(0, 16);+ const cacheKey = accessToken;const cached = _geminiCliSubCache.get(cacheKey);if (cached && Date.now() - cached.fetchedAt < GEMINI_CLI_CACHE_TTL_MS) {diff --git a/src/app/api/providers/[id]/models/route.ts b/src/app/api/providers/[id]/models/route.tsindex 4a9f95a1e9..660076c6c6 100644--- a/src/app/api/providers/[id]/models/route.ts+++ b/src/app/api/providers/[id]/models/route.ts@@ -524,6 +524,7 @@ export async function GET("Content-Type": "application/json",},body: JSON.stringify({ project: projectId }),+ signal: AbortSignal.timeout(10000),});@@ -549,8 +550,9 @@ export async function GET(}));return buildResponse({ provider, connectionId, models });- } catch (err: any) {- console.log("[models] Gemini CLI model fetch error:", err.message);+ } 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 }