Sonnet 5.5 as the default AI model, and a model list with prices (1.6.1)
Settings -> AI picks the model from a list (utils/aiModels.js: Sonnet, Haiku, Opus 5.5 with list prices) or takes another model ID; choosing one fills in its prices. Blank prices use the built-in ones, and cache reads are metered at each model's own price. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-5
@@ -15,10 +15,12 @@
|
||||
const Anthropic = require('@anthropic-ai/sdk');
|
||||
const prisma = require('../config/db');
|
||||
const { getSettings, aiApiKey } = require('./settings');
|
||||
const { findModel } = require('./aiModels');
|
||||
|
||||
// South African time (UTC+2, no daylight saving): the month the cap belongs to.
|
||||
const SAST_MS = 2 * 60 * 60 * 1000;
|
||||
// Cache writes cost 1.25× the input price, cache reads 0.1×.
|
||||
// Cache writes cost 1.25× the input price; reads are priced per model (utils/aiModels.js), 0.1×
|
||||
// the input price for a model the Hub doesn't know.
|
||||
const CACHE_WRITE = 1.25;
|
||||
const CACHE_READ = 0.1;
|
||||
// Prompts are priced higher from 100K tokens, so the Hub refuses anything close to it.
|
||||
@@ -46,22 +48,27 @@ function renewsOn(date = new Date()) {
|
||||
|
||||
/**
|
||||
* Prices for a call, or null when the Hub's AI isn't set up (no key or no exchange rate).
|
||||
* Blank prices use the built-in ones for the model (utils/aiModels.js); cache reads always do,
|
||||
* falling back to 0.1× the input price for a model the Hub doesn't know.
|
||||
* `licence.aiMarkupPercent` overrides the Hub's default markup.
|
||||
*/
|
||||
function pricing(settings, licence, hasKey) {
|
||||
const inUsd = parseFloat(settings.ai_input_usd_per_mtok);
|
||||
const outUsd = parseFloat(settings.ai_output_usd_per_mtok);
|
||||
const known = findModel(settings.ai_model);
|
||||
const price = (value, builtIn) => (value != null && String(value).trim() !== '' ? parseFloat(value) : builtIn ?? NaN);
|
||||
const inUsd = price(settings.ai_input_usd_per_mtok, known?.inputUsd);
|
||||
const outUsd = price(settings.ai_output_usd_per_mtok, known?.outputUsd);
|
||||
const usdZar = parseFloat(settings.ai_usd_zar);
|
||||
const markup = licence?.aiMarkupPercent ?? parseInt(settings.ai_markup_percent, 10);
|
||||
if (!hasKey || !settings.ai_model || !(inUsd >= 0) || !(outUsd > 0) || !(usdZar > 0) || !(markup >= 0)) return null;
|
||||
return { model: settings.ai_model, inUsd, outUsd, usdZar, markup };
|
||||
const cacheReadUsd = known && known.inputUsd === inUsd ? known.cacheReadUsd : inUsd * CACHE_READ;
|
||||
return { model: settings.ai_model, inUsd, outUsd, cacheReadUsd, usdZar, markup };
|
||||
}
|
||||
|
||||
/** Real and charged cost of some usage, in millicents (rounded up). */
|
||||
function costOf(usage, price) {
|
||||
const usd = ((usage.inputTokens || 0) * price.inUsd
|
||||
+ (usage.cacheWriteTokens || 0) * price.inUsd * CACHE_WRITE
|
||||
+ (usage.cacheReadTokens || 0) * price.inUsd * CACHE_READ
|
||||
+ (usage.cacheReadTokens || 0) * (price.cacheReadUsd ?? price.inUsd * CACHE_READ)
|
||||
+ (usage.outputTokens || 0) * price.outUsd) / 1e6;
|
||||
const real = usd * price.usdZar * 100 * 1000;
|
||||
return { real: Math.ceil(real), charged: Math.ceil(real * (1 + price.markup / 100)) };
|
||||
|
||||
Reference in New Issue
Block a user