Skip to content

Open source CapCut alternative.

TypeScript

Centralize Gemini model roles

David Lec21dffca7b42
diff --git a/docs/guides/backend-apis.md b/docs/guides/backend-apis.md
index 1a191c75..dbee40f2 100644
--- a/docs/guides/backend-apis.md
+++ b/docs/guides/backend-apis.md
@@ -62,7 +62,7 @@ provider names are configuration/data inside private adapters only.
- Screenshot parsing is available at `POST /api/inference/screenshots/parse/`.
It accepts scoped app/window or system-navigation screenshots only, never
whole-desktop captures, and returns read-only UI evidence in the Mac app's
- local UI understanding shape. The default provider is Gemini 2.5 Flash through
+ local UI understanding shape. The default provider is Gemini Flash through
a dedicated screenshot-parsing module configured with hosted Google
credentials or `GEMINI_API_KEY`.
- The Gemini adapter uses the official `@google/genai` Node/TypeScript SDK for
diff --git a/site/src/lib/credits/provider-pricing.ts b/site/src/lib/credits/provider-pricing.ts
index 0a40f0ea..a36d650b 100644
--- a/site/src/lib/credits/provider-pricing.ts
+++ b/site/src/lib/credits/provider-pricing.ts
@@ -21,7 +21,6 @@ export type ProviderCreditPricing = {
const providerMarginNumerator = BigInt(13);
const providerMarginDenominator = BigInt(10);
const openAILongContextThresholdTokens = BigInt(272000);
-const geminiLongContextThresholdTokens = BigInt(200000);
export function providerCreditPricing(
provider: string,
@@ -255,37 +254,6 @@ function geminiCreditPricing(model: string): ProviderCreditPricing | undefined {
inputAudio: "0.5",
});
}
- if (modelMatches(model, "gemini-2.5-pro")) {
- return textAudioTokenPricing({
- input: "1.25",
- cachedInput: "0.13",
- output: "10",
- inputAudio: "1.25",
- longContextThresholdTokens: geminiLongContextThresholdTokens,
- longContext: {
- inputTokenCostMicrosPerMillion: usdPerMillionWithMargin("2.5"),
- cachedInputTokenCostMicrosPerMillion: usdPerMillionWithMargin("0.25"),
- outputTokenCostMicrosPerMillion: usdPerMillionWithMargin("15"),
- inputAudioTokenCostMicrosPerMillion: usdPerMillionWithMargin("2.5"),
- },
- });
- }
- if (modelMatches(model, "gemini-2.5-flash-lite")) {
- return textAudioTokenPricing({
- input: "0.1",
- cachedInput: "0.01",
- output: "0.4",
- inputAudio: "0.3",
- });
- }
- if (modelMatches(model, "gemini-2.5-flash")) {
- return textAudioTokenPricing({
- input: "0.3",
- cachedInput: "0.03",
- output: "2.5",
- inputAudio: "1",
- });
- }
return undefined;
}
diff --git a/site/src/lib/inference/adapters/gemini-computer-use.ts b/site/src/lib/inference/adapters/gemini-computer-use.ts
index 98ff49f6..66d075a2 100644
--- a/site/src/lib/inference/adapters/gemini-computer-use.ts
+++ b/site/src/lib/inference/adapters/gemini-computer-use.ts
@@ -12,6 +12,7 @@ import type {
Tool,
} from "@google/genai";
+import { geminiModelRoles } from "@/lib/inference/gemini-models";
import { ensureConfigured } from "@/lib/inference/http";
import {
isJsonObject,
@@ -37,9 +38,9 @@ type GeminiClientFactory = (options: GoogleGenAIOptions) => GeminiClient;
const providerID = "gemini-computer-use";
const geminiProviderID = "gemini";
-const defaultDecisionResponsesModel = "gemini-3.1-flash-lite";
-const defaultVertexResponsesModel = "gemini-3.5-flash";
-const defaultComputerUseModel = "gemini-3-flash-preview";
+const defaultDecisionResponsesModel = geminiModelRoles.fastDecision;
+const defaultVertexResponsesModel = geminiModelRoles.chat;
+const defaultComputerUseModel = geminiModelRoles.browserComputerUse;
const vertexLocation = "global";
const vertexAIScope = "https://www.googleapis.com/auth/cloud-platform";
diff --git a/site/src/lib/inference/gemini-models.ts b/site/src/lib/inference/gemini-models.ts
new file mode 100644
index 00000000..c4157c6e
--- /dev/null
+++ b/site/src/lib/inference/gemini-models.ts
@@ -0,0 +1,31 @@
+// Central registry of Gemini model IDs used by the inference gateway.
+//
+// Model selection lives in code (see docs/guides/backend-apis.md), so this is
+// the single source of truth for which Gemini models we run and what each one
+// is for. Adapters and schemas should import these constants instead of
+// hardcoding version strings, so bumping a model is a one-line change here.
+
+// Canonical, dated-or-versioned model IDs. Add a new constant when adopting a
+// new model; do not inline raw version strings at call sites.
+export const geminiModels = {
+ flash: "gemini-3.5-flash",
+ flashLite: "gemini-3.1-flash-lite",
+ flashComputerUse: "gemini-3-flash-preview",
+} as const;
+
+export type GeminiModel = (typeof geminiModels)[keyof typeof geminiModels];
+
+// Semantic roles map a job to the model we run for it. Prefer referencing a
+// role over a bare constant so intent stays explicit at the call site.
+export const geminiModelRoles = {
+ // General chat and non-decision Responses calls — the latest full flash.
+ chat: geminiModels.flash,
+ // Fast structured task-intent and follow-up decisions.
+ fastDecision: geminiModels.flashLite,
+ // Browser Computer Use tool calls.
+ browserComputerUse: geminiModels.flashComputerUse,
+ // Screenshot parsing into read-only UI evidence.
+ screenshotParse: geminiModels.flash,
+ // Vision grounding: a cheap structured pick over already-parsed elements.
+ visionGrounding: geminiModels.flashLite,
+} as const;
diff --git a/site/src/lib/inference/screenshot-parsing/gemini-flash.ts b/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
index bd30ced2..da1113e6 100644
--- a/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
+++ b/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
@@ -11,6 +11,7 @@ import type {
Schema,
} from "@google/genai";
+import { geminiModelRoles } from "@/lib/inference/gemini-models";
import { ensureConfigured } from "@/lib/inference/http";
import {
isJsonObject,
@@ -35,8 +36,8 @@ type GeminiClientFactory = (options: GoogleGenAIOptions) => GeminiClient;
const geminiProviderID = "gemini";
const screenshotProviderID = "gemini-flash";
-const defaultScreenshotParseModel = "gemini-2.5-flash";
-const defaultDebugOverlayScreenshotParseModel = "gemini-2.5-flash";
+const defaultScreenshotParseModel = geminiModelRoles.screenshotParse;
+const defaultDebugOverlayScreenshotParseModel = geminiModelRoles.screenshotParse;
const defaultVertexLocation = "global";
const vertexAIScope = "https://www.googleapis.com/auth/cloud-platform";
diff --git a/site/src/lib/inference/vision/schema.ts b/site/src/lib/inference/vision/schema.ts
index e63bd8f3..36af6885 100644
--- a/site/src/lib/inference/vision/schema.ts
+++ b/site/src/lib/inference/vision/schema.ts
@@ -1,5 +1,7 @@
import { z } from "zod";
+import { geminiModels, geminiModelRoles } from "@/lib/inference/gemini-models";
+
// Public B2B vision API contract for POST /api/inference/vision.
//
// Two stages: parse a screenshot into UI elements (always), and optionally
@@ -7,11 +9,14 @@ import { z } from "zod";
// target using an LLM. Coordinates are pixels relative to the uploaded image,
// origin top-left.
-// Allow-list of grounding models. Extend deliberately — each must be wired in
-// vision/grounding.ts.
-export const supportedVisionModels = ["gemini-2.5-flash"] as const;
+// Allow-list of grounding models, sourced from the central Gemini registry.
+// Extend deliberately — each must be wired in vision/grounding.ts.
+export const supportedVisionModels = [
+ geminiModels.flash,
+ geminiModels.flashLite,
+] as const;
export type VisionModel = (typeof supportedVisionModels)[number];
-export const defaultVisionModel: VisionModel = "gemini-2.5-flash";
+export const defaultVisionModel: VisionModel = geminiModelRoles.visionGrounding;
export const visionParseOptionsSchema = z.object({
boxThreshold: z.number().min(0).max(1).optional(),