Skip to content

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

1.1 KB
Raw Blame
import { HTTP_STATUS } from "../../config/constants.ts";

/**
 * Whether a failed single-model attempt is a *self-inflicted* upstream timeout — i.e.
 * OmniRoute's own deadline (fetch-start `TimeoutError`, body `BodyTimeoutError`, or the
 * combo-per-model timeout) fired while the upstream was still processing the request,
 * surfaced as a 504 tagged `errorType: "upstream_timeout"`.
 *
 * Such a timeout is NOT a provider rejection — the connection is healthy, we just gave
 * up waiting — so the caller must skip the connection cooldown for it. Cooling the
 * connection down on our own timeout penalises a healthy account and, when a provider
 * has a single connection, blocks every subsequent request behind a self-inflicted
 * cooldown. Antigravity keeps its own pre-response-timeout cooldown policy and is
 * therefore excluded here.
 */
export function isSelfInflictedUpstreamTimeout(
  status: number,
  errorType: string | undefined | null,
  provider: string
): boolean {
  return (
    status === HTTP_STATUS.GATEWAY_TIMEOUT &&
    errorType === "upstream_timeout" &&
    provider !== "antigravity"
  );
}