diff --git a/src/backend/drivers/ai-chat/providers/minimax/models.ts b/src/backend/drivers/ai-chat/providers/minimax/models.ts index 92167fc0b..e7098f0cd 100644 --- a/src/backend/drivers/ai-chat/providers/minimax/models.ts +++ b/src/backend/drivers/ai-chat/providers/minimax/models.ts @@ -18,9 +18,8 @@ */ import type { IChatModel } from '../../types.js'; +import { usdPerMToken } from '../../utils/pricing.js'; -const CENTS_PER_USD = 100; -const MTOK = 1_000_000; const CONTEXT_WINDOW = 204_800; const MAX_OUTPUT_TOKENS = 196_608; @@ -28,17 +27,6 @@ type MiniMaxChatModel = IChatModel & { apiModel: string; }; -const usdPerMToken = ( - inputUsd: number, - outputUsd: number, - cachedReadUsd = 0, -) => ({ - tokens: MTOK, - prompt_tokens: inputUsd * CENTS_PER_USD, - completion_tokens: outputUsd * CENTS_PER_USD, - cached_tokens: cachedReadUsd * CENTS_PER_USD, -}); - const minimaxModel = ( apiModel: string, name: string, diff --git a/src/backend/drivers/ai-chat/providers/zai/models.ts b/src/backend/drivers/ai-chat/providers/zai/models.ts index d82239403..e1070b415 100644 --- a/src/backend/drivers/ai-chat/providers/zai/models.ts +++ b/src/backend/drivers/ai-chat/providers/zai/models.ts @@ -18,22 +18,10 @@ */ import type { IChatModel } from '../../types.js'; +import { usdPerMToken } from '../../utils/pricing.js'; -const CENTS_PER_USD = 100; -const MTOK = 1_000_000; const K = 1_000; -const usdPerMToken = ( - inputUsd: number, - outputUsd: number, - cachedInputUsd = 0, -) => ({ - tokens: MTOK, - prompt_tokens: inputUsd * CENTS_PER_USD, - completion_tokens: outputUsd * CENTS_PER_USD, - cached_tokens: cachedInputUsd * CENTS_PER_USD, -}); - const textModel = ( id: string, name: string, diff --git a/src/backend/drivers/ai-chat/utils/pricing.ts b/src/backend/drivers/ai-chat/utils/pricing.ts new file mode 100644 index 000000000..ad1d63faa --- /dev/null +++ b/src/backend/drivers/ai-chat/utils/pricing.ts @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2024-present Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import type { ModelCost } from '../types.js'; + +const CENTS_PER_USD = 100; +const MTOK = 1_000_000; + +/** + * Builds a `costs` block (currency `usd-cents`, per million tokens) from + * per-million-token USD prices. Providers list pricing in USD/MTok, so this + * keeps the source numbers readable while emitting the cents-based shape the + * driver expects. + */ +export const usdPerMToken = ( + inputUsd: number, + outputUsd: number, + cachedReadUsd = 0, +): ModelCost => ({ + tokens: MTOK, + prompt_tokens: inputUsd * CENTS_PER_USD, + completion_tokens: outputUsd * CENTS_PER_USD, + cached_tokens: cachedReadUsd * CENTS_PER_USD, +});