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

Merge branch 'main' into feat/codex-teamplan

diegosouzapw10793a7e6562
diff --cc open-sse/services/usage.ts
index 060f0d9cb7,1aea556d34..1f79f75848
--- a/open-sse/services/usage.ts
+++ b/open-sse/services/usage.ts
@@@ -511,52 -532,60 +511,74 @@@ async function getCodexUsage(accessToke
const data = await response.json();
- // Parse rate limit info
- const rateLimit = data.rate_limit || {};
- const primaryWindow = rateLimit.primary_window || {};
- const secondaryWindow = rateLimit.secondary_window || {};
-
- // Parse reset dates (reset_at is Unix timestamp in seconds, multiply by 1000 for ms)
- const sessionResetAt = parseResetTime(
- primaryWindow.reset_at ? primaryWindow.reset_at * 1000 : null
- );
- const weeklyResetAt = parseResetTime(
- secondaryWindow.reset_at ? secondaryWindow.reset_at * 1000 : null
- );
+ // Helper to get field with snake_case/camelCase fallback
+ const getField = (obj: any, snakeKey: string, camelKey: string) =>
+ obj?.[snakeKey] ?? obj?.[camelKey] ?? null;
+
+ // Parse rate limit info (supports both snake_case and camelCase)
+ const rateLimit = getField(data, "rate_limit", "rateLimit") || {};
+ const primaryWindow = getField(rateLimit, "primary_window", "primaryWindow") || {};
+ const secondaryWindow = getField(rateLimit, "secondary_window", "secondaryWindow") || {};
+
+ // Parse reset times (reset_at is Unix timestamp in seconds)
+ const parseWindowReset = (window: any) => {
+ const resetAt = getField(window, "reset_at", "resetAt");
+ const resetAfterSeconds = getField(window, "reset_after_seconds", "resetAfterSeconds");
+ if (resetAt) return parseResetTime(resetAt * 1000);
+ if (resetAfterSeconds) return parseResetTime(Date.now() + resetAfterSeconds * 1000);
+ return null;
+ };
- // Parse code review rate limit (3rd window — differs per plan: Plus/Pro/Team)
- const codeReviewRateLimit = data.code_review_rate_limit || {};
- const codeReviewWindow = codeReviewRateLimit.primary_window || {};
- const codeReviewResetAt = parseResetTime(
- codeReviewWindow.reset_at ? codeReviewWindow.reset_at * 1000 : null
- );
+ // Build quota windows
+ const quotas: Record<string, any> = {};
- const quotas: Record<string, any> = {
- session: {
- used: primaryWindow.used_percent || 0,
+ // Primary window (5-hour)
+ if (Object.keys(primaryWindow).length > 0) {
+ quotas.session = {
+ used: getField(primaryWindow, "used_percent", "usedPercent") || 0,
total: 100,
- remaining: 100 - (primaryWindow.used_percent || 0),
- resetAt: sessionResetAt,
+ remaining: 100 - (getField(primaryWindow, "used_percent", "usedPercent") || 0),
+ resetAt: parseWindowReset(primaryWindow),
unlimited: false,
- },
- weekly: {
- used: secondaryWindow.used_percent || 0,
+ };
+ }
+
+ // Secondary window (weekly)
+ if (Object.keys(secondaryWindow).length > 0) {
+ quotas.weekly = {
+ used: getField(secondaryWindow, "used_percent", "usedPercent") || 0,
total: 100,
- remaining: 100 - (secondaryWindow.used_percent || 0),
- resetAt: weeklyResetAt,
+ remaining: 100 - (getField(secondaryWindow, "used_percent", "usedPercent") || 0),
+ resetAt: parseWindowReset(secondaryWindow),
unlimited: false,
- },
- };
+ };
+ }
+
++ // Code review rate limit (3rd window — differs per plan: Plus/Pro/Team)
++ const codeReviewRateLimit =
++ getField(data, "code_review_rate_limit", "codeReviewRateLimit") || {};
++ const codeReviewWindow = getField(codeReviewRateLimit, "primary_window", "primaryWindow") || {};
+
+ // Only include code review quota if the API returned data for it
- if (
- codeReviewWindow.used_percent !== undefined ||
- codeReviewWindow.remaining_count !== undefined
- ) {
++ const codeReviewUsedPercent = getField(codeReviewWindow, "used_percent", "usedPercent");
++ const codeReviewRemainingCount = getField(
++ codeReviewWindow,
++ "remaining_count",
++ "remainingCount"
++ );
++ if (codeReviewUsedPercent !== null || codeReviewRemainingCount !== null) {
+ quotas.code_review = {
- used: codeReviewWindow.used_percent || 0,
++ used: codeReviewUsedPercent || 0,
+ total: 100,
- remaining: 100 - (codeReviewWindow.used_percent || 0),
- resetAt: codeReviewResetAt,
++ remaining: 100 - (codeReviewUsedPercent || 0),
++ resetAt: parseWindowReset(codeReviewWindow),
+ unlimited: false,
+ };
+ }
+
return {
- plan: data.plan_type || "unknown",
- limitReached: rateLimit.limit_reached || false,
+ plan: getField(data, "plan_type", "planType") || "unknown",
+ limitReached: getField(rateLimit, "limit_reached", "limitReached") || false,
quotas,
};
} catch (error) {