mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
Use regular Gemini model prices throughout launch promotions
This commit is contained in:
1 parent
69009706b6
commit
62cb99b8a8
9 files changed
+98
-149
No files matched your search
@@ -112,7 +112,7 @@ const makeProvider = (
|
||||
) => new GeminiChatProvider(config, server.services.metering);
|
||||
|
||||
const ARGON = GEMINI_MODELS.find((m) => m.id === 'gemini-4-argon')!;
|
||||
const LAUNCH = new Date('2026-10-14T12:00:00Z');
|
||||
const REQUEST_TIME = new Date('2026-10-14T12:00:00Z');
|
||||
const NATIVE_IDS = [
|
||||
'gemini-4-hydrogen',
|
||||
'gemini-4-carbon',
|
||||
@@ -171,7 +171,7 @@ const asAsyncIterable = <T>(items: T[]): AsyncIterable<T> => ({
|
||||
},
|
||||
});
|
||||
|
||||
const complete = (args: Partial<ICompleteArguments>, pricingTime = LAUNCH) =>
|
||||
const complete = (args: Partial<ICompleteArguments>, pricingTime = REQUEST_TIME) =>
|
||||
withTestActor(() =>
|
||||
makeProvider().complete(
|
||||
{
|
||||
@@ -439,11 +439,11 @@ describe('gemini-4-argon text completion', () => {
|
||||
thinking_tokens: 69,
|
||||
cached_tokens: 0,
|
||||
});
|
||||
// $2 in, $10 out and thinking per million, in µ¢ per token.
|
||||
// $4 in, $20 out and thinking per million, in µ¢ per token.
|
||||
expect(costs).toEqual({
|
||||
prompt_tokens: 36 * 200,
|
||||
completion_tokens: 5 * 1000,
|
||||
thinking_tokens: 69 * 1000,
|
||||
prompt_tokens: 36 * 400,
|
||||
completion_tokens: 5 * 2000,
|
||||
thinking_tokens: 69 * 2000,
|
||||
cached_tokens: 0,
|
||||
});
|
||||
// The reported breakdown counts the same output tokens that were billed.
|
||||
@@ -483,10 +483,10 @@ describe('gemini-4-argon text completion', () => {
|
||||
cached_tokens: 800,
|
||||
});
|
||||
expect(costs).toEqual({
|
||||
prompt_tokens: 200 * 200,
|
||||
completion_tokens: 10 * 1000,
|
||||
thinking_tokens: 20 * 1000,
|
||||
cached_tokens: 800 * 10,
|
||||
prompt_tokens: 200 * 400,
|
||||
completion_tokens: 10 * 2000,
|
||||
thinking_tokens: 20 * 2000,
|
||||
cached_tokens: 800 * 20,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -496,7 +496,7 @@ describe('gemini-4-argon text completion', () => {
|
||||
);
|
||||
await complete({});
|
||||
const [, , , costs] = recordSpy.mock.calls[0]!;
|
||||
expect(costs).toMatchObject({ tool_use_prompt_tokens: 7 * 200 });
|
||||
expect(costs).toMatchObject({ tool_use_prompt_tokens: 7 * 400 });
|
||||
});
|
||||
|
||||
it('inlines data-URL images as inline data', async () => {
|
||||
@@ -585,7 +585,7 @@ describe('gemini-4-argon unsupported content', () => {
|
||||
|
||||
describe('gemini-4-argon pricing by date', () => {
|
||||
it.each([
|
||||
['2026-11-30T23:59:59.999Z', 200, 1000, 10],
|
||||
['2026-11-30T23:59:59.999Z', 400, 2000, 20],
|
||||
['2026-12-01T00:00:00.000Z', 400, 2000, 20],
|
||||
['2027-01-15T08:00:00.000Z', 400, 2000, 20],
|
||||
])(
|
||||
@@ -618,9 +618,9 @@ describe('gemini-4-argon pricing by date', () => {
|
||||
await complete({}, new Date('2026-11-30T23:59:58Z'));
|
||||
const [, , , costs] = recordSpy.mock.calls[0]!;
|
||||
expect(costs).toEqual({
|
||||
prompt_tokens: 36 * 200,
|
||||
completion_tokens: 5 * 1000,
|
||||
thinking_tokens: 69 * 1000,
|
||||
prompt_tokens: 36 * 400,
|
||||
completion_tokens: 5 * 2000,
|
||||
thinking_tokens: 69 * 2000,
|
||||
cached_tokens: 0,
|
||||
});
|
||||
} finally {
|
||||
@@ -825,8 +825,8 @@ describe('gemini-4-argon output cap', () => {
|
||||
let reserve: MockInstance<MeteringService['reserveCredits']>;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Launch rates, so a hold converts to output tokens exactly.
|
||||
vi.useFakeTimers({ toFake: ['Date'], now: LAUNCH });
|
||||
// Fix the request time for deterministic reservations.
|
||||
vi.useFakeTimers({ toFake: ['Date'], now: REQUEST_TIME });
|
||||
driver = new ChatCompletionDriver(
|
||||
{
|
||||
providers: {
|
||||
@@ -1621,7 +1621,7 @@ describe('geminiNativeClient deadline', () => {
|
||||
|
||||
describe('Gemini 4 Carbon', () => {
|
||||
it.each([
|
||||
['2026-11-30T23:59:59.999Z', 200, 1000, 10],
|
||||
['2026-11-30T23:59:59.999Z', 400, 2000, 20],
|
||||
['2026-12-01T00:00:00.000Z', 400, 2000, 20],
|
||||
])(
|
||||
'routes natively and meters thinking at %s',
|
||||
|
||||
@@ -497,13 +497,13 @@ describe('GeminiChatProvider pricing tiers', () => {
|
||||
'gemini-3.7-flash',
|
||||
'gemini-3.8-flash',
|
||||
].flatMap((model) => [
|
||||
[model, '2026-12-31T23:59:59.999Z', 75, 375, 7.5] as const,
|
||||
[model, '2026-12-31T23:59:59.999Z', 150, 750, 15] as const,
|
||||
[model, '2027-01-01T00:00:00.000Z', 150, 750, 15] as const,
|
||||
]);
|
||||
|
||||
it.each([
|
||||
...SCHEDULED,
|
||||
['gemini-robotics-er-2-preview', '2026-12-31T23:59:59.999Z', 100, 500, 10] as const,
|
||||
['gemini-robotics-er-2-preview', '2026-12-31T23:59:59.999Z', 200, 1000, 20] as const,
|
||||
['gemini-robotics-er-2-preview', '2027-01-01T00:00:00.000Z', 200, 1000, 20] as const,
|
||||
])(
|
||||
'settles %s started at %s at its rates in force',
|
||||
@@ -529,7 +529,7 @@ describe('GeminiChatProvider pricing tiers', () => {
|
||||
);
|
||||
|
||||
it.each(['gemini-3.6-flash', 'gemini-robotics-er-2-preview'])(
|
||||
'lists %s at launch rates before the cutoff and doubled from it',
|
||||
'lists %s at standard rates on both sides of the former cutoff',
|
||||
(id) => {
|
||||
const model = GEMINI_MODELS.find((m) => m.id === id)!;
|
||||
const before = listedCosts(
|
||||
@@ -543,7 +543,7 @@ describe('GeminiChatProvider pricing tiers', () => {
|
||||
'thinking_tokens',
|
||||
'cached_tokens',
|
||||
]) {
|
||||
expect(after[key]).toBe(before[key]! * 2);
|
||||
expect(after[key]).toBe(before[key]);
|
||||
}
|
||||
expect(after.grounding_requests).toBe(1_400_000);
|
||||
},
|
||||
|
||||
@@ -64,55 +64,30 @@ export const GEMINI_NATIVE_MODELS: ReadonlyMap<string, GeminiNativeOptions> =
|
||||
['gemini-3-flash-preview', FLASH_NATIVE_OPTIONS],
|
||||
]);
|
||||
|
||||
const DOUBLED_RATES = [
|
||||
'prompt_tokens',
|
||||
'completion_tokens',
|
||||
'thinking_tokens',
|
||||
'cached_tokens',
|
||||
] as const;
|
||||
|
||||
/** Launch pricing whose token rates all double to list pricing at `startsAt`. */
|
||||
const listPricingFrom = (
|
||||
startsAt: string,
|
||||
launch: ModelCost,
|
||||
): ModelPricingOverride[] => [
|
||||
{
|
||||
startsAt,
|
||||
costs: Object.fromEntries(
|
||||
DOUBLED_RATES.map((key) => [key, launch[key] * 2]),
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// Gemini 3.6/3.8 Flash launch pricing.
|
||||
const FLASH_LAUNCH_COSTS: ModelCost = {
|
||||
const FLASH_COSTS: ModelCost = {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 75,
|
||||
completion_tokens: 375,
|
||||
thinking_tokens: 375,
|
||||
cached_tokens: 7.5,
|
||||
prompt_tokens: 150,
|
||||
completion_tokens: 750,
|
||||
thinking_tokens: 750,
|
||||
cached_tokens: 15,
|
||||
// Gemini 3.x grounding is $14 / 1,000 requests
|
||||
grounding_requests: 1_400_000,
|
||||
};
|
||||
const FLASH_LIST_PRICING = listPricingFrom(
|
||||
'2027-01-01T00:00:00Z',
|
||||
FLASH_LAUNCH_COSTS,
|
||||
);
|
||||
|
||||
const GEMINI_4_LAUNCH_COSTS: ModelCost = {
|
||||
const GEMINI_4_COSTS: ModelCost = {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 400,
|
||||
completion_tokens: 2000,
|
||||
thinking_tokens: 2000,
|
||||
cached_tokens: 20,
|
||||
};
|
||||
|
||||
const ROBOTICS_COSTS: ModelCost = {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 200,
|
||||
completion_tokens: 1000,
|
||||
thinking_tokens: 1000,
|
||||
cached_tokens: 10,
|
||||
};
|
||||
|
||||
const ROBOTICS_LAUNCH_COSTS: ModelCost = {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 100,
|
||||
completion_tokens: 500,
|
||||
thinking_tokens: 500,
|
||||
cached_tokens: 10,
|
||||
cached_tokens: 20,
|
||||
grounding_requests: 1_400_000,
|
||||
};
|
||||
|
||||
@@ -151,11 +126,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: GEMINI_4_LAUNCH_COSTS,
|
||||
pricingOverrides: listPricingFrom(
|
||||
'2026-12-01T00:00:00Z',
|
||||
GEMINI_4_LAUNCH_COSTS,
|
||||
),
|
||||
costs: GEMINI_4_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-4-carbon',
|
||||
@@ -177,11 +148,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: GEMINI_4_LAUNCH_COSTS,
|
||||
pricingOverrides: listPricingFrom(
|
||||
'2026-12-01T00:00:00Z',
|
||||
GEMINI_4_LAUNCH_COSTS,
|
||||
),
|
||||
costs: GEMINI_4_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-4-hydrogen',
|
||||
@@ -238,8 +205,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
output_cost_key: 'completion_tokens',
|
||||
// Google serves this endpoint with gemini-3.6-flash and bills its rates.
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: FLASH_LAUNCH_COSTS,
|
||||
pricingOverrides: FLASH_LIST_PRICING,
|
||||
costs: FLASH_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-3.5-flash-lite',
|
||||
@@ -294,8 +260,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: FLASH_LAUNCH_COSTS,
|
||||
pricingOverrides: FLASH_LIST_PRICING,
|
||||
costs: FLASH_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-3.7-flash',
|
||||
@@ -317,8 +282,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
output_cost_key: 'completion_tokens',
|
||||
// Google serves this endpoint with gemini-3.8-flash and bills its rates.
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: FLASH_LAUNCH_COSTS,
|
||||
pricingOverrides: FLASH_LIST_PRICING,
|
||||
costs: FLASH_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-3.8-flash',
|
||||
@@ -338,8 +302,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
serviceSpeedRates: { fast: 1.8 },
|
||||
costs: FLASH_LAUNCH_COSTS,
|
||||
pricingOverrides: FLASH_LIST_PRICING,
|
||||
costs: FLASH_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemini-3.1-flash-lite',
|
||||
@@ -581,11 +544,7 @@ export const GEMINI_MODELS: IChatModel[] = [
|
||||
costs_currency: 'usd-cents',
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
costs: ROBOTICS_LAUNCH_COSTS,
|
||||
pricingOverrides: listPricingFrom(
|
||||
'2027-01-01T00:00:00Z',
|
||||
ROBOTICS_LAUNCH_COSTS,
|
||||
),
|
||||
costs: ROBOTICS_COSTS,
|
||||
},
|
||||
{
|
||||
puterId: 'google:google/gemma-4-31b-it',
|
||||
|
||||
@@ -41,18 +41,22 @@ import {
|
||||
type MockInstance,
|
||||
} from 'vitest';
|
||||
|
||||
import { SYSTEM_ACTOR_UUID } from '../../../../../core/actor.js';
|
||||
import { Context } from '../../../../../core/context.js';
|
||||
import type { MeteringService } from '../../../../../services/metering/MeteringService.js';
|
||||
import type { UsageInput } from '../../../../../services/metering/types.js';
|
||||
import { withAiCostFactor } from '../../../../../util/aiCostFactor.js';
|
||||
import { PuterServer } from '../../../../../server.js';
|
||||
import { setupTestServer } from '../../../../../testUtil.js';
|
||||
import { callerError, withTestActor } from '../../../shared/integrationTestUtil.js';
|
||||
import {
|
||||
callerError,
|
||||
withTestActor,
|
||||
} from '../../../shared/integrationTestUtil.js';
|
||||
import {
|
||||
GEMINI_TTS_MAX_RESPONSE_BYTES,
|
||||
GeminiTTSProvider,
|
||||
} from './GeminiTTSProvider.js';
|
||||
import { GEMINI_TTS_COSTS, GEMINI_TTS_LAUNCH_PRICING_ENDS } from './costs.js';
|
||||
import { GEMINI_TTS_COSTS } from './costs.js';
|
||||
|
||||
const INTERACTIONS_URL =
|
||||
'https://generativelanguage.googleapis.com/v1beta/interactions';
|
||||
@@ -68,6 +72,10 @@ let batchIncrementUsagesSpy: MockInstance<
|
||||
|
||||
beforeAll(async () => {
|
||||
server = await setupTestServer();
|
||||
await server.services.metering.updateAddonCredit(
|
||||
SYSTEM_ACTOR_UUID,
|
||||
100_000_000,
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -105,26 +113,26 @@ const USAGE = {
|
||||
total_tokens: 75,
|
||||
};
|
||||
|
||||
/** What `USAGE` settles to on the default model at launch rates. */
|
||||
/** What `USAGE` settles to on the default model at standard rates. */
|
||||
const SETTLED_USAGE = [
|
||||
{
|
||||
usageType: 'gemini:gemini-3.8-flash-tts:input',
|
||||
usageAmount: 7,
|
||||
costOverride: 7 * 50,
|
||||
costOverride: 7 * 100,
|
||||
},
|
||||
{
|
||||
usageType: 'gemini:gemini-3.8-flash-tts:output:audio',
|
||||
usageAmount: 68,
|
||||
costOverride: 68 * 900,
|
||||
costOverride: 68 * 1800,
|
||||
},
|
||||
];
|
||||
|
||||
/** µ¢ held for the full 8,192 input and 16,384 audio token budget. */
|
||||
/** Μ¢ held for the full 8,192 input and 16,384 audio token budget. */
|
||||
const reservation = (inputRate: number, audioRate: number) =>
|
||||
8192 * inputRate + 16_384 * audioRate;
|
||||
|
||||
/** The default model's hold at launch rates. */
|
||||
const FLASH_RESERVATION = reservation(50, 900);
|
||||
/** The default model's hold at standard rates. */
|
||||
const FLASH_RESERVATION = reservation(100, 1800);
|
||||
|
||||
/** A completed reply; `usage` given as undefined leaves the field out. */
|
||||
const interaction = (
|
||||
@@ -185,7 +193,9 @@ const trackHolds = () => {
|
||||
const metering = server.services.metering;
|
||||
const realReserve = Object.getPrototypeOf(
|
||||
metering,
|
||||
).reserveCreditsIfAffordable.bind(metering) as typeof metering.reserveCreditsIfAffordable;
|
||||
).reserveCreditsIfAffordable.bind(
|
||||
metering,
|
||||
) as typeof metering.reserveCreditsIfAffordable;
|
||||
const held: number[] = [];
|
||||
const released = vi.fn();
|
||||
vi.spyOn(metering, 'reserveCreditsIfAffordable').mockImplementation(
|
||||
@@ -206,11 +216,9 @@ const trackHolds = () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
// The full flash hold at later rates exceeds the system actor's allowance;
|
||||
// tests of later rates set the clock themselves.
|
||||
vi.useFakeTimers({
|
||||
toFake: ['Date'],
|
||||
now: GEMINI_TTS_LAUNCH_PRICING_ENDS - 1,
|
||||
now: Date.UTC(2027, 0, 1) - 1,
|
||||
});
|
||||
fetchSpy = vi
|
||||
.spyOn(globalThis, 'fetch')
|
||||
@@ -280,25 +288,25 @@ describe('GeminiTTSProvider.getReportedCosts', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
it('reports the launch rates through 2026-12-31 UTC', () => {
|
||||
it('reports standard rates before the former cutoff', () => {
|
||||
vi.useFakeTimers({
|
||||
toFake: ['Date'],
|
||||
now: GEMINI_TTS_LAUNCH_PRICING_ENDS - 1,
|
||||
now: Date.UTC(2027, 0, 1) - 1,
|
||||
});
|
||||
expect(reportedRates()).toEqual({
|
||||
'gemini:gemini-3.8-flash-tts:tts': [50, 900],
|
||||
'gemini:gemini-3.8-flash-lite-tts:tts': [50, 600],
|
||||
'gemini:gemini-3.8-flash-tts:tts': [100, 1800],
|
||||
'gemini:gemini-3.8-flash-lite-tts:tts': [100, 1200],
|
||||
});
|
||||
});
|
||||
|
||||
it('reports doubled rates from 2027-01-01 UTC, read at call time', () => {
|
||||
it('reports the same standard rates after the former cutoff', () => {
|
||||
vi.useFakeTimers({
|
||||
toFake: ['Date'],
|
||||
now: GEMINI_TTS_LAUNCH_PRICING_ENDS - 1,
|
||||
now: Date.UTC(2027, 0, 1) - 1,
|
||||
});
|
||||
const provider = makeProvider();
|
||||
provider.getReportedCosts();
|
||||
vi.setSystemTime(GEMINI_TTS_LAUNCH_PRICING_ENDS);
|
||||
vi.setSystemTime(Date.UTC(2027, 0, 1));
|
||||
expect(
|
||||
Object.fromEntries(
|
||||
provider
|
||||
@@ -505,7 +513,7 @@ describe('GeminiTTSProvider.synthesize credit gate', () => {
|
||||
expect(meteredUsages()).toEqual(SETTLED_USAGE);
|
||||
await expect
|
||||
.poll(() => server.services.metering.getRemainingUsage(actor))
|
||||
.toBe(FLASH_RESERVATION - 7 * 50 - 68 * 900);
|
||||
.toBe(FLASH_RESERVATION - 7 * 100 - 68 * 1800);
|
||||
} finally {
|
||||
await blocking.release();
|
||||
}
|
||||
@@ -575,9 +583,9 @@ describe('GeminiTTSProvider.synthesize request shape', () => {
|
||||
await withTestActor(() =>
|
||||
makeProvider().synthesize({ text: 'hi', model }),
|
||||
);
|
||||
expect(
|
||||
sentRequest().body.generation_config.max_output_tokens,
|
||||
).toBe(16_384);
|
||||
expect(sentRequest().body.generation_config.max_output_tokens).toBe(
|
||||
16_384,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1087,8 +1095,8 @@ describe('GeminiTTSProvider.synthesize upstream failures', () => {
|
||||
|
||||
describe('GeminiTTSProvider.synthesize metering', () => {
|
||||
it.each([
|
||||
['gemini-3.8-flash-tts', 900],
|
||||
['gemini-3.8-flash-lite-tts', 600],
|
||||
['gemini-3.8-flash-tts', 1800],
|
||||
['gemini-3.8-flash-lite-tts', 1200],
|
||||
])(
|
||||
'meters %s text input and audio output from the usage modalities',
|
||||
async (model, audioRate) => {
|
||||
@@ -1107,7 +1115,7 @@ describe('GeminiTTSProvider.synthesize metering', () => {
|
||||
{
|
||||
usageType: `gemini:${model}:input`,
|
||||
usageAmount: 7,
|
||||
costOverride: 7 * 50,
|
||||
costOverride: 7 * 100,
|
||||
},
|
||||
{
|
||||
usageType: `gemini:${model}:output:audio`,
|
||||
@@ -1314,20 +1322,20 @@ describe('GeminiTTSProvider.synthesize metering', () => {
|
||||
);
|
||||
});
|
||||
|
||||
// -- Scheduled rates --
|
||||
// -- Standard rates --
|
||||
|
||||
describe('GeminiTTSProvider.synthesize scheduled rates', () => {
|
||||
const BEFORE = GEMINI_TTS_LAUNCH_PRICING_ENDS - 1;
|
||||
const AT = GEMINI_TTS_LAUNCH_PRICING_ENDS;
|
||||
describe('GeminiTTSProvider.synthesize standard rates', () => {
|
||||
const BEFORE = Date.UTC(2027, 0, 1) - 1;
|
||||
const AT = Date.UTC(2027, 0, 1);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({ toFake: ['Date'], now: BEFORE });
|
||||
});
|
||||
|
||||
const SCHEDULE: [string, number, number, number, number][] = [
|
||||
['gemini-3.8-flash-tts', BEFORE, 50, 900, 15_155_200],
|
||||
['gemini-3.8-flash-tts', BEFORE, 100, 1800, 30_310_400],
|
||||
['gemini-3.8-flash-tts', AT, 100, 1800, 30_310_400],
|
||||
['gemini-3.8-flash-lite-tts', BEFORE, 50, 600, 10_240_000],
|
||||
['gemini-3.8-flash-lite-tts', BEFORE, 100, 1200, 20_480_000],
|
||||
['gemini-3.8-flash-lite-tts', AT, 100, 1200, 20_480_000],
|
||||
];
|
||||
|
||||
@@ -1382,7 +1390,7 @@ describe('GeminiTTSProvider.synthesize scheduled rates', () => {
|
||||
},
|
||||
);
|
||||
|
||||
it('settles a request that crosses the change at the rates it was held at', async () => {
|
||||
it('holds and settles at standard rates across the former cutoff', async () => {
|
||||
const { held } = trackHolds();
|
||||
fetchSpy.mockImplementationOnce(async () => {
|
||||
vi.setSystemTime(AT);
|
||||
@@ -1395,8 +1403,8 @@ describe('GeminiTTSProvider.synthesize scheduled rates', () => {
|
||||
);
|
||||
|
||||
expect(held).toEqual([FLASH_RESERVATION]);
|
||||
expect(metered(':input').costOverride).toBe(7 * 50);
|
||||
expect(metered(':output:audio').costOverride).toBe(68 * 900);
|
||||
expect(metered(':input').costOverride).toBe(7 * 100);
|
||||
expect(metered(':output:audio').costOverride).toBe(68 * 1800);
|
||||
});
|
||||
|
||||
it('throws 500 when no cost data exists for the resolved model', async () => {
|
||||
|
||||
@@ -50,11 +50,7 @@ import {
|
||||
assertMaxChars,
|
||||
TTS_UPSTREAM_TIMEOUT_MS,
|
||||
} from '../../../interfaces/textToSpeech/common.js';
|
||||
import {
|
||||
GEMINI_TTS_COSTS,
|
||||
type GeminiTTSCosts,
|
||||
geminiTTSCostsAt,
|
||||
} from './costs.js';
|
||||
import { GEMINI_TTS_COSTS, type GeminiTTSCosts } from './costs.js';
|
||||
|
||||
/**
|
||||
* Largest Interactions reply read; audio arrives base64-encoded inside JSON.
|
||||
@@ -259,9 +255,8 @@ export class GeminiTTSProvider implements ITTSProvider {
|
||||
}
|
||||
|
||||
getReportedCosts(): Record<string, unknown>[] {
|
||||
const now = Date.now();
|
||||
return Object.keys(GEMINI_TTS_COSTS).flatMap((model) => {
|
||||
const costs = geminiTTSCostsAt(model, now);
|
||||
const costs = GEMINI_TTS_COSTS[model];
|
||||
if (!costs) return [];
|
||||
return [
|
||||
{
|
||||
@@ -351,9 +346,7 @@ export class GeminiTTSProvider implements ITTSProvider {
|
||||
}
|
||||
|
||||
const actor = Context.get('actor')!;
|
||||
// Priced once, so a request that crosses a rate change settles at the
|
||||
// rates it was held at.
|
||||
const costs = geminiTTSCostsAt(model, Date.now());
|
||||
const costs = GEMINI_TTS_COSTS[model];
|
||||
if (!costs) {
|
||||
throw new HttpError(500, `No cost data for model: ${model}`, {
|
||||
legacyCode: 'internal_error',
|
||||
|
||||
@@ -23,27 +23,13 @@ export interface GeminiTTSCosts {
|
||||
output_audio: number;
|
||||
}
|
||||
|
||||
/** The instant launch pricing ends and both rates double. */
|
||||
export const GEMINI_TTS_LAUNCH_PRICING_ENDS = Date.UTC(2027, 0, 1);
|
||||
|
||||
/** Launch pricing, through 2026-12-31 UTC. */
|
||||
export const GEMINI_TTS_COSTS: Record<string, GeminiTTSCosts> = {
|
||||
'gemini-3.8-flash-tts': {
|
||||
input: 50, // $0.50 per 1M tokens
|
||||
output_audio: 900, // $9.00 per 1M tokens
|
||||
input: 100, // $1.00 per 1M tokens
|
||||
output_audio: 1800, // $18.00 per 1M tokens
|
||||
},
|
||||
'gemini-3.8-flash-lite-tts': {
|
||||
input: 50, // $0.50 per 1M tokens
|
||||
output_audio: 600, // $6.00 per 1M tokens
|
||||
input: 100, // $1.00 per 1M tokens
|
||||
output_audio: 1200, // $12.00 per 1M tokens
|
||||
},
|
||||
};
|
||||
|
||||
/** `model`'s rates in force at `at` (ms since epoch); undefined when unpriced. */
|
||||
export const geminiTTSCostsAt = (
|
||||
model: string,
|
||||
at: number,
|
||||
): GeminiTTSCosts | undefined => {
|
||||
const launch = GEMINI_TTS_COSTS[model];
|
||||
if (!launch || at < GEMINI_TTS_LAUNCH_PRICING_ENDS) return launch;
|
||||
return { input: launch.input * 2, output_audio: launch.output_audio * 2 };
|
||||
};
|
||||
@@ -180,7 +180,6 @@ export const OPEN_AI_MODELS: IChatModel[] = [
|
||||
costs_currency: 'usd-cents',
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
// OpenAI's promotional pricing, guaranteed only through 2026-11-21.
|
||||
serviceSpeedRates: { fast: 2 },
|
||||
costs: {
|
||||
tokens: 1_000_000,
|
||||
|
||||
@@ -481,6 +481,8 @@ You can find the implementation in our [prompt caching example](/playground/ai-c
|
||||
|
||||
### Gemini models
|
||||
|
||||
Gemini models use regular token prices, including during provider launch promotions.
|
||||
|
||||
Fast service uses Priority inference on supported text and image requests. Other media use standard service to preserve input handling.
|
||||
|
||||
#### `temperature`
|
||||
|
||||
@@ -90,6 +90,8 @@ For more details about each option, see the [ElevenLabs API reference](https://e
|
||||
|
||||
### Gemini models
|
||||
|
||||
Gemini models use regular token prices, including during provider launch promotions.
|
||||
|
||||
Available when `provider: 'gemini'`:
|
||||
|
||||
| Option | Type | Description |
|
||||
|
||||
Reference in new issue
Block a user