diff --git a/src/app/api/providers/suggested-models/filters.js b/src/app/api/providers/suggested-models/filters.js new file mode 100644 index 00000000..c8d56c51 --- /dev/null +++ b/src/app/api/providers/suggested-models/filters.js @@ -0,0 +1,20 @@ +// Free OpenCode models that don't use the "-free" id suffix +const KNOWN_FREE_OPENCODE_MODELS = ["big-pickle"]; + +export const FILTERS = { + "openrouter-free": (models) => + models + .filter( + (m) => + m.pricing?.prompt === "0" && + m.pricing?.completion === "0" && + m.context_length >= 200000 + ) + .map((m) => ({ id: m.id, name: m.name, contextLength: m.context_length })) + .sort((a, b) => b.contextLength - a.contextLength), + + "opencode-free": (models) => + models + .filter((m) => m.id?.endsWith("-free") || KNOWN_FREE_OPENCODE_MODELS.includes(m.id)) + .map((m) => ({ id: m.id, name: m.id })), +}; diff --git a/src/app/api/providers/suggested-models/route.js b/src/app/api/providers/suggested-models/route.js index 140e3f86..c14f70c8 100644 --- a/src/app/api/providers/suggested-models/route.js +++ b/src/app/api/providers/suggested-models/route.js @@ -1,25 +1,8 @@ import { NextResponse } from "next/server"; +import { FILTERS } from "./filters.js"; export const dynamic = "force-dynamic"; -const FILTERS = { - "openrouter-free": (models) => - models - .filter( - (m) => - m.pricing?.prompt === "0" && - m.pricing?.completion === "0" && - m.context_length >= 200000 - ) - .map((m) => ({ id: m.id, name: m.name, contextLength: m.context_length })) - .sort((a, b) => b.contextLength - a.contextLength), - - "opencode-free": (models) => - models - .filter((m) => m.id?.endsWith("-free")) - .map((m) => ({ id: m.id, name: m.id })), -}; - export async function GET(request) { const { searchParams } = new URL(request.url); const url = searchParams.get("url");