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;
|
||||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
const response = await proxyAwareFetch(CODEX_CONFIG.usageUrl, {
|
||||
@@ -97,16 +114,19 @@ export async function getCodexUsage(accessToken, proxyOptions = null) {
|
||||
const data = await response.json();
|
||||
const normalRateLimit = data.rate_limit || data.rate_limits || data.rate_limits_by_limit_id?.codex || {};
|
||||
const reviewRateLimit = getCodexReviewRateLimit(data);
|
||||
const sparkRateLimit = getCodexSparkRateLimit(data);
|
||||
const availableResetCredits = Math.max(0, toFiniteNumber(data.rate_limit_reset_credits?.available_count, 0));
|
||||
const quotas = {};
|
||||
|
||||
appendCodexQuotaWindows(quotas, "", normalRateLimit);
|
||||
appendCodexQuotaWindows(quotas, "review", reviewRateLimit);
|
||||
appendCodexQuotaWindows(quotas, "spark", sparkRateLimit);
|
||||
|
||||
return {
|
||||
plan: data.plan_type || data.summary?.plan || "unknown",
|
||||
limitReached: getCodexRateLimitBody(normalRateLimit)?.limit_reached || false,
|
||||
reviewLimitReached: getCodexRateLimitBody(reviewRateLimit)?.limit_reached || false,
|
||||
sparkLimitReached: getCodexRateLimitBody(sparkRateLimit)?.limit_reached || false,
|
||||
resetCredits: { availableCount: availableResetCredits },
|
||||
quotas,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user