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
/**
* #13439 — HTTP status for a protected-priority stop: a `priority` target marked
* `fallbackOnlyOnQuotaExhaustion` stops the combo instead of falling through, and
* every such stop answers 503, which reads like quota exhaustion.
*
* Only causes that are provably NOT quota, rate limit or cooldown may answer 502:
* - `circuit_open`: the whole-provider breaker opens on 408/5xx only
* (PROVIDER_BREAKER_FAILURE_STATUSES; 429 and request-scoped failures never trip it);
* - `predictive_ttft`: skipped on recorded latency alone.
* Everything else (model lockout, provider/connection cooldown, request exhaustion,
* unavailable credentials, credential gate, concurrency cap, quota cutoff) keeps 503:
* those cannot be proven non-quota.
*
* Opt-in via PROTECTED_PRIORITY_INFRA_502_ENABLED (default off) because it changes a
* client-visible status; a flag-read failure keeps 503.
*
* @internal — not part of the public combo.ts barrel.
*/
import { isFeatureFlagEnabled } from "../../../src/shared/utils/featureFlags.ts";
export type ProtectedPriorityStopCause = "circuit_open" | "predictive_ttft";
export function protectedPriorityStopStatus(cause?: ProtectedPriorityStopCause): 502 | 503 {
if (cause !== "circuit_open" && cause !== "predictive_ttft") return 503;
try {
return isFeatureFlagEnabled("PROTECTED_PRIORITY_INFRA_502_ENABLED") ? 502 : 503;
} catch {
// no-effect: an unreadable flag store keeps the legacy 503
return 503;
}
}
/**
* #14313 — opt-in gate for the auto strategy's empty-candidate-pool answer (503
* `no_eligible_targets` instead of the legacy 400 capability_mismatch). Lives beside the
* protected-priority status because both decide a client-visible combo stop status behind
* a default-off flag, and this module already holds the feature-flag read (keeps the
* open-sse → src boundary from growing). Fail closed: a flag-read failure keeps the
* legacy answer.
*/
export function isComboEmptyPoolNoEligibleTargetsEnabled(): boolean {
try {
return isFeatureFlagEnabled("COMBO_EMPTY_POOL_NO_ELIGIBLE_TARGETS_ENABLED");
} catch {
// no-effect: an unreadable flag store keeps the legacy 400 capability_mismatch
return false;
}
}