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.3 KB
Raw Blame
import { hasNoRunnableEndpointAdapter } from "@/lib/providerModels/endpointAdapterAvailability";
import { isModelEndpointCapabilityGateEnabled } from "@/lib/providerModels/endpointCapabilityGateFlag";
import { getModelEndpointDecision } from "@omniroute/open-sse/services/modelEndpointPolicy";
import { isModelSelectable } from "@omniroute/open-sse/services/modelLifecycle";

type CatalogModelPolicyInput = {
  id: string;
  supportedEndpoints?: readonly string[];
  endpointCapabilitySource?: string;
};

export function isUnifiedChatSourceModelSelectable(
  provider: string,
  model: CatalogModelPolicyInput
): boolean {
  if (!isModelSelectable(provider, model.id)) return false;
  if (
    getModelEndpointDecision(provider, model.id, model.supportedEndpoints).reason ===
    "provider-policy"
  )
    return false;

  // #16929 (opt-in, MODEL_ENDPOINT_CAPABILITY_GATE_ENABLED): a discovered tag is a
  // capability statement, not evidence of an executable provider handler. With the
  // flag on, known-unrunnable models are not advertised in /v1/models. Legacy and
  // defaulted tags preserve the existing fallback. Flag off = tip listing.
  if (
    model.supportedEndpoints?.length &&
    isModelEndpointCapabilityGateEnabled() &&
    hasNoRunnableEndpointAdapter(provider, model)
  ) {
    return false;
  }
  return true;
}