Skip to content

Open source CapCut alternative.

TypeScript

fix(site): require an explicit price for every model and drop the $1 fallback

David Leae97f3b94638
diff --git a/site/src/lib/credits/inference.ts b/site/src/lib/credits/inference.ts
index 7ef8c0af..f9f3870b 100644
--- a/site/src/lib/credits/inference.ts
+++ b/site/src/lib/credits/inference.ts
@@ -868,9 +868,20 @@ async function resolveCreditRate(
);
}
- return rateSnapshot(
- globalRate,
- providerDefaultRate,
+ if (globalRate) {
+ return rateSnapshot(globalRate, providerDefaultRate);
+ }
+
+ // Flat-priced routes (vision, refresh) don't need per-model pricing.
+ if (routeHasFlatPrice(route)) {
+ return providerDefaultRate;
+ }
+
+ // Every billable model must have a price — a code-level rate in provider-pricing.ts or a DB
+ // override. Fail loudly instead of silently charging a default so a missing price is caught.
+ throw new Error(
+ `No credit price configured for provider="${provider}" model="${model}" on route="${route}". ` +
+ "Add a price in provider-pricing.ts or an InferenceCreditRate row.",
);
}
@@ -908,28 +919,33 @@ function rateSnapshot(
// InferenceCreditRate row still overrides it.
export const visionCallDefaultMicros = creditStringToMicros("0.004");
+// Routes priced per call regardless of model (no per-model pricing required): refresh is free
+// and a vision parse is a flat per-call charge. Every other route bills against a model price.
+function routeHasFlatPrice(route: string): boolean {
+ return (
+ route === inferenceUsageRoutes.assetsRefresh ||
+ route === inferenceUsageRoutes.vision
+ );
+}
+
function defaultCreditRate(
route: string,
provider: string,
model: string,
): CreditRateSnapshot {
- const defaultRequestMicros =
- route === inferenceUsageRoutes.assetsRefresh
- ? zeroCreditMicros
- : route === inferenceUsageRoutes.vision
- ? visionCallDefaultMicros
- : creditStringToMicros("1");
+ const flatRequestMicros =
+ route === inferenceUsageRoutes.vision ? visionCallDefaultMicros : zeroCreditMicros;
const providerPricing = providerCreditPricing(provider, model);
return {
id: null,
version: null,
- baseCostMicros: providerPricing ? zeroCreditMicros : defaultRequestMicros,
+ baseCostMicros: providerPricing ? zeroCreditMicros : flatRequestMicros,
inputTokenCostMicros: zeroCreditMicros,
outputTokenCostMicros: zeroCreditMicros,
totalTokenCostMicros: zeroCreditMicros,
characterCostMicros: zeroCreditMicros,
- fallbackCostMicros: defaultRequestMicros,
+ fallbackCostMicros: flatRequestMicros,
providerPricing,
};
}
diff --git a/site/src/lib/credits/provider-pricing.ts b/site/src/lib/credits/provider-pricing.ts
index 81f60993..485da210 100644
--- a/site/src/lib/credits/provider-pricing.ts
+++ b/site/src/lib/credits/provider-pricing.ts
@@ -2,6 +2,7 @@ import {
creditStringToMicros,
zeroCreditMicros,
} from "@/lib/credits/amounts";
+import { geminiModels, type GeminiModel } from "@/lib/inference/gemini-models";
export type ProviderCreditPricing = {
inputTokenCostMicrosPerMillion?: bigint;
@@ -229,35 +230,37 @@ const openAITextCreditRates: {
{ model: "computer-use-preview", input: "3", output: "12" },
];
-function geminiCreditPricing(model: string): ProviderCreditPricing | undefined {
- if (modelMatches(model, "gemini-3.5-flash")) {
- return textTokenPricing({
- model: "gemini-3.5-flash",
- input: "1.5",
- cachedInput: "0.15",
- output: "9",
- });
- }
- if (modelMatches(model, "gemini-3-flash-preview")) {
- return textAudioTokenPricing({
- input: "0.5",
- cachedInput: "0.05",
- output: "3",
- inputAudio: "1",
- });
- }
- if (modelMatches(model, "gemini-3.1-flash-lite")) {
- return textAudioTokenPricing({
- input: "0.25",
- cachedInput: "0.025",
- output: "1.5",
- inputAudio: "0.5",
- });
- }
+// Every Gemini model we run must appear here: the Record is keyed by the GeminiModel union,
+// so adding a model to gemini-models.ts without a price fails the type-check (and the build).
+const geminiModelPricing: Record<GeminiModel, ProviderCreditPricing> = {
+ [geminiModels.flash]: textTokenPricing({
+ model: "gemini-3.5-flash",
+ input: "1.5",
+ cachedInput: "0.15",
+ output: "9",
+ }),
+ [geminiModels.flashComputerUse]: textAudioTokenPricing({
+ input: "0.5",
+ cachedInput: "0.05",
+ output: "3",
+ inputAudio: "1",
+ }),
+ [geminiModels.flashLite]: textAudioTokenPricing({
+ input: "0.25",
+ cachedInput: "0.025",
+ output: "1.5",
+ inputAudio: "0.5",
+ }),
// Generative image editing/generation ("nano banana") bills per output image:
// ~1290 output tokens at $30/1M ≈ $0.039 each.
- if (modelMatches(model, "gemini-2.5-flash-image")) {
- return { generationCostMicros: usdWithMargin("0.039") };
+ [geminiModels.flashImage]: { generationCostMicros: usdWithMargin("0.039") },
+};
+
+function geminiCreditPricing(model: string): ProviderCreditPricing | undefined {
+ for (const [id, pricing] of Object.entries(geminiModelPricing)) {
+ if (modelMatches(model, id)) {
+ return pricing;
+ }
}
return undefined;