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
Merge branch 'pr-2019' into release/v3.8.0
diegosouzapw7e13bd36f542
diff --cc open-sse/services/usage.tsindex 8424b89af2,a10e8ee746..b55959ddd6--- a/open-sse/services/usage.ts+++ b/open-sse/services/usage.ts@@@ -130,32 -116,6 +130,38 @@@ function toNumber(value: unknown, fallbreturn Number.isFinite(parsed) ? parsed : fallback;}+function toPercentage(value: unknown): number {+ return Math.max(0, Math.min(100, toNumber(value, 0)));+}++function toTitleCase(value: string): string {+ return value+ .trim()+ .split(/[\s_-]+/)+ .filter(Boolean)+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())+ .join(" ");+}++function getGlmTokenQuotaName(+ limit: JsonRecord,+ existingQuotas: Record<string, UsageQuota>+): string {+ const unit = toNumber(limit.unit, 0);+ const number = toNumber(limit.number, 0);++ if (unit === 3 && number === 5) return "session";+ if ((unit === 4 && number === 7) || (unit === 3 && number >= 24 * 7)) return "weekly";++ return existingQuotas.session ? "weekly" : "session";+}+++function getGlmQuotaDisplayName(quotaName: string): string {++ if (quotaName === "session") return "5 Hours Quota";++ if (quotaName === "weekly") return "Weekly Quota";++ return quotaName;++}++function getFieldValue(source: unknown, snakeKey: string, camelKey: string): unknown {const obj = toRecord(source);return obj[snakeKey] ?? obj[camelKey] ?? null;@@@ -620,61 -576,27 +626,68 @@@ async function getGlmUsage(apiKey: strifor (const limit of limits) {const src = toRecord(limit);- const label = getGlmQuotaLabel(src.type, src.unit);- if (!label) continue;-- const usedPercent = toNumber(src.percentage, 0);+ const type = String(src.type || "").toUpperCase();const resetMs = toNumber(src.nextResetTime, 0);- const remaining = Math.max(0, 100 - usedPercent);+ const resetAt = resetMs > 0 ? new Date(resetMs).toISOString() : null;++ if (type === "TOKENS_LIMIT") {+ const quotaName = getGlmTokenQuotaName(src, quotas);+ const usedPercent = toPercentage(src.percentage);+ const remaining = Math.max(0, 100 - usedPercent);++ quotas[quotaName] = {+ used: usedPercent,+ total: 100,+ remaining,+ remainingPercentage: remaining,+ resetAt,++ displayName: getGlmQuotaDisplayName(quotaName),++ details: Array.isArray(src.models)++ ? src.models.map((m: any) => ({++ name: String(m.model || ""),++ used: toNumber(m.percentage, 0),++ }))++ : [],+ unlimited: false,+ };+ continue;+ }- quotas[label] = {- used: usedPercent,- total: 100,- remaining,- remainingPercentage: remaining,- resetAt: resetMs > 0 ? new Date(resetMs).toISOString() : null,- unlimited: false,- };+ if (type === "TIME_LIMIT") {+ const total = toNumber(src.usage, toNumber(src.total, 0));+ const remaining = toNumber(src.remaining, Math.max(0, 100 - toPercentage(src.percentage)));+ const used = toNumber(src.currentValue, Math.max(0, total - remaining));+ const remainingPercentage =+ total > 0 ? Math.max(0, Math.min(100, Math.round((remaining / total) * 100))) : 0;++ quotas["mcp_monthly"] = {+ used,+ total,+ remaining,+ remainingPercentage,+ resetAt,+ unlimited: false,+ displayName: "Monthly",+ details: Array.isArray(src.usageDetails)+ ? src.usageDetails.map((item) => {+ const detail = toRecord(item);+ return {+ name: String(detail.modelCode || detail.name || "usage"),+ used: toNumber(detail.usage, 0),+ };+ })+ : undefined,+ };+ }}- const levelRaw = typeof data.level === "string" ? data.level : "";- const plan = levelRaw- ? levelRaw.charAt(0).toUpperCase() + levelRaw.slice(1).toLowerCase()- : "Unknown";+ const levelRaw =+ typeof data.planName === "string"+ ? data.planName+ : typeof data.level === "string"+ ? data.level+ : "";+ const plan = levelRaw ? toTitleCase(levelRaw.replace(/\s*plan$/i, "")) : null;return { plan, quotas: orderGlmQuotas(quotas) };}@@@ -875,12 -748,9 +888,13 @@@ export async function getUsageForProvidcase "qoder":return await getQoderUsage(accessToken);case "glm":+ case "glm-cn":+ case "zai":case "glmt":- return await getGlmUsage(apiKey, providerSpecificData);+ return await getGlmUsage(apiKey, {+ ...(providerSpecificData || {}),+ ...(provider === "glm-cn" ? { apiRegion: "china" } : {}),+ });case "minimax":case "minimax-cn":return await getMiniMaxUsage(apiKey, provider);diff --cc src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsxindex 615dd51c61,8e3c6b4288..6851c621e3--- a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx+++ b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx@@@ -22,18 -22,13 +22,23 @@@ const QUOTA_LABEL_MAP: Record<string, sagentic_request_freetrial: "Agentic (Trial)",credits: "AI Credits",models: "Models",+ mcp_monthly: "Monthly",+ "search-prime": "Web Search",+ "web-reader": "Web Reader",+ zread: "Zread",+ "5 Hours Quota": "5 Hours",+ "Weekly Quota": "Weekly",+ "Monthly Tools": "Monthly Tools",+ tokens: "Tokens",+ time_limit: "Time Limit",};+const GLM_QUOTA_ORDER: Record<string, number> = {+ session: 0,+ weekly: 1,+ mcp_monthly: 2,+};+function toRecord(value: unknown): Record<string, unknown> {return value && typeof value === "object" && !Array.isArray(value)? (value as Record<string, unknown>)diff --cc src/app/api/usage/analytics/route.tsindex e3fada7b03,004fe0d967..fc76fbce7b--- a/src/app/api/usage/analytics/route.ts+++ b/src/app/api/usage/analytics/route.ts@@@ -555,6 -537,6 +555,7 @@@ export async function GET(request: RequCOALESCE(NULLIF(service_tier, ''), 'standard') as serviceTier,LOWER(provider) as provider,LOWER(model) as model,++ COALESCE(NULLIF(service_tier, ''), 'standard') as serviceTier,COUNT(*) as requests,COALESCE(SUM(tokens_input), 0) as promptTokens,COALESCE(SUM(tokens_output), 0) as completionTokens,@@@ -563,6 -545,6 +564,7 @@@COALESCE(SUM(tokens_reasoning), 0) as reasoningTokens,COALESCE(SUM(tokens_input + tokens_output), 0) as totalTokensFROM usage_history++${whereClause}GROUP BY serviceTier, LOWER(provider), LOWER(model)`diff --cc src/lib/usage/providerLimits.tsindex df189ceb5a,80c3b31e17..11081b6332--- a/src/lib/usage/providerLimits.ts+++ b/src/lib/usage/providerLimits.ts@@@ -46,7 -45,7 +46,8 @@@ interface ProviderConnectionLikeconst PROVIDER_LIMITS_APIKEY_PROVIDERS = new Set(["glm",+ "glm-cn",+ "zai","glmt","minimax","minimax-cn",diff --cc src/shared/constants/providers.tsindex 72064f737b,ee49035bef..ef53efc4b1--- a/src/shared/constants/providers.ts+++ b/src/shared/constants/providers.ts@@@ -1981,7 -1840,7 +1981,8 @@@ export const USAGE_SUPPORTED_PROVIDERS"claude","kimi-coding","glm",+ "glm-cn",+ "zai","glmt","minimax","minimax-cn",