Skip to content

Open source CapCut alternative.

TypeScript

fix(site): enforce per-model pricing for OpenAI and ElevenLabs at build time

David Le8297f3a18d67
diff --git a/site/src/lib/credits/provider-pricing.ts b/site/src/lib/credits/provider-pricing.ts
index 485da210..af29898a 100644
--- a/site/src/lib/credits/provider-pricing.ts
+++ b/site/src/lib/credits/provider-pricing.ts
@@ -2,7 +2,12 @@ import {
creditStringToMicros,
zeroCreditMicros,
} from "@/lib/credits/amounts";
+import {
+ elevenLabsModels,
+ type ElevenLabsRunModel,
+} from "@/lib/inference/elevenlabs-models";
import { geminiModels, type GeminiModel } from "@/lib/inference/gemini-models";
+import { openaiModels, type OpenAIRunModel } from "@/lib/inference/openai-models";
export type ProviderCreditPricing = {
inputTokenCostMicrosPerMillion?: bigint;
@@ -43,12 +48,37 @@ export function providerCreditPricing(
return undefined;
}
+// Every OpenAI model the gateway selects must appear here: the Record is keyed by the
+// OpenAIRunModel union, so adding a run model without a price fails the type-check (and the
+// build). Matched exactly (not by prefix) so it never shadows a more specific table entry.
+const openaiRunModelPricing: Record<OpenAIRunModel, ProviderCreditPricing> = {
+ [openaiModels.computerUse]: textTokenPricing({
+ model: "gpt-5.5",
+ input: "5",
+ cachedInput: "0.5",
+ output: "30",
+ longContext: { input: "10", cachedInput: "1", output: "45" },
+ }),
+ [openaiModels.debugInspection]: textTokenPricing({
+ model: "gpt-5.4",
+ input: "2.5",
+ cachedInput: "0.25",
+ output: "15",
+ longContext: { input: "5", cachedInput: "0.5", output: "22.5" },
+ }),
+};
+
function openAICreditPricing(model: string): ProviderCreditPricing | undefined {
const audioPricing = openAIAudioCreditPricing(model);
if (audioPricing) {
return audioPricing;
}
+ const runModelPricing = openaiRunModelPricing[model as OpenAIRunModel];
+ if (runModelPricing) {
+ return runModelPricing;
+ }
+
const matched = openAITextCreditRates.find((rate) => modelMatches(model, rate.model));
if (!matched) {
return undefined;
@@ -162,17 +192,7 @@ const openAITextCreditRates: {
output: "270",
},
},
- {
- model: "gpt-5.5",
- input: "5",
- cachedInput: "0.5",
- output: "30",
- longContext: {
- input: "10",
- cachedInput: "1",
- output: "45",
- },
- },
+ // gpt-5.5 and gpt-5.4 are gateway-run models — priced in openaiRunModelPricing.
{
model: "gpt-5.4-pro",
input: "30",
@@ -194,17 +214,6 @@ const openAITextCreditRates: {
cachedInput: "0.02",
output: "1.25",
},
- {
- model: "gpt-5.4",
- input: "2.5",
- cachedInput: "0.25",
- output: "15",
- longContext: {
- input: "5",
- cachedInput: "0.5",
- output: "22.5",
- },
- },
{ model: "gpt-5.2-pro", input: "21", output: "168" },
{ model: "gpt-5.2", input: "1.75", cachedInput: "0.175", output: "14" },
{ model: "gpt-5.1", input: "1.25", cachedInput: "0.125", output: "10" },
@@ -266,11 +275,16 @@ function geminiCreditPricing(model: string): ProviderCreditPricing | undefined {
return undefined;
}
+// Every ElevenLabs model the gateway selects must appear here: the Record is keyed by the
+// ElevenLabsRunModel union, so adding a run model without a price fails the build.
+const elevenLabsRunModelPricing: Record<ElevenLabsRunModel, ProviderCreditPricing> = {
+ [elevenLabsModels.music]: { durationSecondCostMicros: usdWithMargin("0.005") },
+};
+
function elevenLabsCreditPricing(model: string): ProviderCreditPricing | undefined {
- if (modelMatches(model, "music_v1")) {
- return {
- durationSecondCostMicros: usdWithMargin("0.005"),
- };
+ const runModelPricing = elevenLabsRunModelPricing[model as ElevenLabsRunModel];
+ if (runModelPricing) {
+ return runModelPricing;
}
if (modelMatches(model, "eleven_text_to_sound_v2")) {
return {
diff --git a/site/src/lib/inference/adapters/audio-studio.ts b/site/src/lib/inference/adapters/audio-studio.ts
index f7b7dc20..b60bf7aa 100644
--- a/site/src/lib/inference/adapters/audio-studio.ts
+++ b/site/src/lib/inference/adapters/audio-studio.ts
@@ -4,6 +4,7 @@ import {
type ElevenLabs,
} from "@elevenlabs/elevenlabs-js";
+import { elevenLabsModels } from "@/lib/inference/elevenlabs-models";
import { ensureConfigured } from "@/lib/inference/http";
import { toJsonObject, toJsonValue } from "@/lib/inference/json";
import {
@@ -127,7 +128,7 @@ function createMusic(
() =>
client.music.compose({
...parameters,
- modelId: request.model === "music_v1" ? "music_v1" : undefined,
+ modelId: request.model === elevenLabsModels.music ? elevenLabsModels.music : undefined,
prompt: request.prompt,
} as ElevenLabs.BodyComposeMusicV1MusicPost),
);
diff --git a/site/src/lib/inference/adapters/hosted-responses.ts b/site/src/lib/inference/adapters/hosted-responses.ts
index f53d8965..d26dc947 100644
--- a/site/src/lib/inference/adapters/hosted-responses.ts
+++ b/site/src/lib/inference/adapters/hosted-responses.ts
@@ -6,6 +6,7 @@ import {
type FetchLike,
} from "@/lib/inference/http";
import { toJsonValue } from "@/lib/inference/json";
+import { openaiModels } from "@/lib/inference/openai-models";
import {
InferenceProviderError,
type InferenceModality,
@@ -24,8 +25,8 @@ const openAIProviderID = "openai";
const openAIBaseURL = "https://api.openai.com/v1";
const openAIMacDesktopInteractionToolType = "donkey_openai_mac_desktop_interaction";
const debugUIInspectionToolType = "donkey_debug_ui_inspection";
-const defaultOpenAIComputerUseModel = "gpt-5.5";
-const defaultOpenAIDebugInspectionModel = "gpt-5.4";
+const defaultOpenAIComputerUseModel = openaiModels.computerUse;
+const defaultOpenAIDebugInspectionModel = openaiModels.debugInspection;
const unsupportedOpenAIComputerUseParameters = ["temperature", "top_p", "topP"];
export function createHostedResponsesProvider(
diff --git a/site/src/lib/inference/elevenlabs-models.ts b/site/src/lib/inference/elevenlabs-models.ts
new file mode 100644
index 00000000..11cc855e
--- /dev/null
+++ b/site/src/lib/inference/elevenlabs-models.ts
@@ -0,0 +1,8 @@
+// Central registry of ElevenLabs model IDs the gateway runs (mirrors gemini-models.ts).
+// Models the code selects live here so they are priced exhaustively in provider-pricing.ts.
+export const elevenLabsModels = {
+ // Music composition.
+ music: "music_v1",
+} as const;
+
+export type ElevenLabsRunModel = (typeof elevenLabsModels)[keyof typeof elevenLabsModels];
diff --git a/site/src/lib/inference/openai-models.ts b/site/src/lib/inference/openai-models.ts
new file mode 100644
index 00000000..fd0dabed
--- /dev/null
+++ b/site/src/lib/inference/openai-models.ts
@@ -0,0 +1,11 @@
+// Central registry of OpenAI model IDs the gateway runs (mirrors gemini-models.ts).
+// Anything the code selects lives here so it is priced exhaustively in provider-pricing.ts;
+// bumping a model is a one-line change here.
+export const openaiModels = {
+ // macOS desktop computer-use Responses calls.
+ computerUse: "gpt-5.5",
+ // Developer UI inspection Responses calls.
+ debugInspection: "gpt-5.4",
+} as const;
+
+export type OpenAIRunModel = (typeof openaiModels)[keyof typeof openaiModels];