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

992 B
Raw Blame
/**
 * Per-connection TPM budget for combo quota reservation.
 *
 * Extracted from roundRobinCombo.ts, a file-size-frozen file: the lookup is
 * unchanged, only relocated so the dispatcher can keep its own behavior.
 *
 * @internal — not part of the public combo.ts barrel.
 */
import { getCachedProviderConnectionById } from "../../../src/lib/db/readCache.ts";

/** Undefined = the store keeps its prior limit for this connection. */
export async function resolveTargetTokenLimit(target: {
  connectionId?: string | null;
}): Promise<number | undefined> {
  const connectionId = target?.connectionId;
  if (!connectionId) return undefined;
  try {
    const connection = await getCachedProviderConnectionById(connectionId);
    const overrides = (connection as { rateLimitOverrides?: Record<string, number> | null } | null)
      ?.rateLimitOverrides;
    const tpm = overrides?.tpm;
    return typeof tpm === "number" && tpm > 0 ? tpm : undefined;
  } catch {
    return undefined;
  }
}