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
import type { ModelAvailabilityResult } from "@omniroute/open-sse/services/combo/types.ts";
/** Preserve an account timer without leaking credentials or weakening caller policy. */
export function getComboCredentialAvailability(
credentials: object | null | undefined,
now = Date.now()
): ModelAvailabilityResult {
if (!credentials || ("waitingForCapacity" in credentials && credentials.waitingForCapacity)) {
return false;
}
if (!("allRateLimited" in credentials) || !credentials.allRateLimited) return true;
// Auth returns an ISO deadline, not Retry-After header seconds. Missing,
// malformed or expired hints must not fabricate a new cooldown deadline.
const resetAt =
"retryAfter" in credentials && typeof credentials.retryAfter === "string"
? Date.parse(credentials.retryAfter)
: NaN;
const retryAfterMs = resetAt - now;
if (!Number.isFinite(retryAfterMs) || retryAfterMs <= 0) return false;
return { available: false, reason: "connection_cooldown", retryAfterMs };
}