Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

8.2 KB
Raw Blame
// Pinned base URLs: a catalog refresh can never change where a newly pasted key for a recommended provider is sent.

export type AnthropicAuth = "bearer" | "x-api-key";

export interface AnthropicEndpoint {
  /** Claude Code's ANTHROPIC_BASE_URL; Claude Code adds /v1/messages. */
  baseUrl: string;
  /** A fixed auth style. Absent: the check decides, preferring Bearer. */
  auth?: AnthropicAuth;
  doc?: string;
}

export type CodexUnsupportedReason = "no-responses-api" | "not-supported";

export type CodexSupport =
  | {
    kind: "documented";
    doc: string;
    denyModels?: RegExp;
    denyKeyPrefixes?: readonly string[];
  }
  | { kind: "unsupported"; reason: CodexUnsupportedReason };

export interface ProviderPreset {
  id: string;
  catalogId?: string;
  label: string;
  recommended?: number;
  /** OpenAI-compatible base URL. Wins over models.dev's `api`. */
  api: string;
  /** For when models.dev's `npm` is for a different endpoint (MiniMax: its Anthropic one). */
  npm?: string;
  env?: string;
  doc?: string;
  anthropic?: AnthropicEndpoint;
  /** Absent: Codex only as an experiment, and only if the check passes. */
  codex?: CodexSupport;
  /** Path added to `api` for a GET that proves the key (a 2xx means it works). */
  keyCheck?: string;
  /** GET {api}/models answers without a key, so it proves nothing about one. */
  publicModels?: true;
  chat?: "after-check";
  /** Last checked by hand (YYYY-MM-DD). */
  checkedAt: string;
}

const CHECKED = "2026-09-30";

export const OPENAI_COMPATIBLE_NPM = "@ai-sdk/openai-compatible";

export const PROVIDER_PRESETS: readonly ProviderPreset[] = [
  {
    id: "openrouter",
    catalogId: "openrouter",
    label: "OpenRouter",
    recommended: 1,
    api: "https://openrouter.ai/api/v1",
    anthropic: {
      baseUrl: "https://openrouter.ai/api",
      auth: "bearer",
      doc: "https://openrouter.ai/docs/guides/guides/claude-code-integration",
    },
    codex: { kind: "documented", doc: "https://openrouter.ai/docs/cookbook/coding-agents/codex-cli" },
    // /models is public; /key answers only with a valid key.
    keyCheck: "/key",
    publicModels: true,
    checkedAt: CHECKED,
  },
  {
    id: "fireworks-ai",
    catalogId: "fireworks-ai",
    label: "Fireworks AI",
    recommended: 2,
    api: "https://api.fireworks.ai/inference/v1",
    anthropic: {
      baseUrl: "https://api.fireworks.ai/inference",
      auth: "bearer",
      doc: "https://docs.fireworks.ai/tools-sdks/anthropic-compatibility",
    },
    codex: {
      kind: "documented",
      doc: "https://docs.fireworks.ai/ecosystem/fireconnect/codex",
      // Fireworks: MiniMax models and Fire Pass keys do not work with Codex.
      denyModels: /minimax/i,
      denyKeyPrefixes: ["fpk_"],
    },
    checkedAt: CHECKED,
  },
  {
    id: "deepseek",
    catalogId: "deepseek",
    label: "DeepSeek",
    recommended: 3,
    api: "https://api.deepseek.com",
    anthropic: { baseUrl: "https://api.deepseek.com/anthropic", doc: "https://api-docs.deepseek.com/guides/anthropic_api" },
    codex: { kind: "unsupported", reason: "no-responses-api" },
    checkedAt: CHECKED,
  },
  {
    id: "cline-pass",
    catalogId: "cline-pass",
    label: "Cline (ClinePass)",
    recommended: 4,
    api: "https://api.cline.bot/api/v1",
    codex: { kind: "unsupported", reason: "not-supported" },
    publicModels: true,
    checkedAt: CHECKED,
  },
  {
    // Cline's pay-as-you-go credits: the ClinePass API with a larger model list. Not in models.dev.
    id: "cline-credits",
    label: "Cline (credits)",
    recommended: 5,
    api: "https://api.cline.bot/api/v1",
    env: "CLINE_API_KEY",
    doc: "https://docs.cline.bot/api/overview",
    codex: { kind: "unsupported", reason: "not-supported" },
    publicModels: true,
    checkedAt: CHECKED,
  },
  { id: "groq", catalogId: "groq", label: "Groq", recommended: 6, api: "https://api.groq.com/openai/v1", checkedAt: CHECKED },
  { id: "togetherai", catalogId: "togetherai", label: "Together AI", recommended: 7, api: "https://api.together.xyz/v1", checkedAt: CHECKED },
  { id: "mistral", catalogId: "mistral", label: "Mistral", recommended: 8, api: "https://api.mistral.ai/v1", checkedAt: CHECKED },
  { id: "xai", catalogId: "xai", label: "xAI", recommended: 9, api: "https://api.x.ai/v1", checkedAt: CHECKED },
  {
    id: "moonshotai",
    catalogId: "moonshotai",
    label: "Moonshot (Kimi)",
    recommended: 10,
    api: "https://api.moonshot.ai/v1",
    anthropic: { baseUrl: "https://api.moonshot.ai/anthropic" },
    checkedAt: CHECKED,
  },
  {
    id: "zai",
    catalogId: "zai",
    label: "Z.ai",
    recommended: 11,
    api: "https://api.z.ai/api/paas/v4",
    anthropic: { baseUrl: "https://api.z.ai/api/anthropic" },
    checkedAt: CHECKED,
  },
  {
    // models.dev lists MiniMax's Anthropic endpoint (with @ai-sdk/anthropic); the chat engine and OpenCode need the OpenAI one.
    id: "minimax",
    catalogId: "minimax",
    label: "MiniMax",
    recommended: 12,
    api: "https://api.minimax.io/v1",
    npm: OPENAI_COMPATIBLE_NPM,
    anthropic: { baseUrl: "https://api.minimax.io/anthropic" },
    chat: "after-check",
    checkedAt: CHECKED,
  },
  { id: "cerebras", catalogId: "cerebras", label: "Cerebras", recommended: 13, api: "https://api.cerebras.ai/v1", checkedAt: CHECKED },
  {
    id: "openai",
    catalogId: "openai",
    label: "OpenAI",
    api: "https://api.openai.com/v1",
    codex: { kind: "documented", doc: "https://github.com/openai/codex" },
    checkedAt: CHECKED,
  },
  {
    id: "opencode",
    catalogId: "opencode",
    label: "OpenCode Zen",
    api: "https://opencode.ai/zen/v1",
    anthropic: { baseUrl: "https://opencode.ai/zen" },
    checkedAt: CHECKED,
  },
  {
    id: "wallaby",
    catalogId: "wallaby",
    label: "Wallaby",
    api: "https://api.wallabytoken.com/v1",
    keyCheck: "/models",
    checkedAt: "2026-10-05",
  },
];

const BY_ID = new Map(PROVIDER_PRESETS.map((preset) => [preset.id, preset]));

export function providerPreset(id: string): ProviderPreset | undefined {
  return BY_ID.get(id);
}

export type ResponsesCheck = "works" | "missing" | "key-refused" | "unchecked";

export type CodexNoReason =
  /** The provider has no Responses API (DeepSeek). */
  | "provider-no-responses-api"
  /** The provider does not support Codex (Cline). */
  | "provider-unsupported"
  /** This kind of key is documented not to work (Fireworks Fire Pass). */
  | "key-type"
  /** /responses answered a plain 404 or 405. */
  | "route-missing"
  /** /responses refused a key that /models accepted. */
  | "key-refused"
  | "not-checked"
  /** Not documented; available once the experimental switch is on. */
  | "experimental-off";

export type CodexVerdict =
  | { use: "yes" }
  | { use: "experimental" }
  | { use: "no"; reason: CodexNoReason };

export function codexKeyAllowed(preset: ProviderPreset | undefined, key: string): boolean {
  const codex = preset?.codex;
  return !(codex?.kind === "documented" && codex.denyKeyPrefixes?.some((prefix) => key.startsWith(prefix)));
}

export function codexModelAllowed(preset: ProviderPreset | undefined, model: string): boolean {
  const codex = preset?.codex;
  return !(codex?.kind === "documented" && codex.denyModels?.test(model));
}

export function codexModels(preset: ProviderPreset | undefined, models: readonly string[]): string[] {
  return models.filter((model) => codexModelAllowed(preset, model));
}

/** Whether Codex can use a provider. `preset` is undefined for custom providers. */
export function codexVerdict(input: {
  preset: ProviderPreset | undefined;
  responses: ResponsesCheck;
  experimental: boolean;
  key?: string;
}): CodexVerdict {
  const codex = input.preset?.codex;
  if (codex?.kind === "unsupported") {
    return { use: "no", reason: codex.reason === "no-responses-api" ? "provider-no-responses-api" : "provider-unsupported" };
  }
  if (input.key !== undefined && !codexKeyAllowed(input.preset, input.key)) return { use: "no", reason: "key-type" };
  if (input.responses === "missing") return { use: "no", reason: "route-missing" };
  if (input.responses === "key-refused") return { use: "no", reason: "key-refused" };
  if (input.responses !== "works") return { use: "no", reason: "not-checked" };
  if (codex?.kind === "documented") return { use: "yes" };
  return input.experimental ? { use: "experimental" } : { use: "no", reason: "experimental-off" };
}