🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(model-bank): fill missing official cache prices (#20921)
YuTengjing862c3407fad4
diff --git a/.agents/skills/model-bank-metadata/scripts/apply-cutoffs.ts b/.agents/skills/model-bank-metadata/scripts/apply-cutoffs.tsindex 02e35b01268..6d4060987f0 100644--- a/.agents/skills/model-bank-metadata/scripts/apply-cutoffs.ts+++ b/.agents/skills/model-bank-metadata/scripts/apply-cutoffs.ts@@ -23,7 +23,10 @@ let touchedFiles = 0;let inserted = 0;const matchedIds = new Set<string>();-for (const file of readdirSync(dir).filter((f) => f.endsWith('.ts'))) {+for (const file of readdirSync(dir, { encoding: 'utf8', recursive: true }).filter(+ // Providers can be directories (e.g. google/) whose cards span several files.+ (f) => f.endsWith('.ts') && !f.endsWith('.test.ts'),+)) {const path = join(dir, file);const lines = readFileSync(path, 'utf8').split('\n');const out: string[] = [];diff --git a/.agents/skills/model-bank-metadata/scripts/apply-family.ts b/.agents/skills/model-bank-metadata/scripts/apply-family.tsindex 9975f2aaae2..afd7fc00c97 100644--- a/.agents/skills/model-bank-metadata/scripts/apply-family.ts+++ b/.agents/skills/model-bank-metadata/scripts/apply-family.ts@@ -9,7 +9,10 @@ const normalize = (id: string) => id.split('/').pop()!.toLowerCase();let inserted = 0;let touchedFiles = 0;-for (const file of readdirSync(dir).filter((f) => f.endsWith('.ts'))) {+for (const file of readdirSync(dir, { encoding: 'utf8', recursive: true }).filter(+ // Providers can be directories (e.g. google/) whose cards span several files.+ (f) => f.endsWith('.ts') && !f.endsWith('.test.ts'),+)) {const path = join(dir, file);const lines = readFileSync(path, 'utf8').split('\n');const out: string[] = [];diff --git a/.agents/skills/model-bank-metadata/scripts/extract-model-ids.ts b/.agents/skills/model-bank-metadata/scripts/extract-model-ids.tsindex 8d87f00e0c0..97035420229 100644--- a/.agents/skills/model-bank-metadata/scripts/extract-model-ids.ts+++ b/.agents/skills/model-bank-metadata/scripts/extract-model-ids.ts@@ -12,7 +12,10 @@ const dir = resolve('packages/model-bank/src/aiModels');const out = process.argv[2] || '/tmp/model-ids.json';const ids = new Set<string>();-for (const f of readdirSync(dir).filter((f) => f.endsWith('.ts'))) {+for (const f of readdirSync(dir, { encoding: 'utf8', recursive: true }).filter(+ // Providers can be directories (e.g. google/) whose cards span several files.+ (f) => f.endsWith('.ts') && !f.endsWith('.test.ts'),+)) {const mod = await import(join(dir, f));for (const m of mod.default || []) {if (!m?.id || m.type !== 'chat') continue;diff --git a/apps/server/src/services/agentQuota/__tests__/pricing.test.ts b/apps/server/src/services/agentQuota/__tests__/pricing.test.tsnew file mode 100644index 00000000000..caf6da7eac6--- /dev/null+++ b/apps/server/src/services/agentQuota/__tests__/pricing.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it } from 'vitest';++import { claudeModelPrice, codexModelPrice } from '../pricing';++describe('claudeModelPrice', () => {+ it('reads both cache-write TTL prices from a ttl lookup', () => {+ expect(claudeModelPrice('claude-fable-5-1')).toEqual({+ cacheRead: 0.25,+ cacheWrite1h: 20,+ cacheWrite5m: 12.5,+ input: 10,+ output: 50,+ });+ });++ it('returns null for a model the bank does not list', () => {+ expect(claudeModelPrice('claude-unknown')).toBeNull();+ });+});++describe('codexModelPrice', () => {+ it('leaves cache-write rates undefined for OpenAI models', () => {+ const price = codexModelPrice('gpt-6.1-sol');++ expect(price?.cacheWrite1h).toBeUndefined();+ expect(price?.cacheWrite5m).toBeUndefined();+ });+});diff --git a/apps/server/src/services/agentQuota/pricing.ts b/apps/server/src/services/agentQuota/pricing.tsindex 65fd35069e8..b392d22c35a 100644--- a/apps/server/src/services/agentQuota/pricing.ts+++ b/apps/server/src/services/agentQuota/pricing.ts@@ -4,16 +4,23 @@ import openaiModels from 'model-bank/openai';/*** $ per million tokens for a model, from the model bank. The bank lists the- * base input/output rates plus the cache-read and 5-minute cache-write rates- * when the provider has them (OpenAI has no cache-write tier, so it stays- * undefined); the 1-hour write rate is derived inside `computeTurnCostUsd`- * (2x base input) when not provided. Returns null for models the bank doesn't- * know — the caller should then store the tokens without a computed cost- * rather than guess a price.+ * base input/output rates plus the cache-read rate and, for Anthropic, the+ * cache-write rate — either one flat rate or a `ttl` lookup with `5m` / `1h`+ * prices (OpenAI has no cache-write tier, so it stays undefined). Any rate the+ * bank omits is derived inside `computeTurnCostUsd` from base input. Returns+ * null for models the bank doesn't know — the caller should then store the+ * tokens without a computed cost rather than guess a price.*/interface BankModelCard {id: string;- pricing?: { units?: { name: string; rate?: number; unit: string }[] };+ pricing?: {+ units?: {+ lookup?: { prices: Record<string, number> };+ name: string;+ rate?: number;+ unit: string;+ }[];+ };}const bankModelPrice = (@@ -24,10 +31,10 @@ const bankModelPrice = (const units = model?.pricing?.units;if (!units) return null;- const rate = (name: string) => {- const unit = units.find((u) => u.name === name && u.unit === 'millionTokens');- return unit && 'rate' in unit ? unit.rate : undefined;- };+ const findUnit = (name: string) =>+ units.find((u) => u.name === name && u.unit === 'millionTokens');+ const rate = (name: string) => findUnit(name)?.rate;+ const cacheWrite = findUnit('textInput_cacheWrite');const input = rate('textInput');const output = rate('textOutput');@@ -35,7 +42,8 @@ const bankModelPrice = (return {cacheRead: rate('textInput_cacheRead'),- cacheWrite5m: rate('textInput_cacheWrite'),+ cacheWrite1h: cacheWrite?.lookup?.prices['1h'],+ cacheWrite5m: cacheWrite?.lookup?.prices['5m'] ?? cacheWrite?.rate,input,output,};diff --git a/packages/model-bank/package.json b/packages/model-bank/package.jsonindex 4d024d867d8..77990467a2e 100644--- a/packages/model-bank/package.json+++ b/packages/model-bank/package.json@@ -37,7 +37,7 @@"./giteeai": "./src/aiModels/giteeai.ts","./github": "./src/aiModels/github.ts","./githubCopilot": "./src/aiModels/githubCopilot.ts",- "./google": "./src/aiModels/google.ts",+ "./google": "./src/aiModels/google/index.ts","./glmCodingPlan": "./src/aiModels/glmCodingPlan.ts","./groq": "./src/aiModels/groq.ts","./higress": "./src/aiModels/higress.ts",diff --git a/packages/model-bank/src/aiModels/__tests__/index.test.ts b/packages/model-bank/src/aiModels/__tests__/index.test.tsindex c250c9fd98d..1f5e2720508 100644--- a/packages/model-bank/src/aiModels/__tests__/index.test.ts+++ b/packages/model-bank/src/aiModels/__tests__/index.test.ts@@ -404,3 +404,85 @@ describe('subscription model catalogs', () => {expect(model?.settings?.extendParams).toContain('preserveThinking');});});++describe('Anthropic cache-write pricing', () => {+ it('lists both the 5-minute and 1-hour cache-write prices for flat-priced models', () => {+ // Official multipliers: a 5-minute write is 1.25x base input, a 1-hour write is 2x.+ // https://platform.claude.com/docs/en/about-claude/pricing+ const flatPriced = LOBE_DEFAULT_MODEL_LIST.filter(+ (m) =>+ m.providerId === ModelProvider.Anthropic &&+ m.pricing?.units.find((u) => u.name === 'textInput')?.strategy === 'fixed',+ );++ expect(flatPriced.map((m) => m.id)).toContain('claude-fable-5-1');++ for (const model of flatPriced) {+ const units = model.pricing!.units;+ const input = units.find((u) => u.name === 'textInput');+ const cacheWrite = units.find((u) => u.name === 'textInput_cacheWrite');+ const inputRate = input?.strategy === 'fixed' ? input.rate : NaN;++ expect({ id: model.id, unit: cacheWrite }).toEqual({+ id: model.id,+ unit: {+ lookup: {+ prices: { '1h': inputRate * 2, '5m': inputRate * 1.25 },+ pricingParams: ['ttl'],+ },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ });+ }+ });+});++describe('Google context-caching pricing', () => {+ // https://ai.google.dev/gemini-api/docs/pricing+ const units = (id: string) =>+ LOBE_DEFAULT_MODEL_LIST.find((m) => m.providerId === ModelProvider.Google && m.id === id)+ ?.pricing?.units;+ const storage = {+ lookup: { prices: { '1h': 1 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ };+ const fixed = (name: string, rate: number) => ({+ name,+ rate,+ strategy: 'fixed',+ unit: 'millionTokens',+ });++ it('prices Gemini 2.5 Pro cache reads by prompt length', () => {+ expect(units('gemini-2.5-pro')).toContainEqual({+ name: 'textInput_cacheRead',+ strategy: 'tiered',+ tiers: [+ { rate: 0.125, upTo: 200_000 },+ { rate: 0.25, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ });+ });++ it.each([+ ['gemini-2.5-flash', 0.03, 0.1],+ ['gemini-2.5-flash-lite', 0.01, 0.03],+ ])('lists text and audio cache reads plus storage for %s', (id, text, audio) => {+ expect(units(id)).toEqual(+ expect.arrayContaining([+ fixed('textInput_cacheRead', text),+ fixed('audioInput_cacheRead', audio),+ storage,+ ]),+ );+ });++ it('lists the audio cache read for Gemini 3 Flash Preview', () => {+ expect(units('gemini-3-flash-preview')).toContainEqual(fixed('audioInput_cacheRead', 0.1));+ });+});diff --git a/packages/model-bank/src/aiModels/anthropic.ts b/packages/model-bank/src/aiModels/anthropic.tsindex d797985444b..650bd555680 100644--- a/packages/model-bank/src/aiModels/anthropic.ts+++ b/packages/model-bank/src/aiModels/anthropic.ts@@ -96,7 +96,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 4, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 20, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 5, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 8, '5m': 5 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-09-22',@@ -133,7 +138,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 0.25, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 10, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 50, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 12.5, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 20, '5m': 12.5 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-09-01',@@ -170,7 +180,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 1, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 10, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 50, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 12.5, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 20, '5m': 12.5 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-06-09',@@ -204,7 +219,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 25, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 6.25, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 10, '5m': 6.25 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-07-24',@@ -233,15 +253,20 @@ const anthropicChatModels: AIChatModelCard[] = [id: 'claude-sonnet-5',knowledgeCutoff: '2026-01',maxOutput: 128_000,- // Introductory pricing, in effect through 2026-08-31. From 2026-09-01 standard rates apply:- // input 3 / output 15 / cacheRead 0.3 / cacheWrite 3.75 (per million tokens).- // See https://platform.claude.com/docs/en/about-claude/pricing+ // The $2 / $10 launch pricing became the standard price; the increase to $3 / $15 that was+ // scheduled for 2026-09-01 did not happen.+ // https://platform.claude.com/docs/en/about-claude/pricingpricing: {units: [{ name: 'textInput_cacheRead', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 2, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 10, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 4, '5m': 2.5 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-06-30',@@ -275,7 +300,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 25, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 6.25, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 10, '5m': 6.25 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-05-28',@@ -309,7 +339,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput_cacheRead', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 25, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 6.25, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 10, '5m': 6.25 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2026-04-16',@@ -458,7 +493,12 @@ const anthropicChatModels: AIChatModelCard[] = [{ name: 'textInput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textOutput', rate: 15, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput_cacheRead', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput_cacheWrite', rate: 3.75, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 6, '5m': 3.75 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },],},releasedAt: '2025-09-29',diff --git a/packages/model-bank/src/aiModels/google/gemini25.ts b/packages/model-bank/src/aiModels/google/gemini25.tsnew file mode 100644index 00000000000..f05eb4f7605--- /dev/null+++ b/packages/model-bank/src/aiModels/google/gemini25.ts@@ -0,0 +1,208 @@+import type { AIChatModelCard } from '../../types';++/**+ * Gemini 2.5 chat models, listed after the newer Gemini generations in `./index.ts`.+ */+export const gemini25ChatModels: AIChatModelCard[] = [+ {+ abilities: {+ audio: true,+ functionCall: true,+ reasoning: true,+ search: true,+ video: true,+ vision: true,+ },+ contextWindowTokens: 1_048_576 + 65_536,+ description:+ 'Gemini 2.5 Pro is Google’s most advanced reasoning model, able to reason over code, math, and STEM problems and analyze large datasets, codebases, and documents with long context.',+ displayName: 'Gemini 2.5 Pro',+ family: 'gemini',+ generation: 'gemini-2.5',+ id: 'gemini-2.5-pro',+ knowledgeCutoff: '2025-01',+ maxOutput: 65_536,+ pricing: {+ units: [+ {+ name: 'textInput_cacheRead',+ strategy: 'tiered',+ tiers: [+ { rate: 0.125, upTo: 200_000 },+ { rate: 0.25, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ name: 'textInput',+ strategy: 'tiered',+ tiers: [+ { rate: 1.25, upTo: 200_000 },+ { rate: 2.5, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ name: 'imageInput',+ strategy: 'tiered',+ tiers: [+ { rate: 1.25, upTo: 200_000 },+ { rate: 2.5, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ name: 'videoInput',+ strategy: 'tiered',+ tiers: [+ { rate: 1.25, upTo: 200_000 },+ { rate: 2.5, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ name: 'audioInput',+ strategy: 'tiered',+ tiers: [+ { rate: 1.25, upTo: 200_000 },+ { rate: 2.5, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ name: 'textOutput',+ strategy: 'tiered',+ tiers: [+ { rate: 10, upTo: 200_000 },+ { rate: 15, upTo: 'infinity' },+ ],+ unit: 'millionTokens',+ },+ {+ lookup: { prices: { '1h': 4.5 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ ],+ },+ releasedAt: '2025-06-17',+ settings: {+ extendParams: ['thinkingBudget', 'urlContext'],+ searchImpl: 'params',+ searchProvider: 'google',+ },+ type: 'chat',+ },+ {+ abilities: {+ audio: true,+ functionCall: true,+ reasoning: true,+ search: true,+ video: true,+ vision: true,+ },+ contextWindowTokens: 1_048_576 + 65_536,+ description: 'Gemini 2.5 Flash is Google’s best-value model with full capabilities.',+ displayName: 'Gemini 2.5 Flash',+ family: 'gemini',+ generation: 'gemini-2.5',+ id: 'gemini-2.5-flash',+ knowledgeCutoff: '2025-01',+ maxOutput: 65_536,+ pricing: {+ units: [+ { name: 'textInput_cacheRead', rate: 0.03, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'audioInput_cacheRead', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'videoInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'audioInput', rate: 1, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 1 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ ],+ },+ releasedAt: '2025-06-17',+ settings: {+ extendParams: ['thinkingBudget', 'urlContext'],+ searchImpl: 'params',+ searchProvider: 'google',+ },+ type: 'chat',+ },+ {+ abilities: {+ imageOutput: true,+ vision: true,+ },+ contextWindowTokens: 65_536 + 32_768,+ description:+ 'Nano Banana is Google’s newest, fastest, and most efficient native multimodal model, enabling conversational image generation and editing.',+ displayName: 'Nano Banana',+ family: 'gemini',+ generation: 'gemini-2.5',+ id: 'gemini-2.5-flash-image',+ knowledgeCutoff: '2025-06',+ maxOutput: 32_768,+ pricing: {+ approximatePricePerImage: 0.039,+ units: [+ { name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },+ ],+ },+ releasedAt: '2025-08-26',+ settings: {+ extendParams: ['imageAspectRatio'],+ },+ type: 'chat',+ },+ {+ abilities: {+ audio: true,+ functionCall: true,+ reasoning: true,+ search: true,+ video: true,+ vision: true,+ },+ contextWindowTokens: 1_048_576 + 65_536,+ description:+ 'Gemini 2.5 Flash-Lite is Google’s smallest, best-value model, designed for large-scale use.',+ displayName: 'Gemini 2.5 Flash-Lite',+ family: 'gemini',+ generation: 'gemini-2.5',+ id: 'gemini-2.5-flash-lite',+ knowledgeCutoff: '2025-01',+ maxOutput: 65_536,+ pricing: {+ units: [+ { name: 'textInput_cacheRead', rate: 0.01, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'audioInput_cacheRead', rate: 0.03, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textInput', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textOutput', rate: 0.4, strategy: 'fixed', unit: 'millionTokens' },+ {+ lookup: { prices: { '1h': 1 }, pricingParams: ['ttl'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ ],+ },+ releasedAt: '2025-07-22',+ settings: {+ extendParams: ['thinkingBudget', 'urlContext'],+ searchImpl: 'params',+ searchProvider: 'google',+ },+ type: 'chat',+ },+];diff --git a/packages/model-bank/src/aiModels/google.ts b/packages/model-bank/src/aiModels/google/index.tssimilarity index 84%rename from packages/model-bank/src/aiModels/google.tsrename to packages/model-bank/src/aiModels/google/index.tsindex 23352e79cd6..9c0ca649203 100644--- a/packages/model-bank/src/aiModels/google.ts+++ b/packages/model-bank/src/aiModels/google/index.ts@@ -3,9 +3,10 @@ import {nanoBanana2Parameters,nanoBananaParameters,nanoBananaProParameters,-} from '../const/imageParameters';-import type { ModelParamsSchema } from '../standard-parameters';-import type { AIChatModelCard, AIImageModelCard, AIVideoModelCard } from '../types';+} from '../../const/imageParameters';+import type { ModelParamsSchema } from '../../standard-parameters';+import type { AIChatModelCard, AIImageModelCard, AIVideoModelCard } from '../../types';+import { gemini25ChatModels } from './gemini25';/*** gemini implicit caching not extra cost@@ -673,6 +674,7 @@ const googleChatModels: AIChatModelCard[] = [pricing: {units: [{ name: 'textInput_cacheRead', rate: 0.05, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'audioInput_cacheRead', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },{ name: 'textInput', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'imageInput', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },{ name: 'videoInput', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },@@ -783,193 +785,7 @@ const googleChatModels: AIChatModelCard[] = [},type: 'chat',},- {- abilities: {- audio: true,- functionCall: true,- reasoning: true,- search: true,- video: true,- vision: true,- },- contextWindowTokens: 1_048_576 + 65_536,- description:- 'Gemini 2.5 Pro is Google’s most advanced reasoning model, able to reason over code, math, and STEM problems and analyze large datasets, codebases, and documents with long context.',- displayName: 'Gemini 2.5 Pro',- family: 'gemini',- generation: 'gemini-2.5',- id: 'gemini-2.5-pro',- knowledgeCutoff: '2025-01',- maxOutput: 65_536,- pricing: {- units: [- {- name: 'textInput_cacheRead',- strategy: 'tiered',- tiers: [- { rate: 0.31, upTo: 200_000 },- { rate: 0.625, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- name: 'textInput',- strategy: 'tiered',- tiers: [- { rate: 1.25, upTo: 200_000 },- { rate: 2.5, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- name: 'imageInput',- strategy: 'tiered',- tiers: [- { rate: 1.25, upTo: 200_000 },- { rate: 2.5, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- name: 'videoInput',- strategy: 'tiered',- tiers: [- { rate: 1.25, upTo: 200_000 },- { rate: 2.5, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- name: 'audioInput',- strategy: 'tiered',- tiers: [- { rate: 1.25, upTo: 200_000 },- { rate: 2.5, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- name: 'textOutput',- strategy: 'tiered',- tiers: [- { rate: 10, upTo: 200_000 },- { rate: 15, upTo: 'infinity' },- ],- unit: 'millionTokens',- },- {- lookup: { prices: { '1h': 4.5 }, pricingParams: ['ttl'] },- name: 'textInput_cacheWrite',- strategy: 'lookup',- unit: 'millionTokens',- },- ],- },- releasedAt: '2025-06-17',- settings: {- extendParams: ['thinkingBudget', 'urlContext'],- searchImpl: 'params',- searchProvider: 'google',- },- type: 'chat',- },- {- abilities: {- audio: true,- functionCall: true,- reasoning: true,- search: true,- video: true,- vision: true,- },- contextWindowTokens: 1_048_576 + 65_536,- description: 'Gemini 2.5 Flash is Google’s best-value model with full capabilities.',- displayName: 'Gemini 2.5 Flash',- family: 'gemini',- generation: 'gemini-2.5',- id: 'gemini-2.5-flash',- knowledgeCutoff: '2025-01',- maxOutput: 65_536,- pricing: {- units: [- { name: 'textInput_cacheRead', rate: 0.075, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'imageInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'videoInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'audioInput', rate: 1, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },- ],- },- releasedAt: '2025-06-17',- settings: {- extendParams: ['thinkingBudget', 'urlContext'],- searchImpl: 'params',- searchProvider: 'google',- },- type: 'chat',- },- {- abilities: {- imageOutput: true,- vision: true,- },- contextWindowTokens: 65_536 + 32_768,- description:- 'Nano Banana is Google’s newest, fastest, and most efficient native multimodal model, enabling conversational image generation and editing.',- displayName: 'Nano Banana',- family: 'gemini',- generation: 'gemini-2.5',- id: 'gemini-2.5-flash-image',- knowledgeCutoff: '2025-06',- maxOutput: 32_768,- pricing: {- approximatePricePerImage: 0.039,- units: [- { name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'imageInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },- { name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },- ],- },- releasedAt: '2025-08-26',- settings: {- extendParams: ['imageAspectRatio'],- },- type: 'chat',- },- {- abilities: {- audio: true,- functionCall: true,- reasoning: true,- search: true,- video: true,- vision: true,- },- contextWindowTokens: 1_048_576 + 65_536,- description:- 'Gemini 2.5 Flash-Lite is Google’s smallest, best-value model, designed for large-scale use.',- displayName: 'Gemini 2.5 Flash-Lite',- family: 'gemini',- generation: 'gemini-2.5',- id: 'gemini-2.5-flash-lite',- knowledgeCutoff: '2025-01',- maxOutput: 65_536,- pricing: {- units: [- { name: 'textInput_cacheRead', rate: 0.025, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textInput', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },- { name: 'textOutput', rate: 0.4, strategy: 'fixed', unit: 'millionTokens' },- ],- },- releasedAt: '2025-07-22',- settings: {- extendParams: ['thinkingBudget', 'urlContext'],- searchImpl: 'params',- searchProvider: 'google',- },- type: 'chat',- },+ ...gemini25ChatModels,];// Common parameters for Imagen modelsdiff --git a/packages/model-runtime/src/core/anthropicCompatibleFactory/resolveCacheTTL.ts b/packages/model-runtime/src/core/anthropicCompatibleFactory/resolveCacheTTL.tsindex 458cb554c0d..e6d98039d2a 100644--- a/packages/model-runtime/src/core/anthropicCompatibleFactory/resolveCacheTTL.ts+++ b/packages/model-runtime/src/core/anthropicCompatibleFactory/resolveCacheTTL.ts@@ -4,7 +4,8 @@ import type { ChatStreamPayload } from '../../types';type CacheTTL = Anthropic.Messages.CacheControlEphemeral['ttl'];-const DEFAULT_CACHE_TTL = '5m' as const;+/** Anthropic caches for 5 minutes unless a request asks for `1h`. */+export const DEFAULT_CACHE_TTL = '5m' as const;/*** Resolves cache TTL from Anthropic payload or request settings* Returns the first valid TTL found in system messages or content blocksdiff --git a/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.lookupDefaults.test.ts b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.lookupDefaults.test.tsnew file mode 100644index 00000000000..914e98efc5e--- /dev/null+++ b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.lookupDefaults.test.ts@@ -0,0 +1,49 @@+import type { ModelTokensUsage } from '@lobechat/types';+import type { Pricing } from 'model-bank';+import anthropicChatModels from 'model-bank/anthropic';+import { describe, expect, it } from 'vitest';++import { computeChatCost } from './computeChatCost';++const cacheWriteOf = (result: ReturnType<typeof computeChatCost>) =>+ result?.breakdown.find((item) => item.unit.name === 'textInput_cacheWrite');++describe('computeChatCost lookup defaults', () => {+ it('bills a cache write at the 5-minute price when the caller resolves no TTL', () => {+ // OpenAI-compatible providers fall back to the Anthropic card without passing a TTL.+ const pricing = anthropicChatModels.find((model) => model.id === 'claude-fable-5-1')?.pricing;+ const usage: ModelTokensUsage = { inputWriteCacheTokens: 1_000_000 };++ const result = computeChatCost(pricing, usage);++ expect(result?.issues).toEqual([]);+ expect(cacheWriteOf(result)).toMatchObject({ credits: 12_500_000, lookupKey: '5m' });+ });++ it('keeps pricing an explicit 1-hour TTL at the 1-hour price', () => {+ const pricing = anthropicChatModels.find((model) => model.id === 'claude-fable-5-1')?.pricing;+ const usage: ModelTokensUsage = { inputWriteCacheTokens: 1_000_000 };++ const result = computeChatCost(pricing, usage, { lookupParams: { ttl: '1h' } });++ expect(cacheWriteOf(result)).toMatchObject({ credits: 20_000_000, lookupKey: '1h' });+ });++ it('still reports a missing non-TTL lookup param without billing it', () => {+ const pricing: Pricing = {+ units: [+ {+ lookup: { prices: { high: 2, low: 1 }, pricingParams: ['quality'] },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ ],+ };++ const result = computeChatCost(pricing, { inputWriteCacheTokens: 1_000_000 });++ expect(result?.issues[0]?.reason).toContain('Missing lookup params: quality');+ expect(cacheWriteOf(result)?.credits).toBe(0);+ });+});diff --git a/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.ts b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.tsindex f801dac7faf..edb14ad07f4 100644--- a/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.ts+++ b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.ts@@ -292,8 +292,8 @@ describe('computeChatPricing', () => {// Verify cached tokensconst cached = breakdown.find((item) => item.unit.name === 'textInput_cacheRead');expect(cached?.quantity).toBe(253_891);- expect(cached?.credits).toBe(158_682); // ceil(253891 * 0.625) = 158682- expect(cached?.segments).toEqual([{ quantity: 253_891, rate: 0.625, credits: 158_681.875 }]);+ expect(cached?.credits).toBe(63_473); // ceil(253891 * 0.25) = 63473+ expect(cached?.segments).toEqual([{ quantity: 253_891, rate: 0.25, credits: 63_472.75 }]);// Verify input cache miss tokensconst input = breakdown.find((item) => item.unit.name === 'textInput');@@ -308,8 +308,8 @@ describe('computeChatPricing', () => {expect(output?.segments).toEqual([{ quantity: 3_063, rate: 15, credits: 45_945 }]);// Verify totals- expect(totalCredits).toBe(215_315); // 158682 + 10688 + 45945 = 215315- expect(totalCost).toBeCloseTo(0.215315, 6);+ expect(totalCredits).toBe(120_106); // 63473 + 10688 + 45945 = 120106+ expect(totalCost).toBeCloseTo(0.120106, 6);});it('supports multi-modal fixed units for Gemini 2.5 Flash Image Preview', () => {@@ -899,8 +899,8 @@ describe('computeChatPricing', () => {// Verify cached tokensconst cached = breakdown.find((item) => item.unit.name === 'textInput_cacheRead');expect(cached?.quantity).toBe(257_955);- expect(cached?.credits).toBe(161_222); // ceil(257955 * 0.625) = 161222- expect(cached?.segments).toEqual([{ quantity: 257_955, rate: 0.625, credits: 161_221.875 }]);+ expect(cached?.credits).toBe(64_489); // ceil(257955 * 0.25) = 64489+ expect(cached?.segments).toEqual([{ quantity: 257_955, rate: 0.25, credits: 64_488.75 }]);// Verify input cache miss tokensconst input = breakdown.find((item) => item.unit.name === 'textInput');@@ -915,8 +915,8 @@ describe('computeChatPricing', () => {expect(output?.segments).toEqual([{ quantity: 1_744, rate: 15, credits: 26_160 }]);// Verify totals- expect(totalCredits).toBe(199_895); // 161222 + 12513 + 26160 = 199895- expect(totalCost).toBeCloseTo(0.199895, 6);+ expect(totalCredits).toBe(103_162); // 64489 + 12513 + 26160 = 103162+ expect(totalCost).toBeCloseTo(0.103162, 6);});it('bills tool-use (grounding) tokens at textInput rate when no explicit cache', () => {@@ -1312,7 +1312,7 @@ describe('computeChatPricing', () => {expect(cacheWrite?.credits).toBe(0); // No credits when lookup fails});- it('handles lookup pricing with missing lookup params and adds issue', () => {+ it('prices a cache write without lookup params at the default TTL', () => {const pricing = anthropicChatModels.find((model: { id: string }) => model.id === 'claude-opus-4-6',)?.pricing;@@ -1324,20 +1324,19 @@ describe('computeChatPricing', () => {outputTextTokens: 500,};- // Don't provide lookup params at all+ // Don't provide lookup params at all: the write is priced at the default 5-minute TTLconst result = computeChatCost(pricing, usage);expect(result).toBeDefined();- expect(result?.issues).toHaveLength(1);- expect(result?.issues[0].reason).toContain('Missing lookup params');- expect(result?.issues[0].reason).toContain('ttl');+ expect(result?.issues).toHaveLength(0);const cacheWrite = result?.breakdown.find((item) => item.unit.name === 'textInput_cacheWrite',);- expect(cacheWrite?.credits).toBe(0); // No credits when lookup params missing+ expect(cacheWrite?.lookupKey).toBe('5m');+ expect(cacheWrite?.credits).toBe(1_875);});- it('handles lookup pricing with undefined lookup params and adds issue', () => {+ it('prices a cache write with a null TTL at the default TTL', () => {const pricing = anthropicChatModels.find((model: { id: string }) => model.id === 'claude-opus-4-6',)?.pricing;@@ -1349,17 +1348,16 @@ describe('computeChatPricing', () => {outputTextTokens: 500,};- // Provide null value for TTL (simulating missing/invalid value)+ // A null TTL also falls back to the default 5-minute priceconst result = computeChatCost(pricing, usage, { lookupParams: { ttl: null as any } });expect(result).toBeDefined();- expect(result?.issues).toHaveLength(1);- expect(result?.issues[0].reason).toContain('Missing lookup params');- expect(result?.issues[0].reason).toContain('ttl');+ expect(result?.issues).toHaveLength(0);const cacheWrite = result?.breakdown.find((item) => item.unit.name === 'textInput_cacheWrite',);- expect(cacheWrite?.credits).toBe(0); // No credits when lookup params undefined+ expect(cacheWrite?.lookupKey).toBe('5m');+ expect(cacheWrite?.credits).toBe(1_875);});describe('Claude Haiku 5.5 prompt-length pricing', () => {diff --git a/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.ts b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.tsindex eb4371380d1..32f728b16b2 100644--- a/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.ts+++ b/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.ts@@ -10,6 +10,8 @@ import type {TieredPricingUnit,} from 'model-bank';+import { DEFAULT_CACHE_TTL } from '../../anthropicCompatibleFactory/resolveCacheTTL';+const log = debug('lobe-cost:computeChatPricing');export interface PricingUnitBreakdown {@@ -311,7 +313,11 @@ const resolveLookupKey = (const missingParams: string[] = [];const params = unit.lookup.pricingParams.map((param) => {- const source = options?.lookupParams?.[param];+ // Paths that never resolve a TTL (e.g. OpenAI-compatible providers falling back to an+ // Anthropic card) still write to the cache, which the API does for its default 5 minutes.+ const source =+ options?.lookupParams?.[param] ??+ (param === 'ttl' && DEFAULT_CACHE_TTL in unit.lookup.prices ? DEFAULT_CACHE_TTL : undefined);if (source === undefined || source === null) {missingParams.push(param);return 'undefined';diff --git a/packages/utils/src/pricing.test.ts b/packages/utils/src/pricing.test.tsindex ab6bab9f788..7817d838915 100644--- a/packages/utils/src/pricing.test.ts+++ b/packages/utils/src/pricing.test.ts@@ -191,6 +191,28 @@ describe('pricing utilities (new)', () => {});});+ describe('TTL cache-write lookups', () => {+ it('display the default 5-minute price instead of the alphabetically first 1-hour price', () => {+ const pricing: Pricing = {+ units: [+ {+ lookup: {+ originalPrices: { '1h': 24, '5m': 15 },+ prices: { '1h': 20, '5m': 12.5 },+ pricingParams: ['ttl'],+ },+ name: 'textInput_cacheWrite',+ strategy: 'lookup',+ unit: 'millionTokens',+ },+ ],+ };++ expect(getWriteCacheInputUnitRate(pricing)).toBe(12.5);+ expect(getOriginalUnitRateByName(pricing, 'textInput_cacheWrite')).toBe(15);+ });+ });+describe('wrapper helpers', () => {it('return the same values as getUnitRateByName for each unit', () => {const pricing: Pricing = {diff --git a/packages/utils/src/pricing.ts b/packages/utils/src/pricing.tsindex 944fd17e82f..48fc957023c 100644--- a/packages/utils/src/pricing.ts+++ b/packages/utils/src/pricing.ts@@ -1,10 +1,29 @@-import type { Pricing, PricingUnit, PricingUnitName } from 'model-bank';+import type { LookupPricingUnit, Pricing, PricingUnit, PricingUnitName } from 'model-bank';++/**+ * Cache TTL a request uses unless it asks for a longer one; Anthropic's prompt caching+ * defaults to 5 minutes, and cache-write lookups key their prices by `ttl`.+ */+const DEFAULT_CACHE_TTL_KEY = '5m';++/**+ * Lookup key whose price represents the unit in a single-price display.+ * Keys are sorted alphabetically in model-bank, so the first key of a TTL lookup is `1h`;+ * showing it would quote the 1-hour cache write as the model's cache-write price.+ */+const getDisplayLookupKey = (unit: LookupPricingUnit): string | undefined => {+ const prices = unit.lookup?.prices || {};+ if (unit.lookup?.pricingParams?.includes('ttl') && DEFAULT_CACHE_TTL_KEY in prices) {+ return DEFAULT_CACHE_TTL_KEY;+ }+ return Object.keys(prices)[0];+};/*** Internal helper to extract the displayed unit rate from a pricing unit by strategy* - fixed: rate* - tiered: tiers[0].rate- * - lookup: first price value+ * - lookup: the default-TTL (`5m`) price for TTL lookups, otherwise the first price value*/const getRateFromUnit = (unit: PricingUnit): number | undefined => {switch (unit.strategy) {@@ -15,8 +34,8 @@ const getRateFromUnit = (unit: PricingUnit): number | undefined => {return unit.tiers?.[0]?.rate;}case 'lookup': {- const prices = Object.values(unit.lookup?.prices || {});- return prices[0];+ const key = getDisplayLookupKey(unit);+ return key ? unit.lookup.prices[key] : undefined;}default: {return undefined;@@ -33,8 +52,8 @@ const getOriginalRateFromUnit = (unit: PricingUnit): number | undefined => {return unit.tiers?.[0]?.originalRate;}case 'lookup': {- const firstKey = Object.keys(unit.lookup?.prices || {})[0];- return firstKey ? unit.lookup.originalPrices?.[firstKey] : undefined;+ const key = getDisplayLookupKey(unit);+ return key ? unit.lookup.originalPrices?.[key] : undefined;}default: {return undefined;