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

8.0 KB
Raw Blame
import { ANTIGRAVITY_SHARED_MODELS, buildSurfaceCatalog } from "./antigravitySharedModels.ts";

export const ANTIGRAVITY_PUBLIC_MODELS = buildSurfaceCatalog(ANTIGRAVITY_SHARED_MODELS, {
  add: [], // IDE-only models (currently none)
  remove: [], // Models hidden from IDE (currently none)
});

export const ANTIGRAVITY_MODEL_ALIASES = Object.freeze({
  // Gemini 3.7 Flash tiers map to the upstream tiered endpoint model; the thinking
  // budget is steered via generationConfig.thinkingConfig.thinkingBudget.
  "gemini-3.7-flash": "gemini-3.7-flash-tiered",
  "gemini-3.7-flash-high": "gemini-3.7-flash-tiered",
  "gemini-3.7-flash-medium": "gemini-3.7-flash-tiered",
  "gemini-3.7-flash-low": "gemini-3.7-flash-tiered",
  // Gemini 3.8 Flash tiers are served DIRECTLY by the live Cloud Code upstream
  // (v1internal:streamGenerateContent) at their own tier ids — unlike 3.7, there is no
  // shared "-tiered" endpoint for 3.8. -high/-medium/-low are accepted verbatim; only
  // the bare display id needs a default-tier alias.
  "gemini-3.8-flash": "gemini-3.8-flash-high",
  "gemini-3.8-flash-tiered": "gemini-3.8-flash-high",
  "gpt-oss-120b": "gpt-oss-120b-medium",
  // gemini-3.1-pro-low is not aliased: the upstream accepts it verbatim.
  // gemini-3.1-pro-high: the discovery slot returns HTTP 400 on v1internal;
  // the live upstream id is gemini-pro-agent (see ANTIGRAVITY_PUBLIC_MODELS).
  "gemini-3.1-pro-high": "gemini-pro-agent",
  "gemini-3-pro-image-preview": "gemini-3-pro-image",
  // Legacy Claude display ids → current upstream ids. NOTE: an earlier comment here
  // assumed Claude was removed from Antigravity 2.0 and would 404; discussion #3184
  // disproved that — the Antigravity OAuth backend still serves claude-opus-4-6-thinking
  // and claude-sonnet-4-6 (now listed in ANTIGRAVITY_PUBLIC_MODELS above). These aliases
  // remap the old gemini-claude-* ids to the live upstream ids.
  "gemini-claude-sonnet-4-5": "claude-sonnet-4-6",
  "gemini-claude-sonnet-4-5-thinking": "claude-sonnet-4-6",
  "gemini-claude-opus-4-5-thinking": "claude-opus-4-6-thinking",
});

type AntigravityModelAliasMap = Record<string, string>;

/**
 * Per-request upstream-id fallback chains for callable Gemini 3.1 Pro tiers.
 * Each chain starts with its own key and every candidate is listed at most once.
 */
export const ANTIGRAVITY_PRO_FALLBACK_CHAINS: Readonly<Record<string, readonly string[]>> =
  Object.freeze({
    "gemini-3.1-pro-low": Object.freeze(["gemini-3.1-pro-low", "gemini-3-pro-low"]),
  });

/**
 * Return the ordered upstream-id fallback chain for `modelId` (the requested id first), or
 * `[]` when the model has no chain (flash, claude, plain pro, etc.). Pure — safe to unit test
 * and to call on every request (returns `[]` cheaply off the happy path's hot models).
 */
export function getAntigravityModelFallbacks(modelId: string): readonly string[] {
  if (!modelId) return [];
  return ANTIGRAVITY_PRO_FALLBACK_CHAINS[modelId] ?? [];
}

export const ANTIGRAVITY_REVERSE_MODEL_ALIASES: AntigravityModelAliasMap = Object.freeze({
  "gemini-3-pro-image": "gemini-3-pro-image-preview",
});

const CLIENT_VISIBLE_MODEL_NAMES = Object.freeze(
  ANTIGRAVITY_PUBLIC_MODELS.reduce<Record<string, string>>((acc, model) => {
    acc[model.id] = model.name;
    return acc;
  }, {})
);

const PUBLIC_MODEL_IDS = new Set(ANTIGRAVITY_PUBLIC_MODELS.map((model) => model.id));
const UPSTREAM_PUBLIC_MODEL_IDS = new Set(
  ANTIGRAVITY_PUBLIC_MODELS.map((model) => resolveAntigravityModelId(model.id))
);

// The authenticated Antigravity `:fetchAvailableModels` response is the source of truth for
// the models enabled for the current account and client version. Keep only known non-chat
// surfaces out of that live catalog; do not require every newly launched chat model to be
// added to this static fallback catalog first.
const ANTIGRAVITY_NON_CHAT_MODEL_IDS = new Set([
  "gemini-3-pro-image-preview",
  "gemini-3.1-flash-image",
  "gemini-3.1-flash-tts-preview",
  "gemini-2.5-flash-preview-tts",
  "tab_flash_lite_preview",
  "tab_jump_flash_lite_preview",
]);

// Non-chat models that still expose user-facing quota buckets. Keep these out of
// chat discovery while allowing Provider Limits to surface their live quota.
export const ANTIGRAVITY_QUOTA_VISIBLE_NON_CHAT_MODEL_IDS: ReadonlySet<string> = new Set([
  "gemini-3-pro-image-preview",
  "gemini-3.1-flash-image",
]);

const ANTIGRAVITY_RETIRED_MODEL_IDS = new Set([
  "gemini-3-pro-preview",
  "gemini-3.1-pro",
  // Per-tier 3.7 ids are absent from the live roster (discussion #15568) and alias onto the
  // shared "-tiered" id. `gemini-3.7-flash-tiered`, `gemini-3.6-flash-tiered` and
  // `gemini-3-flash` ARE still served live, so they are deliberately NOT retired here.
  "gemini-3.7-flash",
  "gemini-3.7-flash-high",
  "gemini-3.7-flash-medium",
  "gemini-3.7-flash-low",
  "gemini-3.6-flash-high",
  "gemini-3.6-flash-medium",
  "gemini-3.6-flash-low",
  "gemini-3-flash-agent",
  "gemini-3.5-flash",
  "gemini-3.5-flash-extra-low",
  "gemini-3.5-flash-low",
  "gemini-3.5-flash-high",
  "gemini-3.5-flash-medium",
  "gemini-3.5-flash-preview",
  "gemini-2.5-pro",
  "gemini-2.5-flash-thinking",
  "gemini-2.5-flash",
  "gemini-2.5-flash-lite",
  "gemini-2.5-computer-use-preview-10-2025",
]);

const ANTIGRAVITY_NON_CHAT_MODEL_PATTERN =
  /(?:^|[-_])(image|imagen|audio|tts|embedding|embed|video|veo)(?:[-_]|$)/i;

export function resolveAntigravityModelId(modelId: string): string {
  if (!modelId) return modelId;
  return (ANTIGRAVITY_MODEL_ALIASES as AntigravityModelAliasMap)[modelId] || modelId;
}

export function toClientAntigravityModelId(modelId: string): string {
  if (!modelId) return modelId;
  return ANTIGRAVITY_REVERSE_MODEL_ALIASES[modelId] || modelId;
}

// Retired/hidden upstream preview buckets that must be dropped from client-facing usage.
const ANTIGRAVITY_DROPPED_QUOTA_BUCKETS = new Set<string>([
  "gemini-3.5-flash-preview",
  "gemini-3-flash-preview",
]);

/**
 * Keep Antigravity quota buckets in the upstream model-id namespace used by the public
 * catalog, or return `null` when a retired preview bucket should be hidden from clients.
 */
export function toClientAntigravityQuotaModelId(modelId: string): string | null {
  if (!modelId) return null;
  if (
    ANTIGRAVITY_DROPPED_QUOTA_BUCKETS.has(modelId) ||
    ANTIGRAVITY_RETIRED_MODEL_IDS.has(modelId)
  ) {
    return null;
  }
  return toClientAntigravityModelId(modelId);
}

export function getClientVisibleAntigravityModelName(
  modelId: string,
  fallbackName?: string
): string {
  return CLIENT_VISIBLE_MODEL_NAMES[modelId] || fallbackName || modelId;
}

export function isUserCallableAntigravityModelId(modelId: string): boolean {
  if (!modelId) return false;
  const clientId = toClientAntigravityModelId(modelId);
  const upstreamId = resolveAntigravityModelId(modelId);
  return PUBLIC_MODEL_IDS.has(clientId) || UPSTREAM_PUBLIC_MODEL_IDS.has(upstreamId);
}

/**
 * Return whether a model reported by Antigravity's authenticated live catalog is eligible for
 * chat discovery. The upstream response already applies account/subscription gating and marks
 * internal entries with `isInternal`; this predicate only excludes known non-chat surfaces.
 */
export function isDiscoverableAntigravityModelId(modelId: string): boolean {
  const id = modelId.trim();
  if (
    !id ||
    id.startsWith("chat_") ||
    id.startsWith("tab_") ||
    id.endsWith("_weekly") ||
    ANTIGRAVITY_NON_CHAT_MODEL_IDS.has(id) ||
    ANTIGRAVITY_RETIRED_MODEL_IDS.has(id)
  ) {
    return false;
  }
  return !ANTIGRAVITY_NON_CHAT_MODEL_PATTERN.test(id);
}

/**
 * Return whether an Antigravity model quota should be visible to users. Quota
 * visibility is intentionally broader than chat discovery: image-only models
 * are callable through /v1/images/generations and have their own live quota
 * buckets, but must remain excluded from the chat model catalog.
 */
export function isUserVisibleAntigravityQuotaModelId(modelId: string): boolean {
  const id = modelId.trim();
  if (!id) return false;
  return (
    isDiscoverableAntigravityModelId(id) || ANTIGRAVITY_QUOTA_VISIBLE_NON_CHAT_MODEL_IDS.has(id)
  );
}