feat(usage): track GPT-5.3-Codex-Spark quota windows
Extract Spark rate limit windows from the Codex usage response and expose them as spark_session/spark_weekly quotas, reusing the existing prefix mechanism. Map codex quota types to readable dashboard labels. Fixes #3431
This commit is contained in:
@@ -80,6 +80,23 @@ function getCodexReviewRateLimit(data) {
|
|||||||
}) || null;
|
}) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCodexSparkRateLimit(data) {
|
||||||
|
if (data.spark_rate_limit || data.gpt_5_3_codex_spark_rate_limit) {
|
||||||
|
return data.spark_rate_limit || data.gpt_5_3_codex_spark_rate_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
const byLimitId = data.rate_limits_by_limit_id;
|
||||||
|
if (byLimitId && typeof byLimitId === "object" && !Array.isArray(byLimitId)) {
|
||||||
|
return byLimitId["gpt-5.3-codex-spark"] || byLimitId.gpt_5_3_codex_spark || byLimitId.spark || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const additional = Array.isArray(data.additional_rate_limits) ? data.additional_rate_limits : [];
|
||||||
|
return additional.find((entry) => {
|
||||||
|
const id = String(entry?.limit_name || entry?.metered_feature || entry?.id || "").toLowerCase();
|
||||||
|
return id.includes("spark") || id.includes("5.3-codex-spark");
|
||||||
|
}) || null;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCodexUsage(accessToken, proxyOptions = null) {
|
export async function getCodexUsage(accessToken, proxyOptions = null) {
|
||||||
try {
|
try {
|
||||||
const response = await proxyAwareFetch(CODEX_CONFIG.usageUrl, {
|
const response = await proxyAwareFetch(CODEX_CONFIG.usageUrl, {
|
||||||
@@ -97,16 +114,19 @@ export async function getCodexUsage(accessToken, proxyOptions = null) {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const normalRateLimit = data.rate_limit || data.rate_limits || data.rate_limits_by_limit_id?.codex || {};
|
const normalRateLimit = data.rate_limit || data.rate_limits || data.rate_limits_by_limit_id?.codex || {};
|
||||||
const reviewRateLimit = getCodexReviewRateLimit(data);
|
const reviewRateLimit = getCodexReviewRateLimit(data);
|
||||||
|
const sparkRateLimit = getCodexSparkRateLimit(data);
|
||||||
const availableResetCredits = Math.max(0, toFiniteNumber(data.rate_limit_reset_credits?.available_count, 0));
|
const availableResetCredits = Math.max(0, toFiniteNumber(data.rate_limit_reset_credits?.available_count, 0));
|
||||||
const quotas = {};
|
const quotas = {};
|
||||||
|
|
||||||
appendCodexQuotaWindows(quotas, "", normalRateLimit);
|
appendCodexQuotaWindows(quotas, "", normalRateLimit);
|
||||||
appendCodexQuotaWindows(quotas, "review", reviewRateLimit);
|
appendCodexQuotaWindows(quotas, "review", reviewRateLimit);
|
||||||
|
appendCodexQuotaWindows(quotas, "spark", sparkRateLimit);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
plan: data.plan_type || data.summary?.plan || "unknown",
|
plan: data.plan_type || data.summary?.plan || "unknown",
|
||||||
limitReached: getCodexRateLimitBody(normalRateLimit)?.limit_reached || false,
|
limitReached: getCodexRateLimitBody(normalRateLimit)?.limit_reached || false,
|
||||||
reviewLimitReached: getCodexRateLimitBody(reviewRateLimit)?.limit_reached || false,
|
reviewLimitReached: getCodexRateLimitBody(reviewRateLimit)?.limit_reached || false,
|
||||||
|
sparkLimitReached: getCodexRateLimitBody(sparkRateLimit)?.limit_reached || false,
|
||||||
resetCredits: { availableCount: availableResetCredits },
|
resetCredits: { availableCount: availableResetCredits },
|
||||||
quotas,
|
quotas,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -379,8 +379,17 @@ export function parseQuotaData(provider, data) {
|
|||||||
case "codex":
|
case "codex":
|
||||||
if (data.quotas) {
|
if (data.quotas) {
|
||||||
Object.entries(data.quotas).forEach(([quotaType, quota]) => {
|
Object.entries(data.quotas).forEach(([quotaType, quota]) => {
|
||||||
|
let displayName = quotaType;
|
||||||
|
if (quotaType === "spark_session") displayName = "Spark (5h)";
|
||||||
|
else if (quotaType === "spark_weekly") displayName = "Spark (Weekly)";
|
||||||
|
else if (quotaType === "session") displayName = "5h";
|
||||||
|
else if (quotaType === "weekly") displayName = "Weekly";
|
||||||
|
else if (quotaType === "review_session") displayName = "Review (5h)";
|
||||||
|
else if (quotaType === "review_weekly") displayName = "Review (Weekly)";
|
||||||
|
|
||||||
normalizedQuotas.push({
|
normalizedQuotas.push({
|
||||||
name: quotaType,
|
name: displayName,
|
||||||
|
quotaType,
|
||||||
used: quota.used || 0,
|
used: quota.used || 0,
|
||||||
total: quota.total || 0,
|
total: quota.total || 0,
|
||||||
remaining: quota.remaining,
|
remaining: quota.remaining,
|
||||||
|
|||||||
37
tests/unit/codex-spark-quota-tracking.test.js
Normal file
37
tests/unit/codex-spark-quota-tracking.test.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { parseQuotaData } from "@/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js";
|
||||||
|
|
||||||
|
describe("Codex Spark Quota Tracking (#3431)", () => {
|
||||||
|
it("correctly normalizes spark_session and spark_weekly quotas with display labels", () => {
|
||||||
|
const mockCodexUsage = {
|
||||||
|
plan: "team",
|
||||||
|
quotas: {
|
||||||
|
session: { used: 20, total: 100, remaining: 80, resetAt: "2026-08-22T05:00:00.000Z" },
|
||||||
|
weekly: { used: 40, total: 100, remaining: 60, resetAt: "2026-08-28T05:00:00.000Z" },
|
||||||
|
review_session: { used: 0, total: 100, remaining: 100, resetAt: "2026-08-22T05:00:00.000Z" },
|
||||||
|
spark_session: { used: 12, total: 100, remaining: 88, resetAt: "2026-08-22T05:00:00.000Z" },
|
||||||
|
spark_weekly: { used: 25, total: 100, remaining: 75, resetAt: "2026-08-28T05:00:00.000Z" },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const parsed = parseQuotaData("codex", mockCodexUsage);
|
||||||
|
|
||||||
|
const sparkSession = parsed.find((q) => q.name === "Spark (5h)");
|
||||||
|
const sparkWeekly = parsed.find((q) => q.name === "Spark (Weekly)");
|
||||||
|
const session = parsed.find((q) => q.name === "5h");
|
||||||
|
const weekly = parsed.find((q) => q.name === "Weekly");
|
||||||
|
|
||||||
|
expect(sparkSession).toBeDefined();
|
||||||
|
expect(sparkSession.used).toBe(12);
|
||||||
|
expect(sparkSession.remaining).toBe(88);
|
||||||
|
|
||||||
|
expect(sparkWeekly).toBeDefined();
|
||||||
|
expect(sparkWeekly.used).toBe(25);
|
||||||
|
expect(sparkWeekly.remaining).toBe(75);
|
||||||
|
|
||||||
|
expect(session).toBeDefined();
|
||||||
|
expect(session.used).toBe(20);
|
||||||
|
expect(weekly).toBeDefined();
|
||||||
|
expect(weekly.used).toBe(40);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user