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.2 KB
Raw Blame
"use client";

import { useEffect, useState } from "react";
import type { LiveModelsByProviderId } from "../providerPageUtils";

/**
 * useSyncedModelsByProvider — fetch the live/synced model catalog for every
 * provider connection via GET /api/synced-available-models, so the Providers
 * page model-name filter can match against real upstream models (not just
 * the static curated registry). See #7250: aggregator providers (openrouter,
 * kilocode, ...) declare a single-entry static placeholder, so a
 * search for a real model name never matched and silently hid the provider.
 *
 * Fails soft — a fetch error leaves the map empty, and callers fall back to
 * the static registry only.
 */
export function useSyncedModelsByProvider(): LiveModelsByProviderId {
  const [models, setModels] = useState<LiveModelsByProviderId>({});

  useEffect(() => {
    let cancelled = false;
    fetch("/api/synced-available-models")
      .then((res) => (res.ok ? res.json() : null))
      .then((data) => {
        if (!cancelled && data && typeof data === "object") {
          setModels(data as LiveModelsByProviderId);
        }
      })
      .catch(() => {});
    return () => {
      cancelled = true;
    };
  }, []);

  return models;
}