tuxevil-rotator 4.4.3 → 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +3 -0
- package/package.json +1 -1
- package/plugins/opencode-discovery/index.mjs +11 -1
- package/src/compat/cache.ts +10 -0
- package/src/compat.ts +115 -13
- package/src/providers/google-antigravity/catalog.ts +2 -0
- package/src/providers/google-antigravity/translators.ts +73 -1
- package/src/responses-store.ts +34 -19
- package/src/types.ts +153 -10
- package/tools/telemetry-receiver/receiver.js +60 -18
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## [4.4.6] - 2026-11-23
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Update `MODEL_PRICING` and the standalone telemetry receiver mirror with official November 2026 API rates for Gemini 4 (`gemini-4-neon`, `gemini-4-hydrogen`, `gemini-4-carbon`, `gemini-4-argon-disabled` plus family fallbacks), Claude 5.5 (`claude-opus-5-5`, `claude-sonnet-5-5` plus `5-5`/`5.5` family fallbacks), OpenAI Codex (`gpt-6.2-astra`, `gpt-6.2-sol`, `gpt-6.1-sol`, `gpt-6.1-terra`), and Ollama Cloud (`beam`, `deepseek-v4.1-flash:1017`, `hy4`, `inkling-2-small`, `kimi-k3.1-pro`, `mimo-v2.6-flash`, `mimo-v2.6-pro`, `minimax-m3.1-flash`, `muse-spark-open`, and updated `mistral-large-4`).
|
|
10
|
+
|
|
11
|
+
## [4.4.5] - 2026-11-23
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Publish `meta.reasoning_efforts` and `meta.default_reasoning_effort` on Antigravity `effortRouting` aliases and adaptive `-tiered` Gemini models (`thinking_budget: -1`) in `GET /v1/models`, and merge discovered effort controls into OpenCode models that previously only declared `capabilities.reasoning.supported: true`, so OpenCode displays effort variants for Gemini and Claude models.
|
|
16
|
+
|
|
17
|
+
## [4.4.4] - 2026-11-21
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Deliver images generated by Gemini image models (such as `gemini-3.1-flash-image`) through the OpenAI Chat, OpenAI Responses and Anthropic Messages routes. The image parts were dropped, so clients received an empty reply; each image now arrives as a markdown data-URI image. When the reply comes back as assistant history, the image is sent upstream as an image part again with its cached thought signature, so it does not consume the model's context as text and can be edited in the next turn. Claude models receive an `[image]` placeholder instead.
|
|
22
|
+
- Preserve literal Markdown in native Gemini responses and return generated images as structured `inlineData` parts.
|
|
23
|
+
- Cap the Responses API conversation store at 32 MiB of serialized entries to bound storage growth from generated images and chained requests.
|
|
24
|
+
|
|
25
|
+
### Contributors
|
|
26
|
+
|
|
27
|
+
- Thanks to [@josenicomaia](https://github.com/josenicomaia) for adding Gemini image support in [PR #50](https://github.com/tuxevil/tuxevil-rotator/pull/50).
|
|
28
|
+
|
|
5
29
|
## [4.4.3] - 2026-11-20
|
|
6
30
|
|
|
7
31
|
### Fixed
|
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
|
|
|
55
55
|
|
|
56
56
|
## Current Model Update
|
|
57
57
|
|
|
58
|
+
- **v4.4.6: Model pricing refresh**: Add official November 2026 pricing and family fallbacks for Gemini 4 (`neon`, `hydrogen`, `carbon`, `argon`), Claude 5.5 (`opus`, `sonnet`), OpenAI `gpt-6.1`/`gpt-6.2`, and newly published Ollama Cloud models in both the rotator and standalone telemetry receiver. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.6))
|
|
59
|
+
- **v4.4.5: Antigravity reasoning effort metadata**: Publish `meta.reasoning_efforts` and `meta.default_reasoning_effort` for Antigravity `effortRouting` aliases and adaptive `-tiered` Gemini models in `GET /v1/models`, and merge discovered effort controls in the OpenCode discovery plugin so Gemini and Claude models expose effort variants. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.5))
|
|
60
|
+
- **v4.4.4: Gemini image output**: Deliver generated images through OpenAI Chat, OpenAI Responses, and Anthropic Messages, with support for editing an image on a follow-up turn. Native Gemini responses return structured image parts. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.4))
|
|
58
61
|
- **v4.4.3: Account model access and routing visibility**: Enforce provider plan eligibility for direct requests, selection, and retries across Antigravity and Codex. Admission rejections now appear in request history, and cooldown estimates use accounts eligible for the requested model. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.3))
|
|
59
62
|
|
|
60
63
|
- **v4.4.2: Model access dashboard**: A redesigned Model access panel with live checks, account evidence, clearer rules and safer plan saving. Thanks to [@CyR1en](https://github.com/CyR1en) for [PR #49](https://github.com/tuxevil/tuxevil-rotator/pull/49). ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.2))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuxevil-rotator",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.6",
|
|
4
4
|
"description": "Multi-provider, multi-account AI proxy rotator with per-model routing, real-time quota tracking, and infringement detection (Google Antigravity, Ollama Cloud)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -291,12 +291,22 @@ export default {
|
|
|
291
291
|
|
|
292
292
|
const toModelInfo = (raw, existingModel) => {
|
|
293
293
|
const { id, modelDef } = mapModelToOpenCode(raw)
|
|
294
|
+
const existingReasoning = existingModel?.capabilities?.reasoning
|
|
295
|
+
const discoveredReasoning = modelDef.capabilities.reasoning
|
|
296
|
+
const mergedReasoning =
|
|
297
|
+
discoveredReasoning || existingReasoning
|
|
298
|
+
? { ...(discoveredReasoning ?? {}), ...(existingReasoning ?? {}) }
|
|
299
|
+
: undefined
|
|
294
300
|
return {
|
|
295
301
|
...modelInfoDefault(resolved.providerID, id),
|
|
296
302
|
...(existingModel ?? {}),
|
|
297
303
|
id: makeModelID(id),
|
|
298
304
|
name: existingModel?.name || modelDef.name,
|
|
299
|
-
capabilities: {
|
|
305
|
+
capabilities: {
|
|
306
|
+
...modelDef.capabilities,
|
|
307
|
+
...(existingModel?.capabilities ?? {}),
|
|
308
|
+
...(mergedReasoning ? { reasoning: mergedReasoning } : {}),
|
|
309
|
+
},
|
|
300
310
|
limit: { ...modelDef.limit, ...(existingModel?.limit ?? {}) },
|
|
301
311
|
...(modelDef.variants ? { variants: [...new Map([...modelDef.variants, ...(Array.isArray(existingModel?.variants) ? existingModel.variants : [])].map(v => [v.id, v])).values()] } : {}),
|
|
302
312
|
}
|
package/src/compat/cache.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { ResponsesStore, type StoredResponseEntry } from "../responses-store.js";
|
|
2
3
|
|
|
3
4
|
export const thoughtSignatureCache = new Map<string, string>();
|
|
@@ -36,3 +37,12 @@ export function cacheThoughtSignature(callId: string, signature: string): void {
|
|
|
36
37
|
}
|
|
37
38
|
thoughtSignatureCache.set(callId, signature);
|
|
38
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generated images reach compat clients as markdown data URIs, which have no
|
|
43
|
+
* room for a thought signature. Key the signature by the image bytes so it can
|
|
44
|
+
* be re-attached when the client sends the image back in the history.
|
|
45
|
+
*/
|
|
46
|
+
export function imageSignatureKey(base64Data: string): string {
|
|
47
|
+
return `image:${createHash("sha256").update(base64Data).digest("hex")}`;
|
|
48
|
+
}
|
package/src/compat.ts
CHANGED
|
@@ -82,6 +82,8 @@ import {
|
|
|
82
82
|
buildResponsesResponse,
|
|
83
83
|
saveResponsesEntry,
|
|
84
84
|
toolArgumentsToObject,
|
|
85
|
+
geminiResponsePartToCompat,
|
|
86
|
+
isTieredEffortModel,
|
|
85
87
|
} from "./providers/google-antigravity/translators.js";
|
|
86
88
|
import {
|
|
87
89
|
openAIToOllamaBody,
|
|
@@ -529,6 +531,7 @@ export function parseOpenAiJson(raw: string): CompatCompletion {
|
|
|
529
531
|
}
|
|
530
532
|
|
|
531
533
|
export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
534
|
+
const geminiParts: Record<string, unknown>[] = [];
|
|
532
535
|
let text = "";
|
|
533
536
|
let thinkingText = "";
|
|
534
537
|
let inputTokens = 0;
|
|
@@ -565,8 +568,12 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
565
568
|
!Array.isArray(candidate.content.parts)
|
|
566
569
|
)
|
|
567
570
|
continue;
|
|
568
|
-
for (const
|
|
569
|
-
|
|
571
|
+
for (const rawPart of candidate.content.parts) {
|
|
572
|
+
const part = geminiResponsePartToCompat(rawPart);
|
|
573
|
+
if (!part) continue;
|
|
574
|
+
if (isRecord(rawPart) && rawPart.thought !== true && typeof part.text === "string") {
|
|
575
|
+
geminiParts.push(rawPart);
|
|
576
|
+
}
|
|
570
577
|
if (typeof part.text === "string") {
|
|
571
578
|
// Route thought blocks separately from normal text
|
|
572
579
|
if (part.thought === true) {
|
|
@@ -656,6 +663,7 @@ export function parseAntigravitySse(raw: string): CompatCompletion {
|
|
|
656
663
|
toolCallsMap.size > 0 ? [...toolCallsMap.values()] : undefined;
|
|
657
664
|
return {
|
|
658
665
|
text: parsedText,
|
|
666
|
+
...(geminiParts.length ? { geminiParts } : {}),
|
|
659
667
|
thinkingText: thinkingText || undefined,
|
|
660
668
|
inputTokens,
|
|
661
669
|
outputTokens,
|
|
@@ -1241,8 +1249,9 @@ export async function streamCompatSse(
|
|
|
1241
1249
|
!Array.isArray(candidate.content.parts)
|
|
1242
1250
|
)
|
|
1243
1251
|
continue;
|
|
1244
|
-
for (const
|
|
1245
|
-
|
|
1252
|
+
for (const rawPart of candidate.content.parts) {
|
|
1253
|
+
const part = geminiResponsePartToCompat(rawPart);
|
|
1254
|
+
if (!part) continue;
|
|
1246
1255
|
if (typeof part.text === "string" && part.text) {
|
|
1247
1256
|
if (part.thought === true) {
|
|
1248
1257
|
// Thought block → reasoning_content (OpenAI) or thinking_delta (Anthropic)
|
|
@@ -2015,8 +2024,9 @@ export async function streamResponsesSse(
|
|
|
2015
2024
|
!Array.isArray(candidate.content.parts)
|
|
2016
2025
|
)
|
|
2017
2026
|
continue;
|
|
2018
|
-
for (const
|
|
2019
|
-
|
|
2027
|
+
for (const rawPart of candidate.content.parts) {
|
|
2028
|
+
const part = geminiResponsePartToCompat(rawPart);
|
|
2029
|
+
if (!part) continue;
|
|
2020
2030
|
if (typeof part.text === "string" && part.text) {
|
|
2021
2031
|
if (part.thought === true) {
|
|
2022
2032
|
// Stream reasoning content via Responses API reasoning events.
|
|
@@ -2590,20 +2600,53 @@ export interface OpenAIModelCatalogEntry {
|
|
|
2590
2600
|
meta: Record<string, unknown>;
|
|
2591
2601
|
}
|
|
2592
2602
|
|
|
2603
|
+
const SCALAR_REASONING_EFFORTS = [
|
|
2604
|
+
"none",
|
|
2605
|
+
"minimal",
|
|
2606
|
+
"low",
|
|
2607
|
+
"medium",
|
|
2608
|
+
"high",
|
|
2609
|
+
"xhigh",
|
|
2610
|
+
"max",
|
|
2611
|
+
] as const;
|
|
2612
|
+
|
|
2613
|
+
const TIERED_REASONING_EFFORTS = ["low", "medium", "high"] as const;
|
|
2614
|
+
|
|
2615
|
+
function withAdaptiveTieredEfforts(model: CompatModelEntry): CompatModelEntry {
|
|
2616
|
+
if (
|
|
2617
|
+
model.isThinking &&
|
|
2618
|
+
model.thinkingBudget === -1 &&
|
|
2619
|
+
getModelFamily(model.id) !== "claude" &&
|
|
2620
|
+
isTieredEffortModel(model.id)
|
|
2621
|
+
) {
|
|
2622
|
+
return {
|
|
2623
|
+
...model,
|
|
2624
|
+
reasoningEfforts: [...TIERED_REASONING_EFFORTS],
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
return model;
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2593
2630
|
function getOpenAIAntigravityModels(
|
|
2594
2631
|
source: ModelCatalogSource,
|
|
2595
2632
|
): CompatModelEntry[] {
|
|
2596
2633
|
// Effort aliases stand in for their targets, so filter before swapping them.
|
|
2597
2634
|
const all = getEffectiveAntigravityModels();
|
|
2598
|
-
const result = all
|
|
2635
|
+
const result = all
|
|
2636
|
+
.filter((model) => isModelServed(source, "google-antigravity", model.id))
|
|
2637
|
+
.map(withAdaptiveTieredEfforts);
|
|
2599
2638
|
const rules = getEffortRouting();
|
|
2600
2639
|
if (!rules || Object.keys(rules).length === 0) {
|
|
2601
2640
|
return result;
|
|
2602
2641
|
}
|
|
2603
2642
|
|
|
2643
|
+
const servedById = new Map(result.map((model) => [model.id.toLowerCase(), model]));
|
|
2604
2644
|
const successfulAliases: Array<{
|
|
2605
2645
|
alias: string;
|
|
2606
2646
|
representative: CompatModelEntry;
|
|
2647
|
+
isThinking: boolean;
|
|
2648
|
+
reasoningEfforts?: string[];
|
|
2649
|
+
defaultReasoningEffort?: string;
|
|
2607
2650
|
}> = [];
|
|
2608
2651
|
const hiddenTargetIds = new Set<string>();
|
|
2609
2652
|
const successfulAliasNames = new Set<string>();
|
|
@@ -2632,9 +2675,7 @@ function getOpenAIAntigravityModels(
|
|
|
2632
2675
|
unavailableAliasNames.add(alias.toLowerCase());
|
|
2633
2676
|
continue;
|
|
2634
2677
|
}
|
|
2635
|
-
const representative =
|
|
2636
|
-
(m) => m.id.toLowerCase() === defaultTargetId.toLowerCase(),
|
|
2637
|
-
);
|
|
2678
|
+
const representative = servedById.get(defaultTargetId.toLowerCase());
|
|
2638
2679
|
if (!representative) {
|
|
2639
2680
|
// A default target turned off on the Models page hides the alias; only
|
|
2640
2681
|
// a target missing from the catalog is a configuration problem.
|
|
@@ -2645,7 +2686,47 @@ function getOpenAIAntigravityModels(
|
|
|
2645
2686
|
}
|
|
2646
2687
|
continue;
|
|
2647
2688
|
}
|
|
2648
|
-
|
|
2689
|
+
|
|
2690
|
+
const servedTargetModels: CompatModelEntry[] = [];
|
|
2691
|
+
const servedEffortSet = new Set<string>();
|
|
2692
|
+
for (const [effortKey, targetId] of Object.entries(rule.targets)) {
|
|
2693
|
+
const target = servedById.get(targetId.toLowerCase());
|
|
2694
|
+
if (!target) continue;
|
|
2695
|
+
if (
|
|
2696
|
+
isRequestOff(source, {
|
|
2697
|
+
catalogModel: alias,
|
|
2698
|
+
model: targetId,
|
|
2699
|
+
providerId: "google-antigravity",
|
|
2700
|
+
})
|
|
2701
|
+
) {
|
|
2702
|
+
continue;
|
|
2703
|
+
}
|
|
2704
|
+
servedTargetModels.push(target);
|
|
2705
|
+
servedEffortSet.add(effortKey.trim().toLowerCase());
|
|
2706
|
+
}
|
|
2707
|
+
const aliasEfforts = SCALAR_REASONING_EFFORTS.filter((effort) =>
|
|
2708
|
+
servedEffortSet.has(effort),
|
|
2709
|
+
);
|
|
2710
|
+
const aliasIsThinking =
|
|
2711
|
+
representative.isThinking || servedTargetModels.some((model) => model.isThinking);
|
|
2712
|
+
const hasAliasEffortSelector = aliasEfforts.length >= 2;
|
|
2713
|
+
const normalizedDefaultEffort = defaultEffortKey.trim().toLowerCase();
|
|
2714
|
+
|
|
2715
|
+
successfulAliases.push({
|
|
2716
|
+
alias,
|
|
2717
|
+
representative,
|
|
2718
|
+
isThinking: aliasIsThinking,
|
|
2719
|
+
reasoningEfforts: hasAliasEffortSelector
|
|
2720
|
+
? aliasEfforts
|
|
2721
|
+
: representative.reasoningEfforts,
|
|
2722
|
+
defaultReasoningEffort: hasAliasEffortSelector
|
|
2723
|
+
? aliasEfforts.includes(
|
|
2724
|
+
normalizedDefaultEffort as (typeof SCALAR_REASONING_EFFORTS)[number],
|
|
2725
|
+
)
|
|
2726
|
+
? normalizedDefaultEffort
|
|
2727
|
+
: undefined
|
|
2728
|
+
: representative.defaultReasoningEffort,
|
|
2729
|
+
});
|
|
2649
2730
|
successfulAliasNames.add(alias.toLowerCase());
|
|
2650
2731
|
for (const targetId of Object.values(rule.targets)) {
|
|
2651
2732
|
hiddenTargetIds.add(targetId.toLowerCase());
|
|
@@ -2659,10 +2740,19 @@ function getOpenAIAntigravityModels(
|
|
|
2659
2740
|
!successfulAliasNames.has(m.id.toLowerCase()),
|
|
2660
2741
|
);
|
|
2661
2742
|
|
|
2662
|
-
for (const {
|
|
2743
|
+
for (const {
|
|
2744
|
+
alias,
|
|
2745
|
+
representative,
|
|
2746
|
+
isThinking,
|
|
2747
|
+
reasoningEfforts,
|
|
2748
|
+
defaultReasoningEffort,
|
|
2749
|
+
} of successfulAliases) {
|
|
2663
2750
|
filtered.push({
|
|
2664
2751
|
...representative,
|
|
2665
2752
|
id: alias,
|
|
2753
|
+
isThinking,
|
|
2754
|
+
...(reasoningEfforts ? { reasoningEfforts } : {}),
|
|
2755
|
+
...(defaultReasoningEffort ? { defaultReasoningEffort } : {}),
|
|
2666
2756
|
});
|
|
2667
2757
|
}
|
|
2668
2758
|
|
|
@@ -2697,6 +2787,8 @@ export function buildOpenAIModelCatalog(
|
|
|
2697
2787
|
thinkingBudget,
|
|
2698
2788
|
minThinkingBudget,
|
|
2699
2789
|
isThinking,
|
|
2790
|
+
reasoningEfforts,
|
|
2791
|
+
defaultReasoningEffort,
|
|
2700
2792
|
}) => ({
|
|
2701
2793
|
id,
|
|
2702
2794
|
object: "model",
|
|
@@ -2716,6 +2808,16 @@ export function buildOpenAIModelCatalog(
|
|
|
2716
2808
|
...(minThinkingBudget !== undefined
|
|
2717
2809
|
? { min_thinking_budget: minThinkingBudget }
|
|
2718
2810
|
: {}),
|
|
2811
|
+
...(isThinking && reasoningEfforts && reasoningEfforts.length > 0
|
|
2812
|
+
? { reasoning_efforts: reasoningEfforts }
|
|
2813
|
+
: {}),
|
|
2814
|
+
...(isThinking &&
|
|
2815
|
+
reasoningEfforts &&
|
|
2816
|
+
reasoningEfforts.length > 0 &&
|
|
2817
|
+
defaultReasoningEffort &&
|
|
2818
|
+
reasoningEfforts.includes(defaultReasoningEffort)
|
|
2819
|
+
? { default_reasoning_effort: defaultReasoningEffort }
|
|
2820
|
+
: {}),
|
|
2719
2821
|
},
|
|
2720
2822
|
}),
|
|
2721
2823
|
);
|
|
@@ -2997,7 +3099,7 @@ export async function handleGeminiGenerateContent(
|
|
|
2997
3099
|
{
|
|
2998
3100
|
content: {
|
|
2999
3101
|
role: "model",
|
|
3000
|
-
parts: [{ text: result.completion.text }],
|
|
3102
|
+
parts: result.completion.geminiParts ?? [{ text: result.completion.text }],
|
|
3001
3103
|
},
|
|
3002
3104
|
finishReason: "STOP",
|
|
3003
3105
|
},
|
|
@@ -124,6 +124,8 @@ export interface CompatModelEntry {
|
|
|
124
124
|
thinkingBudget: number;
|
|
125
125
|
minThinkingBudget?: number;
|
|
126
126
|
isThinking: boolean;
|
|
127
|
+
reasoningEfforts?: string[];
|
|
128
|
+
defaultReasoningEffort?: string;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
export function getEffectiveAntigravityModels(): CompatModelEntry[] {
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
import { dynamicCatalog } from "./dynamic-catalog.js";
|
|
19
19
|
import {
|
|
20
20
|
thoughtSignatureCache,
|
|
21
|
+
cacheThoughtSignature,
|
|
22
|
+
imageSignatureKey,
|
|
21
23
|
getStoredResponse,
|
|
22
24
|
setStoredResponse,
|
|
23
25
|
makeCompatId,
|
|
@@ -179,6 +181,7 @@ export interface AnthropicMessagesRequest {
|
|
|
179
181
|
|
|
180
182
|
export interface CompatCompletion {
|
|
181
183
|
text: string;
|
|
184
|
+
geminiParts?: Record<string, unknown>[];
|
|
182
185
|
thinkingText?: string; // Gemini thought blocks (thought: true), emitted as reasoning_content
|
|
183
186
|
inputTokens: number;
|
|
184
187
|
outputTokens: number;
|
|
@@ -303,6 +306,73 @@ export function dataUrlToInlineData(url: string): AntigravityPart | null {
|
|
|
303
306
|
return { inlineData: { mimeType: match[1], data: match[2] } };
|
|
304
307
|
}
|
|
305
308
|
|
|
309
|
+
const MARKDOWN_DATA_IMAGE =
|
|
310
|
+
/!\[[^\]\n]*\]\(data:(image\/[A-Za-z0-9.+-]+);base64,([A-Za-z0-9+/=]+)\)/g;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Normalize one Gemini response part for the compat (OpenAI/Anthropic/
|
|
314
|
+
* Responses) encoders, which only understand text, thoughts and function
|
|
315
|
+
* calls. A generated image (`inlineData`) becomes a markdown data-URI image
|
|
316
|
+
* text part so clients that render markdown can show it. Returns null for
|
|
317
|
+
* parts that must not reach the client: non-records, interim "thought"
|
|
318
|
+
* images and non-image inline payloads.
|
|
319
|
+
*/
|
|
320
|
+
export function geminiResponsePartToCompat(
|
|
321
|
+
part: unknown,
|
|
322
|
+
): Record<string, unknown> | null {
|
|
323
|
+
if (!isRecord(part)) return null;
|
|
324
|
+
if (!isRecord(part.inlineData)) return part;
|
|
325
|
+
const { mimeType, data } = part.inlineData;
|
|
326
|
+
if (
|
|
327
|
+
part.thought === true ||
|
|
328
|
+
typeof mimeType !== "string" ||
|
|
329
|
+
!mimeType.startsWith("image/") ||
|
|
330
|
+
typeof data !== "string" ||
|
|
331
|
+
!data
|
|
332
|
+
) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
if (typeof part.thoughtSignature === "string" && part.thoughtSignature) {
|
|
336
|
+
cacheThoughtSignature(imageSignatureKey(data), part.thoughtSignature);
|
|
337
|
+
}
|
|
338
|
+
return { text: `\n\n\n\n` };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Inverse of geminiResponsePartToCompat for model turns sent back by the
|
|
343
|
+
* client: markdown data-URI images become `inlineData` parts again, so the
|
|
344
|
+
* base64 is not billed as text and the image can be edited in later turns.
|
|
345
|
+
* With `inlineImages` false (models that do not accept images in model turns)
|
|
346
|
+
* each image collapses to an `[image]` placeholder instead.
|
|
347
|
+
*/
|
|
348
|
+
export function modelTextToGeminiParts(
|
|
349
|
+
text: string,
|
|
350
|
+
inlineImages: boolean,
|
|
351
|
+
): Array<Record<string, unknown>> {
|
|
352
|
+
if (!text.includes("](data:image/")) return [{ text }];
|
|
353
|
+
if (!inlineImages) return [{ text: text.replace(MARKDOWN_DATA_IMAGE, "[image]") }];
|
|
354
|
+
const parts: Array<Record<string, unknown>> = [];
|
|
355
|
+
const pushText = (segment: string): void => {
|
|
356
|
+
const trimmed = segment.trim();
|
|
357
|
+
if (trimmed) parts.push({ text: trimmed });
|
|
358
|
+
};
|
|
359
|
+
let last = 0;
|
|
360
|
+
for (const match of text.matchAll(MARKDOWN_DATA_IMAGE)) {
|
|
361
|
+
const index = match.index ?? 0;
|
|
362
|
+
pushText(text.slice(last, index));
|
|
363
|
+
last = index + match[0].length;
|
|
364
|
+
const [, mimeType, data] = match;
|
|
365
|
+
const signature = thoughtSignatureCache.get(imageSignatureKey(data));
|
|
366
|
+
parts.push({
|
|
367
|
+
inlineData: { mimeType, data },
|
|
368
|
+
...(signature ? { thoughtSignature: signature } : {}),
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (last === 0) return [{ text }];
|
|
372
|
+
pushText(text.slice(last));
|
|
373
|
+
return parts;
|
|
374
|
+
}
|
|
375
|
+
|
|
306
376
|
export function extractParts(
|
|
307
377
|
content: ChatMessage["content"],
|
|
308
378
|
): AntigravityPart[] {
|
|
@@ -1088,7 +1158,9 @@ export function openAIToAntigravityBody(
|
|
|
1088
1158
|
typeof msg.content === "string"
|
|
1089
1159
|
? msg.content
|
|
1090
1160
|
: extractText(msg.content);
|
|
1091
|
-
if (textContent)
|
|
1161
|
+
if (textContent) {
|
|
1162
|
+
parts.push(...modelTextToGeminiParts(textContent, !isClaude));
|
|
1163
|
+
}
|
|
1092
1164
|
}
|
|
1093
1165
|
if (Array.isArray(msgToolCalls) && msgToolCalls.length > 0) {
|
|
1094
1166
|
let isFirstInMessage = true;
|
package/src/responses-store.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface PersistedResponsesStore {
|
|
|
31
31
|
|
|
32
32
|
const FLUSH_DEBOUNCE_MS = 1_500;
|
|
33
33
|
const MAX_ENTRIES = 500;
|
|
34
|
-
const
|
|
34
|
+
const MAX_STORE_BYTES = 32 * 1024 * 1024;
|
|
35
35
|
|
|
36
36
|
function now(): number {
|
|
37
37
|
return Date.now();
|
|
@@ -43,11 +43,12 @@ function now(): number {
|
|
|
43
43
|
* Maps `response_id` to the conversation state needed to continue a previous
|
|
44
44
|
* turn via `previous_response_id`. Persisted via the settings repository.
|
|
45
45
|
* Writes are debounced to 1.5s and coalesced if a flush is already in flight.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* Entries expire after 6h. Oldest entries are evicted above 500 entries
|
|
47
|
+
* or 32 MiB of serialized entries, including response and history payloads.
|
|
48
48
|
*/
|
|
49
49
|
export class ResponsesStore {
|
|
50
|
-
private cache = new Map<string, StoredResponseEntry>();
|
|
50
|
+
private cache = new Map<string, { entry: StoredResponseEntry; bytes: number }>();
|
|
51
|
+
private bytes = 0;
|
|
51
52
|
private flushTimer: ReturnType<typeof setTimeout> | null = null;
|
|
52
53
|
private flushing: Promise<void> | null = null;
|
|
53
54
|
private pendingFlush = false;
|
|
@@ -62,20 +63,21 @@ export class ResponsesStore {
|
|
|
62
63
|
if (!dbStore || dbStore.version !== 1 || !Array.isArray(dbStore.entries)) {
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
65
|
-
const cutoff = now()
|
|
66
|
+
const cutoff = now();
|
|
66
67
|
for (const [id, entry] of dbStore.entries) {
|
|
67
68
|
if (!entry || typeof entry !== "object") continue;
|
|
68
69
|
if (typeof entry.expiresAt !== "number" || entry.expiresAt < cutoff)
|
|
69
70
|
continue;
|
|
70
|
-
this.
|
|
71
|
+
this.insert(id, entry);
|
|
71
72
|
}
|
|
73
|
+
if (this.cache.size < dbStore.entries.length) this.scheduleFlush();
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
get(id: string): StoredResponseEntry | null {
|
|
75
|
-
const entry = this.cache.get(id);
|
|
77
|
+
const entry = this.cache.get(id)?.entry;
|
|
76
78
|
if (!entry) return null;
|
|
77
79
|
if (entry.expiresAt <= now()) {
|
|
78
|
-
this.
|
|
80
|
+
this.remove(id);
|
|
79
81
|
this.scheduleFlush();
|
|
80
82
|
return null;
|
|
81
83
|
}
|
|
@@ -83,19 +85,19 @@ export class ResponsesStore {
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
set(id: string, entry: StoredResponseEntry): void {
|
|
86
|
-
this.
|
|
87
|
-
this.pruneIfNeeded();
|
|
88
|
+
this.insert(id, entry);
|
|
88
89
|
this.scheduleFlush();
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
delete(id: string): boolean {
|
|
92
|
-
const existed = this.
|
|
93
|
+
const existed = this.remove(id);
|
|
93
94
|
if (existed) this.scheduleFlush();
|
|
94
95
|
return existed;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
clear(): void {
|
|
98
99
|
this.cache.clear();
|
|
100
|
+
this.bytes = 0;
|
|
99
101
|
this.scheduleFlush();
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -103,16 +105,28 @@ export class ResponsesStore {
|
|
|
103
105
|
return this.cache.size;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
private
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
private insert(id: string, entry: StoredResponseEntry): void {
|
|
109
|
+
const bytes = Buffer.byteLength(JSON.stringify([id, entry])) + 1;
|
|
110
|
+
this.remove(id);
|
|
111
|
+
const cutoff = now();
|
|
112
|
+
if (bytes > MAX_STORE_BYTES || entry.expiresAt <= cutoff) return;
|
|
113
|
+
for (const [key, cached] of this.cache) {
|
|
114
|
+
if (cached.entry.expiresAt <= cutoff) this.remove(key);
|
|
110
115
|
}
|
|
111
|
-
while (this.cache.size >
|
|
116
|
+
while (this.cache.size >= MAX_ENTRIES || this.bytes + bytes > MAX_STORE_BYTES) {
|
|
112
117
|
const oldest = this.cache.keys().next();
|
|
113
118
|
if (oldest.done) break;
|
|
114
|
-
this.
|
|
119
|
+
this.remove(oldest.value);
|
|
115
120
|
}
|
|
121
|
+
this.cache.set(id, { entry, bytes });
|
|
122
|
+
this.bytes += bytes;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private remove(id: string): boolean {
|
|
126
|
+
const cached = this.cache.get(id);
|
|
127
|
+
if (!cached) return false;
|
|
128
|
+
this.bytes -= cached.bytes;
|
|
129
|
+
return this.cache.delete(id);
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
private scheduleFlush(): void {
|
|
@@ -139,11 +153,12 @@ export class ResponsesStore {
|
|
|
139
153
|
if (!this.dirty) return;
|
|
140
154
|
const data: PersistedResponsesStore = {
|
|
141
155
|
version: 1,
|
|
142
|
-
entries: Array.from(this.cache
|
|
156
|
+
entries: Array.from(this.cache, ([id, { entry }]) => [id, entry]),
|
|
143
157
|
};
|
|
144
|
-
await setCachedResponsesStore(data);
|
|
145
158
|
this.dirty = false;
|
|
159
|
+
await setCachedResponsesStore(data);
|
|
146
160
|
} catch {
|
|
161
|
+
this.dirty = true;
|
|
147
162
|
// Best effort — will retry on next schedule.
|
|
148
163
|
} finally {
|
|
149
164
|
this.flushing = null;
|
package/src/types.ts
CHANGED
|
@@ -884,10 +884,22 @@ export interface ModelPricing {
|
|
|
884
884
|
}
|
|
885
885
|
|
|
886
886
|
// Pricing per 1M tokens (USD) — what these would cost on paid APIs.
|
|
887
|
-
// Source audit and estimation limits: docs/model-pricing.md (2026-
|
|
887
|
+
// Source audit and estimation limits: docs/model-pricing.md (2026-11-23).
|
|
888
888
|
export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
889
889
|
"claude-opus-4-6-thinking": { inputPer1M: 5.0, outputPer1M: 25.0 },
|
|
890
890
|
"claude-sonnet-4-6": { inputPer1M: 3.0, outputPer1M: 15.0 },
|
|
891
|
+
// Official Anthropic pricing verified 2026-11-23:
|
|
892
|
+
// https://platform.claude.com/docs/en/about-claude/pricing
|
|
893
|
+
"claude-opus-5-5": {
|
|
894
|
+
inputPer1M: 4.0,
|
|
895
|
+
outputPer1M: 20.0,
|
|
896
|
+
cachingPer1M: 0.2,
|
|
897
|
+
},
|
|
898
|
+
"claude-sonnet-5-5": {
|
|
899
|
+
inputPer1M: 2.0,
|
|
900
|
+
outputPer1M: 10.0,
|
|
901
|
+
cachingPer1M: 0.1,
|
|
902
|
+
},
|
|
891
903
|
"gemini-3.1-pro": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
892
904
|
"gemini-3.1-pro-low": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
893
905
|
"gemini-3.1-pro-high": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
@@ -937,8 +949,20 @@ export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
|
937
949
|
cachingStoragePer1MPerHour: 0.5,
|
|
938
950
|
},
|
|
939
951
|
// Gemini 3.8 Flash — introductory public Gemini API pricing verified
|
|
940
|
-
// 2026-
|
|
941
|
-
// separate low/medium/high model ids.
|
|
952
|
+
// 2026-11-23. These rates double on 2027-01-01. Antigravity exposes
|
|
953
|
+
// separate low/medium/high model ids plus effort alias and tiered id.
|
|
954
|
+
"gemini-3.8-flash": {
|
|
955
|
+
inputPer1M: 0.75,
|
|
956
|
+
outputPer1M: 3.75,
|
|
957
|
+
cachingPer1M: 0.075,
|
|
958
|
+
cachingStoragePer1MPerHour: 0.5,
|
|
959
|
+
},
|
|
960
|
+
"gemini-3.8-flash-tiered": {
|
|
961
|
+
inputPer1M: 0.75,
|
|
962
|
+
outputPer1M: 3.75,
|
|
963
|
+
cachingPer1M: 0.075,
|
|
964
|
+
cachingStoragePer1MPerHour: 0.5,
|
|
965
|
+
},
|
|
942
966
|
"gemini-3.8-flash-low": {
|
|
943
967
|
inputPer1M: 0.75,
|
|
944
968
|
outputPer1M: 3.75,
|
|
@@ -957,13 +981,23 @@ export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
|
957
981
|
cachingPer1M: 0.075,
|
|
958
982
|
cachingStoragePer1MPerHour: 0.5,
|
|
959
983
|
},
|
|
960
|
-
//
|
|
961
|
-
// https://ai.google.dev/gemini-api/docs/pricing (verified 2026-
|
|
984
|
+
// Gemini 4 Carbon & Argon: standard rates through 2026-11-30; then 4/20/0.2.
|
|
985
|
+
// Implicit cache only. https://ai.google.dev/gemini-api/docs/pricing (verified 2026-11-23).
|
|
986
|
+
"gemini-4-carbon": {
|
|
987
|
+
inputPer1M: 2.0,
|
|
988
|
+
outputPer1M: 10.0,
|
|
989
|
+
cachingPer1M: 0.1,
|
|
990
|
+
},
|
|
962
991
|
"gemini-4-argon": {
|
|
963
992
|
inputPer1M: 2.0,
|
|
964
993
|
outputPer1M: 10.0,
|
|
965
994
|
cachingPer1M: 0.1,
|
|
966
995
|
},
|
|
996
|
+
"gemini-4-argon-disabled": {
|
|
997
|
+
inputPer1M: 2.0,
|
|
998
|
+
outputPer1M: 10.0,
|
|
999
|
+
cachingPer1M: 0.1,
|
|
1000
|
+
},
|
|
967
1001
|
"gemini-4-argon-low": {
|
|
968
1002
|
inputPer1M: 2.0,
|
|
969
1003
|
outputPer1M: 10.0,
|
|
@@ -979,12 +1013,94 @@ export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
|
979
1013
|
outputPer1M: 10.0,
|
|
980
1014
|
cachingPer1M: 0.1,
|
|
981
1015
|
},
|
|
1016
|
+
// Gemini 4 Neon: standard paid tier rates, implicit cache only (verified 2026-11-23).
|
|
1017
|
+
"gemini-4-neon": {
|
|
1018
|
+
inputPer1M: 3.0,
|
|
1019
|
+
outputPer1M: 15.0,
|
|
1020
|
+
cachingPer1M: 0.15,
|
|
1021
|
+
},
|
|
1022
|
+
"gemini-4-neon-low": {
|
|
1023
|
+
inputPer1M: 3.0,
|
|
1024
|
+
outputPer1M: 15.0,
|
|
1025
|
+
cachingPer1M: 0.15,
|
|
1026
|
+
},
|
|
1027
|
+
"gemini-4-neon-medium": {
|
|
1028
|
+
inputPer1M: 3.0,
|
|
1029
|
+
outputPer1M: 15.0,
|
|
1030
|
+
cachingPer1M: 0.15,
|
|
1031
|
+
},
|
|
1032
|
+
"gemini-4-neon-high": {
|
|
1033
|
+
inputPer1M: 3.0,
|
|
1034
|
+
outputPer1M: 15.0,
|
|
1035
|
+
cachingPer1M: 0.15,
|
|
1036
|
+
},
|
|
1037
|
+
"gemini-4-neon-xhigh": {
|
|
1038
|
+
inputPer1M: 3.0,
|
|
1039
|
+
outputPer1M: 15.0,
|
|
1040
|
+
cachingPer1M: 0.15,
|
|
1041
|
+
},
|
|
1042
|
+
// Gemini 4 Hydrogen: standard paid tier rates, implicit cache only (verified 2026-11-23).
|
|
1043
|
+
"gemini-4-hydrogen": {
|
|
1044
|
+
inputPer1M: 1.5,
|
|
1045
|
+
outputPer1M: 7.5,
|
|
1046
|
+
cachingPer1M: 0.075,
|
|
1047
|
+
},
|
|
1048
|
+
"gemini-4-hydrogen-low": {
|
|
1049
|
+
inputPer1M: 1.5,
|
|
1050
|
+
outputPer1M: 7.5,
|
|
1051
|
+
cachingPer1M: 0.075,
|
|
1052
|
+
},
|
|
1053
|
+
"gemini-4-hydrogen-medium": {
|
|
1054
|
+
inputPer1M: 1.5,
|
|
1055
|
+
outputPer1M: 7.5,
|
|
1056
|
+
cachingPer1M: 0.075,
|
|
1057
|
+
},
|
|
1058
|
+
"gemini-4-hydrogen-high": {
|
|
1059
|
+
inputPer1M: 1.5,
|
|
1060
|
+
outputPer1M: 7.5,
|
|
1061
|
+
cachingPer1M: 0.075,
|
|
1062
|
+
},
|
|
1063
|
+
"gemini-4-hydrogen-xhigh": {
|
|
1064
|
+
inputPer1M: 1.5,
|
|
1065
|
+
outputPer1M: 7.5,
|
|
1066
|
+
cachingPer1M: 0.075,
|
|
1067
|
+
},
|
|
1068
|
+
"gemini-4-hydrogen-tiered": {
|
|
1069
|
+
inputPer1M: 1.5,
|
|
1070
|
+
outputPer1M: 7.5,
|
|
1071
|
+
cachingPer1M: 0.075,
|
|
1072
|
+
},
|
|
1073
|
+
"gemini-4-hydrogen-sonar": {
|
|
1074
|
+
inputPer1M: 1.5,
|
|
1075
|
+
outputPer1M: 7.5,
|
|
1076
|
+
cachingPer1M: 0.075,
|
|
1077
|
+
},
|
|
982
1078
|
"gpt-oss-120b-medium": { inputPer1M: 2.0, outputPer1M: 10.0 },
|
|
983
1079
|
|
|
984
|
-
// OpenAI Codex API-equivalent standard rates, checked against
|
|
985
|
-
// https://developers.openai.com/api/docs/pricing on 2026-
|
|
1080
|
+
// OpenAI Codex API-equivalent standard short-context rates, checked against
|
|
1081
|
+
// https://developers.openai.com/api/docs/pricing on 2026-11-23.
|
|
986
1082
|
// Spend logs use aggregate input/output tokens;
|
|
987
1083
|
// cache rates are metadata and are not applied separately.
|
|
1084
|
+
"gpt-6.2-astra": {
|
|
1085
|
+
inputPer1M: 8.0,
|
|
1086
|
+
outputPer1M: 40.0,
|
|
1087
|
+
cachingPer1M: 0.4,
|
|
1088
|
+
},
|
|
1089
|
+
"gpt-6.2-sol": {
|
|
1090
|
+
inputPer1M: 2.0,
|
|
1091
|
+
outputPer1M: 10.0,
|
|
1092
|
+
cachingPer1M: 0.1,
|
|
1093
|
+
},
|
|
1094
|
+
"gpt-6.1-sol": {
|
|
1095
|
+
inputPer1M: 2.0,
|
|
1096
|
+
outputPer1M: 10.0,
|
|
1097
|
+
cachingPer1M: 0.1,
|
|
1098
|
+
},
|
|
1099
|
+
"gpt-6.1-terra": {
|
|
1100
|
+
inputPer1M: 1.0,
|
|
1101
|
+
outputPer1M: 5.0,
|
|
1102
|
+
cachingPer1M: 0.05,
|
|
1103
|
+
},
|
|
988
1104
|
"gpt-6-astra": {
|
|
989
1105
|
inputPer1M: 10.0,
|
|
990
1106
|
outputPer1M: 50.0,
|
|
@@ -1000,7 +1116,7 @@ export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
|
1000
1116
|
outputPer1M: 0.5,
|
|
1001
1117
|
cachingPer1M: 0.01,
|
|
1002
1118
|
},
|
|
1003
|
-
// Promotional pricing available
|
|
1119
|
+
// Promotional pricing available through 2026-11-30.
|
|
1004
1120
|
"gpt-5.6-sol": {
|
|
1005
1121
|
inputPer1M: 4.0,
|
|
1006
1122
|
outputPer1M: 20.0,
|
|
@@ -1017,26 +1133,35 @@ export const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
|
1017
1133
|
cachingPer1M: 0.02,
|
|
1018
1134
|
},
|
|
1019
1135
|
|
|
1020
|
-
// Ollama Cloud standard USD/1M rates, verified 2026-
|
|
1136
|
+
// Ollama Cloud standard USD/1M rates, verified 2026-11-23:
|
|
1021
1137
|
// https://ollama.com/pricing. Aggregates do not track cache hits or off-peak
|
|
1022
1138
|
// billing, so savings represent standard list-price value, not a net saving.
|
|
1139
|
+
"beam": { inputPer1M: 0.125, outputPer1M: 0.40, cachingPer1M: 0.015 },
|
|
1023
1140
|
"gpt-oss:20b": { inputPer1M: 0.07, outputPer1M: 0.30, cachingPer1M: 0.035 },
|
|
1024
1141
|
"gpt-oss:120b": { inputPer1M: 0.15, outputPer1M: 0.60, cachingPer1M: 0.014 },
|
|
1025
1142
|
"deepseek-v4.1-flash": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.006 },
|
|
1143
|
+
"deepseek-v4.1-flash:1017": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.006 },
|
|
1026
1144
|
"deepseek-v4-pro": { inputPer1M: 1.32, outputPer1M: 3.96, cachingPer1M: 0.044 },
|
|
1027
1145
|
"glm-5.2": { inputPer1M: 1.40, outputPer1M: 4.40, cachingPer1M: 0.26 },
|
|
1028
1146
|
"glm-5.3": { inputPer1M: 1.40, outputPer1M: 4.40, cachingPer1M: 0.26 },
|
|
1029
1147
|
"glm-5.3-flash": { inputPer1M: 0.15, outputPer1M: 0.50, cachingPer1M: 0.03 },
|
|
1030
1148
|
"gemma4": { inputPer1M: 0.14, outputPer1M: 0.40, cachingPer1M: 0.05 },
|
|
1031
1149
|
"gemma4:31b": { inputPer1M: 0.14, outputPer1M: 0.40, cachingPer1M: 0.05 },
|
|
1150
|
+
"hy4": { inputPer1M: 0.834, outputPer1M: 2.501, cachingPer1M: 0.042 },
|
|
1151
|
+
"inkling-2-small": { inputPer1M: 0.30, outputPer1M: 1.00, cachingPer1M: 0.03 },
|
|
1032
1152
|
"kimi-k2.6": { inputPer1M: 0.95, outputPer1M: 4.00, cachingPer1M: 0.16 },
|
|
1033
1153
|
"kimi-k2.7-code": { inputPer1M: 0.95, outputPer1M: 4.00, cachingPer1M: 0.19 },
|
|
1034
1154
|
"kimi-k3": { inputPer1M: 3.00, outputPer1M: 15.00, cachingPer1M: 0.30 },
|
|
1155
|
+
"kimi-k3.1-pro": { inputPer1M: 2.00, outputPer1M: 10.00, cachingPer1M: 0.20 },
|
|
1156
|
+
"mimo-v2.6-flash": { inputPer1M: 0.14, outputPer1M: 0.28, cachingPer1M: 0.0028 },
|
|
1157
|
+
"mimo-v2.6-pro": { inputPer1M: 0.435, outputPer1M: 0.87, cachingPer1M: 0.0036 },
|
|
1035
1158
|
"minimax-m2.7": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.06 },
|
|
1036
1159
|
"minimax-m3": { inputPer1M: 0.60, outputPer1M: 2.40, cachingPer1M: 0.12 },
|
|
1037
|
-
"
|
|
1160
|
+
"minimax-m3.1-flash": { inputPer1M: 0.15, outputPer1M: 0.60, cachingPer1M: 0.015 },
|
|
1161
|
+
"mistral-large-4": { inputPer1M: 0.70, outputPer1M: 2.10, cachingPer1M: 0.07 },
|
|
1038
1162
|
"mistral-large-3": { inputPer1M: 0.50, outputPer1M: 1.50 },
|
|
1039
1163
|
"mistral-large-3:675b": { inputPer1M: 0.50, outputPer1M: 1.50 },
|
|
1164
|
+
"muse-spark-open": { inputPer1M: 1.25, outputPer1M: 4.25, cachingPer1M: 0.15 },
|
|
1040
1165
|
"nemotron-3-nano": { inputPer1M: 0.06, outputPer1M: 0.24 },
|
|
1041
1166
|
"nemotron-3-nano:30b": { inputPer1M: 0.06, outputPer1M: 0.24 },
|
|
1042
1167
|
"nemotron-3-super": { inputPer1M: 0.015, outputPer1M: 0.60, cachingPer1M: 0.015 },
|
|
@@ -1078,12 +1203,30 @@ export function getModelPricing(model: string): ModelPricing | undefined {
|
|
|
1078
1203
|
// version checks explicit so an unrelated model containing "flash" cannot
|
|
1079
1204
|
// inherit Gemini pricing.
|
|
1080
1205
|
if (lower.includes("claude") && lower.includes("opus")) {
|
|
1206
|
+
if (lower.includes("5-5") || lower.includes("5.5")) {
|
|
1207
|
+
return MODEL_PRICING["claude-opus-5-5"];
|
|
1208
|
+
}
|
|
1081
1209
|
return MODEL_PRICING["claude-opus-4-6-thinking"];
|
|
1082
1210
|
}
|
|
1083
1211
|
if (lower.includes("claude") && lower.includes("sonnet")) {
|
|
1212
|
+
if (lower.includes("5-5") || lower.includes("5.5")) {
|
|
1213
|
+
return MODEL_PRICING["claude-sonnet-5-5"];
|
|
1214
|
+
}
|
|
1084
1215
|
return MODEL_PRICING["claude-sonnet-4-6"];
|
|
1085
1216
|
}
|
|
1086
1217
|
if (lower.includes("gemini")) {
|
|
1218
|
+
if (lower.includes("4-carbon") || lower.includes("4.0-carbon")) {
|
|
1219
|
+
return MODEL_PRICING["gemini-4-carbon"];
|
|
1220
|
+
}
|
|
1221
|
+
if (lower.includes("4-argon") || lower.includes("4.0-argon")) {
|
|
1222
|
+
return MODEL_PRICING["gemini-4-argon"];
|
|
1223
|
+
}
|
|
1224
|
+
if (lower.includes("4-neon") || lower.includes("4.0-neon")) {
|
|
1225
|
+
return MODEL_PRICING["gemini-4-neon"];
|
|
1226
|
+
}
|
|
1227
|
+
if (lower.includes("4-hydrogen") || lower.includes("4.0-hydrogen")) {
|
|
1228
|
+
return MODEL_PRICING["gemini-4-hydrogen"];
|
|
1229
|
+
}
|
|
1087
1230
|
if (lower.includes("3.8") && lower.includes("flash")) {
|
|
1088
1231
|
return MODEL_PRICING["gemini-3.8-flash-high"];
|
|
1089
1232
|
}
|
|
@@ -336,6 +336,8 @@ function sanitizeTokensByModel(raw) {
|
|
|
336
336
|
const MODEL_PRICING = {
|
|
337
337
|
"claude-opus-4-6-thinking": { inputPer1M: 5.0, outputPer1M: 25.0 },
|
|
338
338
|
"claude-sonnet-4-6": { inputPer1M: 3.0, outputPer1M: 15.0 },
|
|
339
|
+
"claude-opus-5-5": { inputPer1M: 4.0, outputPer1M: 20.0, cachingPer1M: 0.2 },
|
|
340
|
+
"claude-sonnet-5-5": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
339
341
|
"gemini-3.1-pro": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
340
342
|
"gemini-3.1-pro-low": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
341
343
|
"gemini-3.1-pro-high": { inputPer1M: 2.0, outputPer1M: 12.0 },
|
|
@@ -345,30 +347,67 @@ const MODEL_PRICING = {
|
|
|
345
347
|
"gemini-3.6-flash-medium": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
346
348
|
"gemini-3.6-flash-low": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
347
349
|
"gemini-3.6-flash-tiered": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
348
|
-
// Gemini introductory pricing: see docs/model-pricing.md (2026-
|
|
350
|
+
// Gemini introductory pricing: see docs/model-pricing.md (2026-11-23).
|
|
349
351
|
"gemini-3.7-flash-tiered": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
350
352
|
// Gemini 3.8 Flash uses the same introductory window and doubles on 2027-01-01.
|
|
353
|
+
"gemini-3.8-flash": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
354
|
+
"gemini-3.8-flash-tiered": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
351
355
|
"gemini-3.8-flash-low": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
352
356
|
"gemini-3.8-flash-medium": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
353
357
|
"gemini-3.8-flash-high": { inputPer1M: 0.75, outputPer1M: 3.75, cachingPer1M: 0.075, cachingStoragePer1MPerHour: 0.5 },
|
|
358
|
+
"gemini-4-carbon": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
359
|
+
"gemini-4-argon": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
360
|
+
"gemini-4-argon-disabled": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
361
|
+
"gemini-4-argon-low": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
362
|
+
"gemini-4-argon-medium": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
363
|
+
"gemini-4-argon-high": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
364
|
+
"gemini-4-neon": { inputPer1M: 3.0, outputPer1M: 15.0, cachingPer1M: 0.15 },
|
|
365
|
+
"gemini-4-neon-low": { inputPer1M: 3.0, outputPer1M: 15.0, cachingPer1M: 0.15 },
|
|
366
|
+
"gemini-4-neon-medium": { inputPer1M: 3.0, outputPer1M: 15.0, cachingPer1M: 0.15 },
|
|
367
|
+
"gemini-4-neon-high": { inputPer1M: 3.0, outputPer1M: 15.0, cachingPer1M: 0.15 },
|
|
368
|
+
"gemini-4-neon-xhigh": { inputPer1M: 3.0, outputPer1M: 15.0, cachingPer1M: 0.15 },
|
|
369
|
+
"gemini-4-hydrogen": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
370
|
+
"gemini-4-hydrogen-low": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
371
|
+
"gemini-4-hydrogen-medium": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
372
|
+
"gemini-4-hydrogen-high": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
373
|
+
"gemini-4-hydrogen-xhigh": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
374
|
+
"gemini-4-hydrogen-tiered": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
375
|
+
"gemini-4-hydrogen-sonar": { inputPer1M: 1.5, outputPer1M: 7.5, cachingPer1M: 0.075 },
|
|
354
376
|
"gpt-oss-120b-medium": { inputPer1M: 2.0, outputPer1M: 10.0 },
|
|
355
377
|
|
|
356
378
|
// Ollama Cloud standard-price models — mirrors MODEL_PRICING in src/types.ts
|
|
379
|
+
"beam": { inputPer1M: 0.125, outputPer1M: 0.40, cachingPer1M: 0.015 },
|
|
357
380
|
"gpt-oss:20b": { inputPer1M: 0.07, outputPer1M: 0.30, cachingPer1M: 0.035 },
|
|
358
381
|
"gpt-oss:120b": { inputPer1M: 0.15, outputPer1M: 0.60, cachingPer1M: 0.014 },
|
|
359
382
|
"deepseek-v4-flash:preview": { inputPer1M: 0.14, outputPer1M: 0.28 },
|
|
360
383
|
"deepseek-v4-flash:0731": { inputPer1M: 0.14, outputPer1M: 0.28, cachingPer1M: 0.0028 },
|
|
384
|
+
"deepseek-v4.1-flash": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.006 },
|
|
385
|
+
"deepseek-v4.1-flash:1017": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.006 },
|
|
361
386
|
"deepseek-v4-pro": { inputPer1M: 1.32, outputPer1M: 3.96, cachingPer1M: 0.044 },
|
|
387
|
+
"deepseek-v4-pro:0813": { inputPer1M: 1.74, outputPer1M: 3.48 },
|
|
362
388
|
"qwen3.5:397b": { inputPer1M: 0.60, outputPer1M: 3.60 },
|
|
363
389
|
"glm-5.1": { inputPer1M: 0.80, outputPer1M: 2.56 },
|
|
364
390
|
"glm-5.2": { inputPer1M: 1.40, outputPer1M: 4.40, cachingPer1M: 0.26 },
|
|
391
|
+
"glm-5.3": { inputPer1M: 1.40, outputPer1M: 4.40, cachingPer1M: 0.26 },
|
|
392
|
+
"glm-5.3-flash": { inputPer1M: 0.15, outputPer1M: 0.50, cachingPer1M: 0.03 },
|
|
393
|
+
"gemma4": { inputPer1M: 0.14, outputPer1M: 0.40, cachingPer1M: 0.05 },
|
|
365
394
|
"gemma4:31b": { inputPer1M: 0.14, outputPer1M: 0.40, cachingPer1M: 0.05 },
|
|
395
|
+
"hy4": { inputPer1M: 0.834, outputPer1M: 2.501, cachingPer1M: 0.042 },
|
|
396
|
+
"inkling-2-small": { inputPer1M: 0.30, outputPer1M: 1.00, cachingPer1M: 0.03 },
|
|
366
397
|
"kimi-k2.6": { inputPer1M: 0.95, outputPer1M: 4.00, cachingPer1M: 0.16 },
|
|
367
398
|
"kimi-k2.7-code": { inputPer1M: 0.95, outputPer1M: 4.00, cachingPer1M: 0.19 },
|
|
368
399
|
"kimi-k3": { inputPer1M: 3.00, outputPer1M: 15.00, cachingPer1M: 0.30 },
|
|
400
|
+
"kimi-k3.1-pro": { inputPer1M: 2.00, outputPer1M: 10.00, cachingPer1M: 0.20 },
|
|
401
|
+
"mimo-v2.6-flash": { inputPer1M: 0.14, outputPer1M: 0.28, cachingPer1M: 0.0028 },
|
|
402
|
+
"mimo-v2.6-pro": { inputPer1M: 0.435, outputPer1M: 0.87, cachingPer1M: 0.0036 },
|
|
369
403
|
"minimax-m2.7": { inputPer1M: 0.30, outputPer1M: 1.20, cachingPer1M: 0.06 },
|
|
370
404
|
"minimax-m3": { inputPer1M: 0.60, outputPer1M: 2.40, cachingPer1M: 0.12 },
|
|
405
|
+
"minimax-m3.1-flash": { inputPer1M: 0.15, outputPer1M: 0.60, cachingPer1M: 0.015 },
|
|
406
|
+
"mistral-large-4": { inputPer1M: 0.70, outputPer1M: 2.10, cachingPer1M: 0.07 },
|
|
407
|
+
"mistral-large-3": { inputPer1M: 0.50, outputPer1M: 1.50 },
|
|
371
408
|
"mistral-large-3:675b": { inputPer1M: 0.50, outputPer1M: 1.50 },
|
|
409
|
+
"muse-spark-open": { inputPer1M: 1.25, outputPer1M: 4.25, cachingPer1M: 0.15 },
|
|
410
|
+
"nemotron-3-nano": { inputPer1M: 0.06, outputPer1M: 0.24 },
|
|
372
411
|
"nemotron-3-nano:30b": { inputPer1M: 0.06, outputPer1M: 0.24 },
|
|
373
412
|
"nemotron-3-super": { inputPer1M: 0.015, outputPer1M: 0.60, cachingPer1M: 0.015 },
|
|
374
413
|
"nemotron-3-ultra": { inputPer1M: 0.10, outputPer1M: 3.00, cachingPer1M: 0.10 },
|
|
@@ -384,31 +423,34 @@ const MODEL_PRICING = {
|
|
|
384
423
|
"laguna-s-2.1-free": { inputPer1M: 0.20, outputPer1M: 0.80 },
|
|
385
424
|
|
|
386
425
|
// OpenAI Codex models — mirrors MODEL_PRICING in src/types.ts
|
|
387
|
-
"gpt-
|
|
388
|
-
"gpt-
|
|
389
|
-
"gpt-
|
|
390
|
-
"
|
|
391
|
-
"gemini-4-argon-low": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
392
|
-
"gemini-4-argon-medium": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
393
|
-
"gemini-4-argon-high": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
426
|
+
"gpt-6.2-astra": { inputPer1M: 8.0, outputPer1M: 40.0, cachingPer1M: 0.4 },
|
|
427
|
+
"gpt-6.2-sol": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
428
|
+
"gpt-6.1-sol": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.1 },
|
|
429
|
+
"gpt-6.1-terra": { inputPer1M: 1.0, outputPer1M: 5.0, cachingPer1M: 0.05 },
|
|
394
430
|
"gpt-6-astra": { inputPer1M: 10.0, outputPer1M: 50.0, cachingPer1M: 1.0 },
|
|
395
431
|
"gpt-6-sol": { inputPer1M: 2.0, outputPer1M: 10.0, cachingPer1M: 0.2 },
|
|
396
432
|
"gpt-6-luna": { inputPer1M: 0.1, outputPer1M: 0.5, cachingPer1M: 0.01 },
|
|
397
|
-
"
|
|
398
|
-
"
|
|
399
|
-
"
|
|
400
|
-
"gemma4": { inputPer1M: 0.14, outputPer1M: 0.40, cachingPer1M: 0.05 },
|
|
401
|
-
"mistral-large-4": { inputPer1M: 0.68, outputPer1M: 2.09, cachingPer1M: 0.07 },
|
|
402
|
-
"mistral-large-3": { inputPer1M: 0.50, outputPer1M: 1.50 },
|
|
403
|
-
"nemotron-3-nano": { inputPer1M: 0.06, outputPer1M: 0.24 },
|
|
404
|
-
"deepseek-v4-pro:0813": { inputPer1M: 1.74, outputPer1M: 3.48 },
|
|
433
|
+
"gpt-5.6-sol": { inputPer1M: 4.0, outputPer1M: 20.0, cachingPer1M: 0.40 },
|
|
434
|
+
"gpt-5.6-terra": { inputPer1M: 2.0, outputPer1M: 12.0, cachingPer1M: 0.20 },
|
|
435
|
+
"gpt-5.6-luna": { inputPer1M: 0.20, outputPer1M: 1.20, cachingPer1M: 0.02 },
|
|
405
436
|
};
|
|
406
437
|
|
|
407
438
|
function getModelPricing(model) {
|
|
408
439
|
if (MODEL_PRICING[model]) return MODEL_PRICING[model];
|
|
409
440
|
const lower = (model || "").toLowerCase();
|
|
410
|
-
if (lower
|
|
411
|
-
if (lower.includes("
|
|
441
|
+
if (MODEL_PRICING[lower]) return MODEL_PRICING[lower];
|
|
442
|
+
if (lower.includes("opus")) {
|
|
443
|
+
if (lower.includes("5-5") || lower.includes("5.5")) return MODEL_PRICING["claude-opus-5-5"];
|
|
444
|
+
return MODEL_PRICING["claude-opus-4-6-thinking"];
|
|
445
|
+
}
|
|
446
|
+
if (lower.includes("sonnet")) {
|
|
447
|
+
if (lower.includes("5-5") || lower.includes("5.5")) return MODEL_PRICING["claude-sonnet-5-5"];
|
|
448
|
+
return MODEL_PRICING["claude-sonnet-4-6"];
|
|
449
|
+
}
|
|
450
|
+
if (lower.includes("4-carbon") || lower.includes("4.0-carbon")) return MODEL_PRICING["gemini-4-carbon"];
|
|
451
|
+
if (lower.includes("4-argon") || lower.includes("4.0-argon")) return MODEL_PRICING["gemini-4-argon"];
|
|
452
|
+
if (lower.includes("4-neon") || lower.includes("4.0-neon")) return MODEL_PRICING["gemini-4-neon"];
|
|
453
|
+
if (lower.includes("4-hydrogen") || lower.includes("4.0-hydrogen")) return MODEL_PRICING["gemini-4-hydrogen"];
|
|
412
454
|
if (lower.includes("3.8-flash")) return MODEL_PRICING["gemini-3.8-flash-high"];
|
|
413
455
|
if (lower.includes("3.7-flash")) return MODEL_PRICING["gemini-3.7-flash-tiered"];
|
|
414
456
|
if (lower.includes("3.6-flash")) return MODEL_PRICING["gemini-3.6-flash-high"];
|