Make usdPerMToken a pricing utility

This commit is contained in:
ProgrammerIn-wonderland
2026-05-29 13:34:37 -04:00
parent 0bfb8e3383
commit d11d73e07a
3 changed files with 42 additions and 26 deletions
@@ -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,
@@ -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,
@@ -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 <https://www.gnu.org/licenses/>.
*/
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,
});