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:
2026-10-30 17:21:30 +02:00
co-authored by Claude Opus 5.5
parent 160ff3b927
commit ae7e10844d
12 changed files with 131 additions and 26 deletions
+12 -5
View File
@@ -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)) };
+21
View File
@@ -0,0 +1,21 @@
/**
* The Claude models Settings → AI offers, with Anthropic's list prices in US dollars per million
* tokens (prompts under 100K tokens — the Hub refuses anything near that). Anthropic's API doesn't
* publish prices, so they're kept here: choosing a model fills in its prices, which stay editable
* in case Anthropic changes them before a Hub release does.
*
* Prices as of October 2026. Cache writes (5-minute) cost 1.25× the input price for every model;
* cache reads vary, so each model gives its own.
*/
const AI_MODELS = [
{ id: 'claude-sonnet-5-5', label: 'Claude Sonnet 5.5', inputUsd: 2, outputUsd: 10, cacheReadUsd: 0.2, note: 'The default. Chosen after the October 2026 trial: right on report figures, feedback counts and message spelling.' },
{ id: 'claude-haiku-5-5', label: 'Claude Haiku 5.5', inputUsd: 0.1, outputUsd: 0.5, cacheReadUsd: 0.01, note: 'About 15× cheaper; made some factual and spelling mistakes in the trial.' },
{ id: 'claude-opus-5-5', label: 'Claude Opus 5.5', inputUsd: 4, outputUsd: 20, cacheReadUsd: 0.2, note: 'The most capable of the three, at twice Sonnet\'s price.' },
];
const DEFAULT_AI_MODEL = AI_MODELS[0];
const findModel = id => AI_MODELS.find(m => m.id === id) || null;
module.exports = { AI_MODELS, DEFAULT_AI_MODEL, findModel };
+6 -3
View File
@@ -1,5 +1,6 @@
const prisma = require('../config/db');
const { encrypt, decrypt } = require('./crypto');
const { DEFAULT_AI_MODEL } = require('./aiModels');
// Hub settings Joshua edits on the Settings page, with their defaults.
const DEFAULTS = {
@@ -26,10 +27,12 @@ const DEFAULTS = {
release_sync_error: '',
// AI for Cross Events 2.0 (utils/ai.js). Off until a key and the exchange rate are set.
ai_api_key: '',
ai_model: 'claude-haiku-5-5',
// One of utils/aiModels.js, or another model ID typed in.
ai_model: DEFAULT_AI_MODEL.id,
// US dollars per million tokens, for prompts under 100K tokens (the Hub refuses bigger ones).
ai_input_usd_per_mtok: '0.10',
ai_output_usd_per_mtok: '0.50',
// Filled in from utils/aiModels.js when a model is chosen; blank means the built-in price.
ai_input_usd_per_mtok: String(DEFAULT_AI_MODEL.inputUsd),
ai_output_usd_per_mtok: String(DEFAULT_AI_MODEL.outputUsd),
// Rand per US dollar.
ai_usd_zar: '',
// Default markup on the real cost, in %; a licence can override it.