mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix: invert utilization values — API returns remaining, not used
The OAuth usage endpoint returns utilization as percentage remaining, not percentage used. Claude.ai showing 10% used corresponded to utilization=90 from the API.
This commit is contained in:
@@ -445,36 +445,45 @@ async function getClaudeUsage(accessToken) {
|
||||
const quotas: Record<string, any> = {};
|
||||
|
||||
// Parse five_hour window (session limit)
|
||||
// utilization = percentage remaining, not used
|
||||
if (data.five_hour !== undefined) {
|
||||
const remaining = data.five_hour.utilization ?? 0;
|
||||
quotas["session (5h)"] = {
|
||||
used: data.five_hour.utilization ?? 0,
|
||||
used: 100 - remaining,
|
||||
total: 100,
|
||||
resetAt: data.five_hour.resets_at || null,
|
||||
remainingPercentage: 100 - (data.five_hour.utilization ?? 0),
|
||||
remainingPercentage: remaining,
|
||||
unlimited: false,
|
||||
};
|
||||
}
|
||||
|
||||
// Parse seven_day window (weekly limit)
|
||||
if (data.seven_day !== undefined) {
|
||||
const remaining = data.seven_day.utilization ?? 0;
|
||||
quotas["weekly (7d)"] = {
|
||||
used: data.seven_day.utilization ?? 0,
|
||||
used: 100 - remaining,
|
||||
total: 100,
|
||||
resetAt: data.seven_day.resets_at || null,
|
||||
remainingPercentage: 100 - (data.seven_day.utilization ?? 0),
|
||||
remainingPercentage: remaining,
|
||||
unlimited: false,
|
||||
};
|
||||
}
|
||||
|
||||
// Parse model-specific weekly windows (e.g., seven_day_sonnet, seven_day_opus)
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
if (key.startsWith("seven_day_") && key !== "seven_day" && value && typeof value === "object") {
|
||||
if (
|
||||
key.startsWith("seven_day_") &&
|
||||
key !== "seven_day" &&
|
||||
value &&
|
||||
typeof value === "object"
|
||||
) {
|
||||
const modelName = key.replace("seven_day_", "");
|
||||
const remaining = (value as any).utilization ?? 0;
|
||||
quotas[`weekly ${modelName} (7d)`] = {
|
||||
used: (value as any).utilization ?? 0,
|
||||
used: 100 - remaining,
|
||||
total: 100,
|
||||
resetAt: (value as any).resets_at || null,
|
||||
remainingPercentage: 100 - ((value as any).utilization ?? 0),
|
||||
remainingPercentage: remaining,
|
||||
unlimited: false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user