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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(v1beta): use stored token limits and metadata in Gemini models endpoint
Chris Staleyfaae82eae1b8
diff --git a/src/app/api/v1beta/models/route.ts b/src/app/api/v1beta/models/route.tsindex 1838e63375..e9bbd3842f 100644--- a/src/app/api/v1beta/models/route.ts+++ b/src/app/api/v1beta/models/route.ts@@ -1,5 +1,6 @@import { CORS_ORIGIN } from "@/shared/utils/cors";import { PROVIDER_MODELS } from "@/shared/constants/models";+import { getAllCustomModels } from "@/lib/db/models";/*** Handle CORS preflight@@ -16,13 +17,13 @@ export async function OPTIONS() {/*** GET /v1beta/models - Gemini compatible models list- * Returns models in Gemini API format+ * Returns models in Gemini API format with real token limits when available.*/export async function GET() {try {- // Collect all models from all providersconst models = [];+ // Built-in models (hardcoded defaults)for (const [provider, providerModels] of Object.entries(PROVIDER_MODELS)) {for (const model of providerModels) {models.push({@@ -36,8 +37,34 @@ export async function GET() {}}+ // Custom models (use stored metadata from provider APIs)+ try {+ const customModelsMap = (await getAllCustomModels()) as Record<string, unknown>;+ for (const [providerId, rawModels] of Object.entries(customModelsMap)) {+ if (!Array.isArray(rawModels)) continue;+ for (const model of rawModels) {+ if (!model || typeof model !== "object" || typeof (model as any).id !== "string") continue;+ const m = model as Record<string, unknown>;+ if (m.isHidden === true) continue;+ models.push({+ name: `models/${providerId}/${m.id}`,+ displayName: m.name || m.id,+ ...(typeof m.description === "string" ? { description: m.description } : {}),+ supportedGenerationMethods: ["generateContent"],+ inputTokenLimit:+ typeof m.inputTokenLimit === "number" ? m.inputTokenLimit : 128000,+ outputTokenLimit:+ typeof m.outputTokenLimit === "number" ? m.outputTokenLimit : 8192,+ ...(m.supportsThinking === true ? { thinking: true } : {}),+ });+ }+ }+ } catch {+ // Custom models are optional — skip on error+ }+return Response.json({ models });- } catch (error) {+ } catch (error: any) {console.log("Error fetching models:", error);return Response.json({ error: { message: error.message } }, { status: 500 });}