mapigate 0.5.136 → 0.5.146
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/README.md +8 -8
- package/dist/cli/commands/logs.js +0 -1
- package/dist/core/adapters/anthropic/requestOpenAiToAnthropic.js +1 -1
- package/dist/core/adapters/helpers/toolCallRescue.js +1 -1
- package/dist/core/adapters/responsesAdapter.js +11 -0
- package/dist/core/capabilities/index.js +5 -4
- package/dist/core/capabilities/modelDictionary.js +1 -0
- package/dist/core/scanner/modelScanner.js +2 -1
- package/dist/core/scanner/payloadExtractor.js +1 -1
- package/dist/core/scanner/urlResolver.js +16 -0
- package/dist/core/tokenSaver/methods/rtk/autodetect.js +1 -1
- package/dist/core/tokenSaver/methods/rtk/filters/gitLog.js +1 -1
- package/dist/core/usage/pricing.js +98 -42
- package/dist/core/usage/tokenExtractor.js +59 -0
- package/dist/mitm/handlers/antigravity/config.js +22 -0
- package/dist/mitm/handlers/antigravity/modelInjector.js +2 -2
- package/dist/providers/catalog/coarena/index.js +3 -0
- package/dist/providers/catalog/coarena/metadata.js +104 -0
- package/dist/providers/catalog/coarena/provider.js +91 -0
- package/dist/providers/catalog/coarena/quota.js +119 -0
- package/dist/providers/catalog/iflow/provider.js +1 -1
- package/dist/providers/catalog/iteracompute/metadata.js +154 -13
- package/dist/providers/catalog/iteracompute/provider.js +111 -0
- package/dist/providers/catalog/opencode-go/responsesPayload.js +1 -1
- package/dist/providers/catalog/openrouter/metadata.js +1 -0
- package/dist/providers/core/base/baseProvider.js +5 -3
- package/dist/providers/generated/chunks/chunk1.js +2 -2
- package/dist/providers/generated/chunks/chunk2.js +2 -2
- package/dist/providers/generated/chunks/chunk3.js +2 -2
- package/dist/providers/generated/chunks/chunk4.js +2 -0
- package/dist/providers/generated/runtime/chunk1.js +2 -2
- package/dist/providers/generated/runtime/chunk2.js +2 -2
- package/dist/providers/generated/runtime/chunk3.js +2 -2
- package/dist/providers/generated/runtime/chunk4.js +2 -0
- package/dist/providers/runtime/antigravity/executor.js +2 -2
- package/dist/providers/runtime/antigravity/metadata.js +2 -2
- package/dist/providers/runtime/antigravity/models.js +9 -0
- package/dist/providers/runtime/antigravity/provider.js +2 -2
- package/dist/providers/runtime/antigravity/routes.js +2 -2
- package/dist/providers/runtime/antigravity/schema.js +1 -1
- package/dist/providers/runtime/antigravity/types.js +10 -2
- package/dist/providers/runtime/gemini/provider.js +77 -0
- package/dist/providers/runtime/gemini-cli/provider.js +2 -2
- package/dist/providers/runtime/github/routes.js +1 -1
- package/dist/providers/runtime/grok/provider.js +1 -1
- package/dist/providers/runtime/kiro/provider.js +1 -1
- package/dist/providers/runtime/minimax/routes.js +0 -1
- package/dist/providers/runtime/opencode/tools.js +1 -1
- package/dist/providers/runtime/trae/index.js +1 -0
- package/dist/providers/runtime/trae/metadata.js +1 -0
- package/dist/providers/runtime/trae/provider.js +7 -0
- package/dist/providers/runtime/trae/quota.js +99 -0
- package/dist/providers/runtime/windsurf/routes.js +0 -2
- package/dist/providers/runtime/xkiro/quota.js +4 -1
- package/dist/providers/runtime/zed/metadata.js +1 -1
- package/dist/providers/runtime/zed/models.js +68 -8
- package/dist/providers/runtime/zed/provider.js +60 -15
- package/dist/providers/runtime/zed/quota.js +69 -12
- package/dist/providers/runtime/zed/routes.js +7 -0
- package/dist/server/proxy/executorHelpers.js +1 -1
- package/dist/server/proxy/index.js +1 -1
- package/dist/server/proxy/pipeline.js +12 -6
- package/dist/server/proxy/responseHandlers.js +2 -18
- package/dist/server/proxy/singleModelExecutor.js +1 -1
- package/dist/server/proxy/streaming/sseStreamer.js +3 -10
- package/dist/server/routes/apiMitm.js +1 -1
- package/dist/server/routes/apiModels.js +17 -12
- package/dist/server/utils/consoleLogBuffer.js +3 -3
- package/dist/shared/constants/index.js +2 -2
- package/dist/shared/constants/quotaOrder.js +5 -0
- package/dist/shared/logger.js +2 -2
- package/dist/storage/repositories/logRepo.js +3 -23
- package/dist/storage/repositories/requestDetailsRepo.js +1 -1
- package/dist/storage/repositories/usageRepo.js +136 -74
- package/dist/web/assets/{CliToolsTab-CkzwuwaC.js → CliToolsTab-BYO-wJ7y.js} +1 -1
- package/dist/web/assets/CombosTab-CujUAbYQ.js +1 -0
- package/dist/web/assets/{ConfirmModal-DGvcf0gB.js → ConfirmModal-BS3mAUd5.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-84Ens8T5.js → ConsoleLogTab-CSgZxPGW.js} +1 -1
- package/dist/web/assets/{EditAccountModal-D-_omvev.js → EditAccountModal-BhPOk3Ya.js} +1 -1
- package/dist/web/assets/{EndpointTab-7nBfEdYE.js → EndpointTab-BRVjAng2.js} +1 -1
- package/dist/web/assets/{MitmTab-CqS6mXHZ.js → MitmTab-ZOoWyRnb.js} +5 -5
- package/dist/web/assets/{ModelAutocompleteInput-B9syrV1O.js → ModelAutocompleteInput-DJkxW2yD.js} +1 -1
- package/dist/web/assets/{ProviderDetailPage-DGZceQ2d.js → ProviderDetailPage-CnWjM-0J.js} +2 -2
- package/dist/web/assets/ProvidersTab-BFdg0gXr.js +1 -0
- package/dist/web/assets/QuotaTab-DXg3adeS.js +1 -0
- package/dist/web/assets/{SettingsTab-4c0ksNJa.js → SettingsTab-DoYGKtDn.js} +1 -1
- package/dist/web/assets/UsageTab-O6OK0i38.js +1 -0
- package/dist/web/assets/index-5TzViNxR.js +2 -0
- package/dist/web/assets/metadataRegistry-W75_wn57.js +1 -0
- package/dist/web/assets/providers/coarena/icon.png +0 -0
- package/dist/web/assets/providers/coarena/icon.svg +3 -0
- package/dist/web/assets/providers/openrouter/icon.png +0 -0
- package/dist/web/assets/{providersData-DkVCRBsJ.js → providersData-BI_7MaUL.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +9 -1
- package/dist/web/assets/CombosTab-C5RzRwwr.js +0 -1
- package/dist/web/assets/ProvidersTab-CiYbqRou.js +0 -1
- package/dist/web/assets/QuotaTab-DFr0DWAU.js +0 -1
- package/dist/web/assets/UsageTab-BQcPmvtQ.js +0 -1
- package/dist/web/assets/index-C4NTQZ40.js +0 -2
- package/dist/web/assets/metadataRegistry-B91sal4r.js +0 -1
- package/dist/web/assets/providers/openrouter/openrouter.png +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Local-first AI model gateway and token optimizer for coding assistants
|
|
6
6
|
|
|
7
|
-
**One local endpoint (`http://127.0.0.1:20128`) that speaks the OpenAI, Anthropic, and Responses APIs, and routes to
|
|
7
|
+
**One local endpoint (`http://127.0.0.1:20128`) that speaks the OpenAI, Anthropic, and Responses APIs, and routes to 152+ AI providers.**
|
|
8
8
|
*Works with Claude Code, Cursor, Cline, Codex, OpenCode, and 26 coding tools in total, plus GitHub Copilot, Kiro IDE, and Antigravity through a local MITM proxy.*
|
|
9
9
|
|
|
10
10
|
---
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
[](#)
|
|
15
15
|
[](https://www.typescriptlang.org/)
|
|
16
|
-
[](package.json)
|
|
17
17
|
|
|
18
|
-
[**What is Mapigate?**](#-what-is-mapigate) • [**Gateway API**](#-gateway-api) • [**Supported Providers**](#-supported-providers-
|
|
18
|
+
[**What is Mapigate?**](#-what-is-mapigate) • [**Gateway API**](#-gateway-api) • [**Supported Providers**](#-supported-providers-152) • [**Quick Start**](#-quick-start-get-running-in-60s) • [**Token Saver**](#-feature-1-token-saver-modular-token-optimization) • [**Smart Routing & Combos**](#-feature-2-smart-routing--combo-engine) • [**Connect Coding Tools**](#-feature-3-one-click-connection-for-26-coding-assistants) • [**MITM Interceptor**](#-feature-4-mitm-https-interceptor-for-closed-tools) • [**Web Dashboard**](#-feature-5-web-dashboard-tour) • [**CLI Reference**](#-cli-reference-mapigate--mpg)
|
|
19
19
|
|
|
20
20
|
</div>
|
|
21
21
|
|
|
@@ -30,7 +30,7 @@ Mapigate is a local API gateway that runs on your machine (Node.js, single port
|
|
|
30
30
|
| | |
|
|
31
31
|
| :--- | :--- |
|
|
32
32
|
| **Client APIs** | OpenAI Chat Completions (`/v1/chat/completions`), Anthropic Messages (`/v1/messages`), OpenAI Responses (`/v1/responses`), model list (`/v1/models`). Streaming and non-streaming. |
|
|
33
|
-
| **Providers** |
|
|
33
|
+
| **Providers** | 152+ built in: 32 runtime (OAuth / custom auth: Claude, OpenAI, Gemini, Copilot, Codex, Kiro, Cursor, Bedrock, Azure…), 119 catalog (OpenRouter, Groq, Cerebras, Mistral, Together, Moonshot, Z.ai, local Ollama / LM Studio…), plus the combo engine. More via the community catalog. |
|
|
34
34
|
| **Coding tools** | 26 with config definitions (`mpg connect`): Claude Code, Codex, OpenCode, Cline, Roo Code, Continue, Qwen Code, Crush, Factory Droid… Cursor via base URL override. Copilot, Kiro IDE, and Antigravity via MITM. |
|
|
35
35
|
| **Routing** | Model aliases, global and per-tool model mappings, combos (`fallback`, `round-robin`, `fusion`, `lkgp`, `p2c`), multi-account rotation (`round-robin` / `fill-first`), automatic fallback on 429 and quota errors. |
|
|
36
36
|
| **Token saving** | Modular Token Saver: RTK in-place compression (`git diff`, terminal logs, search results — 20–40% fewer input tokens), Caveman style compression, Ponytail minimalist coding, and Custom Prompts. Fail-open, and error results are never compressed. |
|
|
@@ -63,7 +63,7 @@ graph TD
|
|
|
63
63
|
VAULT[("SQLite (WAL) + AES-256-GCM vault")]
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
subgraph UPSTREAM["
|
|
66
|
+
subgraph UPSTREAM["152+ providers"]
|
|
67
67
|
P1["Runtime: Claude, OpenAI, Gemini, Copilot, Codex, Kiro, Bedrock..."]
|
|
68
68
|
P2["Catalog: OpenRouter, Groq, Cerebras, Mistral, Together..."]
|
|
69
69
|
P3["Local: Ollama, LM Studio, Jan"]
|
|
@@ -115,14 +115,14 @@ The dashboard and CLI use a REST management API under `/api/*` (providers, accou
|
|
|
115
115
|
|
|
116
116
|
---
|
|
117
117
|
|
|
118
|
-
## 🌐 Supported Providers (
|
|
118
|
+
## 🌐 Supported Providers (152+)
|
|
119
119
|
|
|
120
|
-
Mapigate ships with **
|
|
120
|
+
Mapigate ships with **152+ provider modules**, discovered automatically from `src/providers/` by `npm run codegen`:
|
|
121
121
|
|
|
122
122
|
| Tier | Count | What it covers |
|
|
123
123
|
| :--- | :---: | :--- |
|
|
124
124
|
| **Runtime** (`src/providers/runtime/`) | 32 | Providers with custom auth, OAuth, or streaming: `claude`, `openai`, `gemini`, `gemini-cli`, `antigravity`, `bedrock`, `azure`, `cloudflare`, `deepseek`, `github` (Copilot), `codex`, `cursor`, `cursor-api`, `kiro`, `xkiro`, `windsurf`, `zed`, `trae`, `qoder`, `cline`, `codebuddy`, `devin`, `opencode`, `grok`, `grok-cli`, `kimi`, `glm`, `minimax`, `minimax-code`, `mimo`, `alicode`, `ollama` |
|
|
125
|
-
| **Catalog** (`src/providers/catalog/`) |
|
|
125
|
+
| **Catalog** (`src/providers/catalog/`) | 119 | Standard OpenAI/Anthropic-compatible API-key providers: Anthropic, OpenRouter, Groq, Cerebras, Together, Fireworks, DeepInfra, Mistral, Codestral, Cohere, Perplexity, NVIDIA, Hugging Face, Vertex AI, Databricks, Snowflake, watsonx, SambaNova, Nebius, Novita, SiliconFlow, Moonshot, Z.ai, StepFun, Baidu, Tencent, Volcengine, Vercel AI Gateway, LM Studio, Jan, local Ollama, Coarena, and more |
|
|
126
126
|
| **Composite** (`src/providers/composite/`) | 1 | The `combo` engine (fallback, round-robin, fusion, lkgp, p2c) |
|
|
127
127
|
| **Community catalog** | — | Additional providers importable from the dashboard (**Providers → Community Catalog**) |
|
|
128
128
|
|
|
@@ -18,7 +18,6 @@ function lineMatchesLevel(line, minLevel) {
|
|
|
18
18
|
const isInfo = upper.includes("[INFO]") || line.includes("ℹ️") || line.includes("DONE") || line.includes("📥") || line.includes("▶") || line.includes("⚙") || line.includes("📊");
|
|
19
19
|
if (minLevel === LogLevel.INFO)
|
|
20
20
|
return isErr || isWarn || isInfo || (!upper.includes("[DEBUG]") && !line.includes("🔬"));
|
|
21
|
-
const isDebug = upper.includes("[DEBUG]") || line.includes("🔍");
|
|
22
21
|
if (minLevel === LogLevel.DEBUG)
|
|
23
22
|
return !line.includes("🔬") && !upper.includes("[TRACE]");
|
|
24
23
|
return true;
|
|
@@ -111,7 +111,7 @@ export function translateOpenAiToAnthropic(openAiBody, modelOverride, providerId
|
|
|
111
111
|
let textContent = typeof msg.content === "string" ? msg.content : "";
|
|
112
112
|
const hasToolCalls = Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0;
|
|
113
113
|
// Inline dialect rescue if no structured tool_calls present
|
|
114
|
-
|
|
114
|
+
const rescuedBlocks = [];
|
|
115
115
|
if (!hasToolCalls && textContent && toolNames.size > 0) {
|
|
116
116
|
const rescue = rescueInlineToolCalls(textContent, toolNames);
|
|
117
117
|
if (rescue.detected && rescue.calls && rescue.calls.length > 0) {
|
|
@@ -424,7 +424,7 @@ function parseXmlDialect(text, toolNames) {
|
|
|
424
424
|
matches.push(m[1]);
|
|
425
425
|
}
|
|
426
426
|
for (const inner of matches) {
|
|
427
|
-
|
|
427
|
+
const call = parseAnyToolBlock(inner, toolNames);
|
|
428
428
|
if (call)
|
|
429
429
|
calls.push(call);
|
|
430
430
|
else
|
|
@@ -182,6 +182,17 @@ export function convertResponsesApiFormat(body) {
|
|
|
182
182
|
delete result.prompt_cache_key;
|
|
183
183
|
delete result.store;
|
|
184
184
|
delete result.reasoning;
|
|
185
|
+
delete result.origin;
|
|
186
|
+
delete result.profileArn;
|
|
187
|
+
delete result.previous_response_id;
|
|
188
|
+
delete result.text;
|
|
189
|
+
delete result.truncation;
|
|
190
|
+
delete result.background;
|
|
191
|
+
delete result.max_tool_calls;
|
|
192
|
+
delete result.prompt_cache_retention;
|
|
193
|
+
delete result.safety_identifier;
|
|
194
|
+
delete result.conversation;
|
|
195
|
+
delete result.inferenceConfig;
|
|
185
196
|
if (result.stream === undefined) {
|
|
186
197
|
result.stream = true;
|
|
187
198
|
}
|
|
@@ -38,9 +38,10 @@ export function getCapabilitiesForModel(provider, model) {
|
|
|
38
38
|
return { ...DEFAULT_CAPABILITIES };
|
|
39
39
|
const baseModel = model.includes("/") ? model.split("/").pop() : model;
|
|
40
40
|
const inferredProvider = (!provider && model.includes("/")) ? model.split("/")[0] : provider;
|
|
41
|
+
const cleanProvider = inferredProvider ? inferredProvider.replace(/\[.*?\]$/, "") : null;
|
|
41
42
|
// 1. Primary Source of Truth: Provider Metadata Registry
|
|
42
|
-
if (
|
|
43
|
-
const regProvider = getRegistryProvider(
|
|
43
|
+
if (cleanProvider) {
|
|
44
|
+
const regProvider = getRegistryProvider(cleanProvider);
|
|
44
45
|
if (regProvider?.models) {
|
|
45
46
|
const match = regProvider.models.find((m) => m.id === model ||
|
|
46
47
|
m.id === baseModel ||
|
|
@@ -76,8 +77,8 @@ export function getCapabilitiesForModel(provider, model) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
// 2. Provider-specific runtime override
|
|
79
|
-
if (
|
|
80
|
-
const pCaps = PROVIDER_CAPABILITIES[
|
|
80
|
+
if (cleanProvider && PROVIDER_CAPABILITIES[cleanProvider]) {
|
|
81
|
+
const pCaps = PROVIDER_CAPABILITIES[cleanProvider];
|
|
81
82
|
if (pCaps[model])
|
|
82
83
|
return { ...DEFAULT_CAPABILITIES, ...pCaps[model] };
|
|
83
84
|
if (pCaps[baseModel])
|
|
@@ -94,6 +94,7 @@ export const STANDARD_MODELS = {
|
|
|
94
94
|
// ── Google Gemini & Gemma ──
|
|
95
95
|
"gemini-4-argon": "Gemini 4 Argon",
|
|
96
96
|
"gemini-4-carbon": "Gemini 4 Carbon",
|
|
97
|
+
"gemini-4-hydrogen": "Gemini 4 Hydrogen",
|
|
97
98
|
"gemini-4-ultra": "Gemini 4 Ultra",
|
|
98
99
|
"gemini-4-pro": "Gemini 4 Pro",
|
|
99
100
|
"gemini-4-flash": "Gemini 4 Flash",
|
|
@@ -12,7 +12,8 @@ export { extractModelsFromPayload } from "./payloadExtractor.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export async function scanProviderModels(options) {
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
const { providerId, accountId, apiKey, timeoutMs = 8000, providerSpecificData } = options;
|
|
16
|
+
let { baseUrl, customHeaders, format, region } = options;
|
|
16
17
|
let registryItem;
|
|
17
18
|
if (providerId) {
|
|
18
19
|
registryItem = getRegistryProvider(providerId);
|
|
@@ -107,7 +107,7 @@ export function extractModelsFromPayload(data, providerId) {
|
|
|
107
107
|
}
|
|
108
108
|
if (typeof item === "object") {
|
|
109
109
|
const rec = item;
|
|
110
|
-
|
|
110
|
+
const rawId = rec.id || rec.slug || rec.name || rec.model || rec.model_name || rec.code || rec.modelId;
|
|
111
111
|
if (typeof rawId !== "string" && typeof rawId !== "number")
|
|
112
112
|
continue;
|
|
113
113
|
let id = String(rawId).trim();
|
|
@@ -60,6 +60,22 @@ export function resolveCandidateUrls(baseUrl, format, providerId, registryItem,
|
|
|
60
60
|
add(cleanBase);
|
|
61
61
|
return candidates;
|
|
62
62
|
}
|
|
63
|
+
// IteraCompute endpoint resolution (strictly scoped to /v1/models, root /models is 404)
|
|
64
|
+
const isIteraCompute = providerId === "iteracompute" ||
|
|
65
|
+
providerId === "itera" ||
|
|
66
|
+
registryItem?.id === "iteracompute" ||
|
|
67
|
+
registryItem?.alias === "iteracompute" ||
|
|
68
|
+
lowerBase.includes("iteracompute.com");
|
|
69
|
+
if (isIteraCompute) {
|
|
70
|
+
add("https://api.iteracompute.com/v1/models");
|
|
71
|
+
if (cleanBase.endsWith("/v1")) {
|
|
72
|
+
add(`${cleanBase}/models`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
add(`${cleanBase}/v1/models`);
|
|
76
|
+
}
|
|
77
|
+
return candidates;
|
|
78
|
+
}
|
|
63
79
|
// OpenCode Free discovery endpoint - strictly scoped to OpenCode Free, excluding paid opencode-go and opencode-zen
|
|
64
80
|
const isOpenCodeFree = (providerId === "opencode" ||
|
|
65
81
|
providerId === "oc" ||
|
|
@@ -19,7 +19,7 @@ const RE_GIT_LOG = /^[*|/\\ ]*commit [0-9a-f]{7,40}$/m;
|
|
|
19
19
|
const RE_PORCELAIN = /^[ MADRCU?!][ MADRCU?!] \S/m;
|
|
20
20
|
const RE_BUILD_OUTPUT = /^(npm (warn|error|ERR!)|yarn (warn|error)|\s*Compiling\s+\S+|\s*Downloading\s+\S+|added \d+ package|\[ERROR\]|BUILD (SUCCESS|FAILED)|\s*Finished\s+|Successfully (installed|built)|ERROR:)/im;
|
|
21
21
|
const RE_ANSI_OR_SPINNER = /\x1b\[[0-9;]*[a-zA-Z]|\[=+\]\s*\d+%|\[(?:progress|\.\.\.)\]/m;
|
|
22
|
-
const RE_TREE_GLYPH = /[├└]──|│
|
|
22
|
+
const RE_TREE_GLYPH = /[├└]──|│ {2}/;
|
|
23
23
|
const RE_LS_ROW = /^[-dlbcps][rwx-]{9}/m;
|
|
24
24
|
const RE_LS_TOTAL = /^total \d+$/m;
|
|
25
25
|
function isBase64Data(text) {
|
|
@@ -40,7 +40,7 @@ export function gitLog(text, maxLines = GIT_LOG_MAX_LINES) {
|
|
|
40
40
|
if (trimmed === "")
|
|
41
41
|
continue;
|
|
42
42
|
// indented subject (4 spaces, optionally preceded by graph decoration)
|
|
43
|
-
if (!subjectSeen && /^[*|/\\ ]*
|
|
43
|
+
if (!subjectSeen && /^[*|/\\ ]* {4}\S/.test(line)) {
|
|
44
44
|
pushLine(" Subject: " + trimmed);
|
|
45
45
|
subjectSeen = true;
|
|
46
46
|
continue;
|
|
@@ -6,6 +6,67 @@ export const ZERO_PRICING = {
|
|
|
6
6
|
reasoning: 0,
|
|
7
7
|
cache_creation: 0,
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Regex matching common model suffixes:
|
|
11
|
+
* - Dates: 20241022, 2025-02-19
|
|
12
|
+
* - Tiers: high, medium, low, extra-low, tiered
|
|
13
|
+
* - Modes / Tags: thinking, reasoning, preview, latest, extended, instruct, chat, turbo, online, search, free, beta, exact, v1, v2
|
|
14
|
+
*/
|
|
15
|
+
export const MODEL_SUFFIX_REGEX = /[-:_.](high|medium|low|extra-low|thinking|reasoning|free|beta|exact|preview|latest|extended|instruct|chat|turbo|online|search|tiered|v\d+|\d{8}|\d{4}-\d{2}-\d{2})$/i;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts normalized candidate model IDs for pricing lookup.
|
|
18
|
+
* Automatically removes:
|
|
19
|
+
* 1. Provider/vendor prefixes (e.g. "anthropic/claude-3-5-sonnet" -> "claude-3-5-sonnet")
|
|
20
|
+
* 2. Bracket tags (e.g. "[1m]")
|
|
21
|
+
* 3. Iterative suffixes (dates like -20241022, tiers like -high, modes like -thinking)
|
|
22
|
+
* 4. Generates dot vs dash version aliases (e.g. claude-3-5-sonnet <-> claude-3.5-sonnet)
|
|
23
|
+
*/
|
|
24
|
+
export function extractModelPricingCandidates(model) {
|
|
25
|
+
if (!model)
|
|
26
|
+
return [];
|
|
27
|
+
// 1. Strip vendor prefixes
|
|
28
|
+
let clean = model.includes("/") ? model.split("/").pop() : model;
|
|
29
|
+
clean = clean.trim().toLowerCase();
|
|
30
|
+
// 2. Strip bracket tags like [1m], [2m]
|
|
31
|
+
clean = clean.replace(/\[[^\]]+\]/g, "");
|
|
32
|
+
const candidates = [];
|
|
33
|
+
if (clean)
|
|
34
|
+
candidates.push(clean);
|
|
35
|
+
// 3. Iteratively strip recognized suffixes (dates, tiers, modes, tags)
|
|
36
|
+
let base = clean;
|
|
37
|
+
let stripping = true;
|
|
38
|
+
while (stripping) {
|
|
39
|
+
const match = base.match(MODEL_SUFFIX_REGEX);
|
|
40
|
+
if (match && match.index !== undefined && match.index > 0) {
|
|
41
|
+
base = base.slice(0, match.index);
|
|
42
|
+
if (base && !candidates.includes(base)) {
|
|
43
|
+
candidates.push(base);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
stripping = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// 4. Dot vs Dash version variants
|
|
51
|
+
const variants = [];
|
|
52
|
+
for (const c of candidates) {
|
|
53
|
+
// claude-3-5-xxx <-> claude-3.5-xxx
|
|
54
|
+
const dot1 = c.replace(/claude-(\d+)-(\d+)/g, "claude-$1.$2");
|
|
55
|
+
if (dot1 !== c && !candidates.includes(dot1))
|
|
56
|
+
variants.push(dot1);
|
|
57
|
+
const dash1 = c.replace(/claude-(\d+)\.(\d+)/g, "claude-$1-$2");
|
|
58
|
+
if (dash1 !== c && !candidates.includes(dash1))
|
|
59
|
+
variants.push(dash1);
|
|
60
|
+
// claude-(opus|sonnet|haiku)-(\d+)-(\d+) <-> claude-$1-$2.$3
|
|
61
|
+
const dot2 = c.replace(/claude-(opus|sonnet|haiku)-(\d+)-(\d+)/g, "claude-$1-$2.$3");
|
|
62
|
+
if (dot2 !== c && !candidates.includes(dot2))
|
|
63
|
+
variants.push(dot2);
|
|
64
|
+
const dash2 = c.replace(/claude-(opus|sonnet|haiku)-(\d+)\.(\d+)/g, "claude-$1-$2-$3");
|
|
65
|
+
if (dash2 !== c && !candidates.includes(dash2))
|
|
66
|
+
variants.push(dash2);
|
|
67
|
+
}
|
|
68
|
+
return [...candidates, ...variants];
|
|
69
|
+
}
|
|
9
70
|
export const FREE_MODEL_NAMESPACES = ["cline-free/", "free/", "local/"];
|
|
10
71
|
export function isFreeModel(model) {
|
|
11
72
|
if (!model)
|
|
@@ -22,31 +83,26 @@ export const MODEL_PRICING = {
|
|
|
22
83
|
"claude-opus-5.5": { input: 4.00, output: 20.00, cached: 0.40, reasoning: 20.00, cache_creation: 5.00 },
|
|
23
84
|
"claude-opus-5": { input: 5.00, output: 25.00, cached: 0.50, reasoning: 25.00, cache_creation: 6.25 },
|
|
24
85
|
"claude-opus-4-6": { input: 5.00, output: 25.00, cached: 0.50, reasoning: 25.00, cache_creation: 6.25 },
|
|
25
|
-
"claude-opus-4
|
|
86
|
+
"claude-opus-4.5": { input: 5.00, output: 25.00, cached: 0.50, reasoning: 25.00, cache_creation: 6.25 },
|
|
87
|
+
"claude-opus-4.1": { input: 15.00, output: 75.00, cached: 1.50, reasoning: 75.00, cache_creation: 18.75 },
|
|
88
|
+
"claude-opus-4": { input: 15.00, output: 25.00, cached: 7.50, reasoning: 112.50, cache_creation: 15.00 },
|
|
26
89
|
"claude-sonnet-5.5": { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.50 },
|
|
27
90
|
"claude-sonnet-5": { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.50 },
|
|
28
91
|
"claude-sonnet-4-6": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
29
|
-
"claude-sonnet-4
|
|
92
|
+
"claude-sonnet-4.5": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
93
|
+
"claude-sonnet-4": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
30
94
|
"claude-haiku-5.5": { input: 0.10, output: 0.50, cached: 0.01, reasoning: 0.50, cache_creation: 0.125 },
|
|
31
|
-
"claude-haiku-4
|
|
32
|
-
"claude-sonnet
|
|
33
|
-
"claude-opus-4-20250514": { input: 15.00, output: 25.00, cached: 7.50, reasoning: 112.50, cache_creation: 15.00 },
|
|
34
|
-
"claude-3-7-sonnet-20250219": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
95
|
+
"claude-haiku-4.5": { input: 1.00, output: 5.00, cached: 0.10, reasoning: 5.00, cache_creation: 1.25 },
|
|
96
|
+
"claude-3.7-sonnet": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
35
97
|
"claude-3-7-sonnet": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
98
|
+
"claude-3.5-sonnet": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
36
99
|
"claude-3-5-sonnet": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"claude-3-
|
|
40
|
-
"claude-3-
|
|
41
|
-
"claude-3-5-haiku-20241022": { input: 0.80, output: 4.00, cached: 0.08, reasoning: 4.00, cache_creation: 1.00 },
|
|
42
|
-
"claude-haiku-4.5": { input: 1.00, output: 5.00, cached: 0.10, reasoning: 5.00, cache_creation: 1.25 },
|
|
43
|
-
"claude-opus-4.1": { input: 15.00, output: 75.00, cached: 1.50, reasoning: 75.00, cache_creation: 18.75 },
|
|
44
|
-
"claude-opus-4.5": { input: 5.00, output: 25.00, cached: 0.50, reasoning: 25.00, cache_creation: 6.25 },
|
|
45
|
-
"claude-sonnet-4": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
46
|
-
"claude-sonnet-4.5": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.75 },
|
|
100
|
+
"claude-3.5-haiku": { input: 0.80, output: 4.00, cached: 0.08, reasoning: 4.00, cache_creation: 1.00 },
|
|
101
|
+
"claude-3-5-haiku": { input: 0.80, output: 4.00, cached: 0.08, reasoning: 4.00, cache_creation: 1.00 },
|
|
102
|
+
"claude-3-opus": { input: 15.00, output: 75.00, cached: 1.50, reasoning: 75.00, cache_creation: 18.75 },
|
|
103
|
+
"claude-3-haiku": { input: 0.25, output: 1.25, cached: 0.025, reasoning: 1.25, cache_creation: 0.3125 },
|
|
47
104
|
// === OpenAI / GPT ===
|
|
48
105
|
"gpt-4o": { input: 2.50, output: 10.00, cached: 1.25, reasoning: 15.00, cache_creation: 2.50 },
|
|
49
|
-
"openai/gpt-4o": { input: 2.50, output: 10.00, cached: 1.25, reasoning: 15.00, cache_creation: 2.50 },
|
|
50
106
|
"gpt-4o-mini": { input: 0.15, output: 0.60, cached: 0.075, reasoning: 0.90, cache_creation: 0.15 },
|
|
51
107
|
"gpt-4.1": { input: 2.50, output: 10.00, cached: 1.25, reasoning: 15.00, cache_creation: 2.50 },
|
|
52
108
|
"gpt-5": { input: 1.25, output: 10.00, cached: 0.625, reasoning: 10.00, cache_creation: 1.25 },
|
|
@@ -71,31 +127,24 @@ export const MODEL_PRICING = {
|
|
|
71
127
|
"o1-mini": { input: 3.00, output: 12.00, cached: 1.50, reasoning: 18.00, cache_creation: 3.00 },
|
|
72
128
|
"o3": { input: 2.00, output: 8.00, cached: 0.50, reasoning: 8.00, cache_creation: 2.00 },
|
|
73
129
|
"o3-mini": { input: 1.10, output: 4.40, cached: 0.55, reasoning: 4.40, cache_creation: 1.10 },
|
|
74
|
-
"openai/o3-mini": { input: 1.10, output: 4.40, cached: 0.55, reasoning: 4.40, cache_creation: 1.10 },
|
|
75
130
|
"o4-mini": { input: 1.10, output: 4.40, cached: 0.275, reasoning: 4.40, cache_creation: 1.10 },
|
|
76
131
|
// === Google / Gemini ===
|
|
77
132
|
"gemini-2.5-pro": { input: 2.00, output: 12.00, cached: 0.25, reasoning: 18.00, cache_creation: 2.00 },
|
|
78
|
-
"google/gemini-2.5-pro": { input: 2.00, output: 12.00, cached: 0.25, reasoning: 18.00, cache_creation: 2.00 },
|
|
79
133
|
"gemini-2.5-flash": { input: 0.15, output: 0.60, cached: 0.0375, reasoning: 0.60, cache_creation: 0.15 },
|
|
80
|
-
"google/gemini-2.5-flash": { input: 0.15, output: 0.60, cached: 0.0375, reasoning: 0.60, cache_creation: 0.15 },
|
|
81
134
|
"gemini-3-flash": { input: 0.50, output: 3.00, cached: 0.03, reasoning: 4.50, cache_creation: 0.50 },
|
|
82
135
|
"gemini-3-pro": { input: 2.00, output: 12.00, cached: 0.25, reasoning: 18.00, cache_creation: 2.00 },
|
|
83
136
|
"gemini-3.7-flash": { input: 1.50, output: 7.50, cached: 0.15, reasoning: 11.25, cache_creation: 1.875 },
|
|
84
137
|
"gemini-3.8-flash": { input: 1.50, output: 7.50, cached: 0.15, reasoning: 11.25, cache_creation: 1.875 },
|
|
85
138
|
"gemini-4-argon": { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 },
|
|
86
|
-
"
|
|
87
|
-
"
|
|
139
|
+
"gemini-4-carbon": { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 },
|
|
140
|
+
"gemini-4-hydrogen": { input: 1.50, output: 7.50, cached: 0.075, reasoning: 7.50, cache_creation: 1.50 },
|
|
88
141
|
// === DeepSeek ===
|
|
89
142
|
"deepseek-chat": { input: 0.14, output: 0.28, cached: 0.014, reasoning: 0.28, cache_creation: 0.14 },
|
|
90
143
|
"deepseek-reasoner": { input: 0.55, output: 2.19, cached: 0.14, reasoning: 2.19, cache_creation: 0.55 },
|
|
91
144
|
"deepseek-r1": { input: 0.55, output: 2.19, cached: 0.14, reasoning: 2.19, cache_creation: 0.55 },
|
|
92
|
-
"deepseek/deepseek-r1": { input: 0.55, output: 2.19, cached: 0.14, reasoning: 2.19, cache_creation: 0.55 },
|
|
93
145
|
"deepseek-v3": { input: 0.14, output: 0.28, cached: 0.014, reasoning: 0.28, cache_creation: 0.14 },
|
|
94
|
-
"deepseek/deepseek-v3": { input: 0.14, output: 0.28, cached: 0.014, reasoning: 0.28, cache_creation: 0.14 },
|
|
95
146
|
"deepseek-v4.1-flash": { input: 0.14, output: 0.28, cached: 0.014, reasoning: 0.28, cache_creation: 0.14 },
|
|
96
|
-
"deepseek/deepseek-v4.1-flash": { input: 0.14, output: 0.28, cached: 0.014, reasoning: 0.28, cache_creation: 0.14 },
|
|
97
147
|
"deepseek-v4-pro": { input: 0.66, output: 1.98, cached: 0.066, reasoning: 1.98, cache_creation: 0.66 },
|
|
98
|
-
"deepseek/deepseek-v4-pro": { input: 0.66, output: 1.98, cached: 0.066, reasoning: 1.98, cache_creation: 0.66 },
|
|
99
148
|
// === Qwen ===
|
|
100
149
|
"qwen-turbo": { input: 0.05, output: 0.20, cached: 0.01, reasoning: 0.20, cache_creation: 0.05 },
|
|
101
150
|
"qwen-2.5-coder-32b": { input: 0.07, output: 0.20, cached: 0.01, reasoning: 0.20, cache_creation: 0.07 },
|
|
@@ -107,21 +156,16 @@ export const MODEL_PRICING = {
|
|
|
107
156
|
"qwen3.8-max": { input: 2.00, output: 6.00, cached: 0.40, reasoning: 6.00, cache_creation: 2.00 },
|
|
108
157
|
// === Xiaomi MiMo ===
|
|
109
158
|
"mimo-v2.6-pro": { input: 0.435, output: 0.87, cached: 0.0036, reasoning: 0.87, cache_creation: 0.435 },
|
|
110
|
-
"xiaomi/mimo-v2.6-pro": { input: 0.435, output: 0.87, cached: 0.0036, reasoning: 0.87, cache_creation: 0.435 },
|
|
111
159
|
"mimo-v2.6-flash": { input: 0.14, output: 0.28, cached: 0.0028, reasoning: 0.28, cache_creation: 0.14 },
|
|
112
|
-
"xiaomi/mimo-v2.6-flash": { input: 0.14, output: 0.28, cached: 0.0028, reasoning: 0.28, cache_creation: 0.14 },
|
|
113
160
|
"mimo-v2.5": { input: 0.14, output: 0.28, cached: 0.0028, reasoning: 0.28, cache_creation: 0.14 },
|
|
114
161
|
"mimo-v2": { input: 0.14, output: 0.28, cached: 0.0028, reasoning: 0.28, cache_creation: 0.14 },
|
|
115
162
|
// === Kimi (Moonshot AI / Kimi for Coding) ===
|
|
116
163
|
"k3.1-pro": { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.00 },
|
|
117
164
|
"kimi-k3.1-pro": { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.00 },
|
|
118
|
-
"kimi/kimi-k3.1-pro": { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.00 },
|
|
119
165
|
"k3.1-pro-highspeed": { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 },
|
|
120
166
|
"kimi-k3.1-pro-highspeed": { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 },
|
|
121
|
-
"kimi/kimi-k3.1-pro-highspeed": { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 },
|
|
122
167
|
"k3": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
123
168
|
"kimi-k3": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
124
|
-
"kimi/kimi-k3": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
125
169
|
"kimi-for-coding": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
126
170
|
"kimi-for-coding-highspeed": { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 },
|
|
127
171
|
"kimi-k2.7-code": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
@@ -129,9 +173,7 @@ export const MODEL_PRICING = {
|
|
|
129
173
|
"kimi-k2.5": { input: 3.00, output: 15.00, cached: 0.30, reasoning: 15.00, cache_creation: 3.00 },
|
|
130
174
|
// === MiniMax ===
|
|
131
175
|
"minimax-m3": { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 },
|
|
132
|
-
"minimax/minimax-m3": { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 },
|
|
133
176
|
"minimax-m3.1-flash": { input: 0.15, output: 0.60, cached: 0.03, reasoning: 0.60, cache_creation: 0.15 },
|
|
134
|
-
"minimax/minimax-m3.1-flash": { input: 0.15, output: 0.60, cached: 0.03, reasoning: 0.60, cache_creation: 0.15 },
|
|
135
177
|
"minimax-m2.7": { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 },
|
|
136
178
|
"minimax-m2.5": { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 },
|
|
137
179
|
"minimax-m2.1": { input: 0.20, output: 1.10, cached: 0.04, reasoning: 1.10, cache_creation: 0.20 },
|
|
@@ -141,8 +183,10 @@ export const PATTERN_PRICING = [
|
|
|
141
183
|
{ pattern: /minimax.*flash/i, pricing: { input: 0.15, output: 0.60, cached: 0.03, reasoning: 0.60, cache_creation: 0.15 } },
|
|
142
184
|
{ pattern: /minimax.*(m3|m2\.7|m2\.5)/i, pricing: { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 } },
|
|
143
185
|
{ pattern: /minimax/i, pricing: { input: 0.30, output: 1.20, cached: 0.06, reasoning: 1.20, cache_creation: 0.30 } },
|
|
144
|
-
{ pattern: /gemini-4-argon/i, pricing: { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 } },
|
|
145
|
-
{ pattern: /argon/i, pricing: { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 } },
|
|
186
|
+
{ pattern: /gemini-4-(argon|carbon)/i, pricing: { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 } },
|
|
187
|
+
{ pattern: /(argon|carbon)/i, pricing: { input: 2.00, output: 10.00, cached: 0.10, reasoning: 10.00, cache_creation: 2.00 } },
|
|
188
|
+
{ pattern: /gemini-4-hydrogen/i, pricing: { input: 1.50, output: 7.50, cached: 0.075, reasoning: 7.50, cache_creation: 1.50 } },
|
|
189
|
+
{ pattern: /hydrogen/i, pricing: { input: 1.50, output: 7.50, cached: 0.075, reasoning: 7.50, cache_creation: 1.50 } },
|
|
146
190
|
{ pattern: /k3\.1.*highspeed/i, pricing: { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 } },
|
|
147
191
|
{ pattern: /kimi.*highspeed/i, pricing: { input: 4.00, output: 20.00, cached: 0.20, reasoning: 20.00, cache_creation: 4.00 } },
|
|
148
192
|
{ pattern: /k3\.1/i, pricing: { input: 2.00, output: 10.00, cached: 0.20, reasoning: 10.00, cache_creation: 2.00 } },
|
|
@@ -193,14 +237,23 @@ export function getPricingForModel(provider, model) {
|
|
|
193
237
|
return null;
|
|
194
238
|
if (isFreeModel(model))
|
|
195
239
|
return ZERO_PRICING;
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
240
|
+
const candidates = extractModelPricingCandidates(model);
|
|
241
|
+
// 1. Direct match in MODEL_PRICING
|
|
242
|
+
for (const cand of candidates) {
|
|
243
|
+
if (MODEL_PRICING[cand])
|
|
244
|
+
return MODEL_PRICING[cand];
|
|
245
|
+
}
|
|
246
|
+
// Also check original raw model
|
|
199
247
|
if (MODEL_PRICING[model])
|
|
200
248
|
return MODEL_PRICING[model];
|
|
249
|
+
// 2. Pattern matching across original model and stripped candidates
|
|
201
250
|
for (const { pattern, pricing } of PATTERN_PRICING) {
|
|
202
|
-
if (pattern.test(
|
|
251
|
+
if (pattern.test(model))
|
|
203
252
|
return pricing;
|
|
253
|
+
for (const cand of candidates) {
|
|
254
|
+
if (pattern.test(cand)) {
|
|
255
|
+
return pricing;
|
|
256
|
+
}
|
|
204
257
|
}
|
|
205
258
|
}
|
|
206
259
|
// Default fallback for unknown model: reasonable standard rate
|
|
@@ -227,9 +280,12 @@ export function calculateCostFromTokens(tokens, model, provider) {
|
|
|
227
280
|
if (cacheCreationTokens > 0) {
|
|
228
281
|
cost += cacheCreationTokens * ((pricing.cache_creation ?? pricing.input) / 1_000_000);
|
|
229
282
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
283
|
+
const nonReasoningOutput = pricing.reasoning
|
|
284
|
+
? Math.max(0, outputTokens - reasoningTokens)
|
|
285
|
+
: outputTokens;
|
|
286
|
+
cost += nonReasoningOutput * (pricing.output / 1_000_000);
|
|
287
|
+
if (reasoningTokens > 0 && pricing.reasoning) {
|
|
288
|
+
cost += reasoningTokens * (pricing.reasoning / 1_000_000);
|
|
233
289
|
}
|
|
234
290
|
return Number(cost.toFixed(6));
|
|
235
291
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts normalized token counts from OpenAI Chat, OpenAI Responses,
|
|
3
|
+
* Anthropic Messages, DeepSeek/Qwen, Ollama, or Gemini usage payloads
|
|
4
|
+
* without double-counting cached tokens.
|
|
5
|
+
*/
|
|
6
|
+
export function extractUsageTokens(payload, fallbackPromptTokens = 0) {
|
|
7
|
+
const usage = payload?.usage || {};
|
|
8
|
+
const geminiMeta = payload?.usageMetadata;
|
|
9
|
+
if (!payload?.usage && geminiMeta) {
|
|
10
|
+
const promptTokens = Number(geminiMeta.promptTokenCount ?? fallbackPromptTokens ?? 0) || 0;
|
|
11
|
+
const completionTokens = Number(geminiMeta.candidatesTokenCount ?? 0) || 0;
|
|
12
|
+
const cachedTokens = Number(geminiMeta.cachedContentTokenCount ?? 0) || 0;
|
|
13
|
+
const reasoningTokens = Number(geminiMeta.thoughtsTokenCount ?? 0) || 0;
|
|
14
|
+
return {
|
|
15
|
+
promptTokens,
|
|
16
|
+
completionTokens,
|
|
17
|
+
cachedTokens,
|
|
18
|
+
cacheCreationTokens: 0,
|
|
19
|
+
reasoningTokens,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
let promptTokens = Number(usage.prompt_tokens ??
|
|
23
|
+
usage.input_tokens ??
|
|
24
|
+
usage.prompt_eval_count ??
|
|
25
|
+
fallbackPromptTokens ??
|
|
26
|
+
0) || 0;
|
|
27
|
+
const completionTokens = Number(usage.completion_tokens ??
|
|
28
|
+
usage.output_tokens ??
|
|
29
|
+
usage.eval_count ??
|
|
30
|
+
0) || 0;
|
|
31
|
+
const cachedTokens = Number(usage.prompt_tokens_details?.cached_tokens ??
|
|
32
|
+
usage.input_tokens_details?.cached_tokens ??
|
|
33
|
+
usage.cache_read_input_tokens ??
|
|
34
|
+
usage.prompt_cache_hit_tokens ??
|
|
35
|
+
usage.cached_tokens ??
|
|
36
|
+
0) || 0;
|
|
37
|
+
const cacheCreationTokens = Number(usage.cache_creation_input_tokens ?? 0) || 0;
|
|
38
|
+
const reasoningTokens = Number(usage.completion_tokens_details?.reasoning_tokens ??
|
|
39
|
+
usage.output_tokens_details?.reasoning_tokens ??
|
|
40
|
+
0) || 0;
|
|
41
|
+
// In Anthropic Messages API, `input_tokens` excludes `cache_read_input_tokens` and
|
|
42
|
+
// `cache_creation_input_tokens`. In OpenAI Responses API (`input_tokens_details`),
|
|
43
|
+
// `input_tokens` ALREADY includes `cached_tokens` — never add cachedTokens twice.
|
|
44
|
+
const isAnthropicInputShape = usage.input_tokens !== undefined &&
|
|
45
|
+
usage.prompt_tokens === undefined &&
|
|
46
|
+
usage.input_tokens_details === undefined &&
|
|
47
|
+
(usage.cache_read_input_tokens !== undefined ||
|
|
48
|
+
usage.cache_creation_input_tokens !== undefined);
|
|
49
|
+
if (isAnthropicInputShape) {
|
|
50
|
+
promptTokens = (Number(usage.input_tokens) || 0) + cachedTokens + cacheCreationTokens;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
promptTokens,
|
|
54
|
+
completionTokens,
|
|
55
|
+
cachedTokens,
|
|
56
|
+
cacheCreationTokens,
|
|
57
|
+
reasoningTokens,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -68,6 +68,14 @@ export const toolConfig = {
|
|
|
68
68
|
"gemini-4-argon-high": "gemini-4-argon-high",
|
|
69
69
|
"gemini-4-argon-medium": "gemini-4-argon-medium",
|
|
70
70
|
"gemini-4-argon-low": "gemini-4-argon-low",
|
|
71
|
+
"gemini-4-carbon": "gemini-4-carbon-medium",
|
|
72
|
+
"gemini-4-carbon-high": "gemini-4-carbon-high",
|
|
73
|
+
"gemini-4-carbon-medium": "gemini-4-carbon-medium",
|
|
74
|
+
"gemini-4-carbon-low": "gemini-4-carbon-low",
|
|
75
|
+
"gemini-4-hydrogen": "gemini-4-hydrogen-medium",
|
|
76
|
+
"gemini-4-hydrogen-high": "gemini-4-hydrogen-high",
|
|
77
|
+
"gemini-4-hydrogen-medium": "gemini-4-hydrogen-medium",
|
|
78
|
+
"gemini-4-hydrogen-low": "gemini-4-hydrogen-low",
|
|
71
79
|
},
|
|
72
80
|
modelPatterns: [
|
|
73
81
|
{ match: /flash.*extra.*low|extra.*low.*flash|flash.*low|low.*flash/i, alias: "gemini-3.8-flash-low" },
|
|
@@ -86,6 +94,12 @@ export const toolConfig = {
|
|
|
86
94
|
{ match: /opus/i, alias: "claude-opus-4-6-thinking" },
|
|
87
95
|
{ match: /sonnet|claude/i, alias: "claude-sonnet-4-6" },
|
|
88
96
|
{ match: /gpt.*oss|oss/i, alias: "gpt-oss-120b-medium" },
|
|
97
|
+
{ match: /carbon.*high/i, alias: "gemini-4-carbon-high" },
|
|
98
|
+
{ match: /carbon.*low/i, alias: "gemini-4-carbon-low" },
|
|
99
|
+
{ match: /carbon/i, alias: "gemini-4-carbon-medium" },
|
|
100
|
+
{ match: /hydrogen.*high/i, alias: "gemini-4-hydrogen-high" },
|
|
101
|
+
{ match: /hydrogen.*low/i, alias: "gemini-4-hydrogen-low" },
|
|
102
|
+
{ match: /hydrogen/i, alias: "gemini-4-hydrogen-medium" },
|
|
89
103
|
{ match: /argon.*high|gemini.*4.*high/i, alias: "gemini-4-argon-high" },
|
|
90
104
|
{ match: /argon.*low|gemini.*4.*low/i, alias: "gemini-4-argon-low" },
|
|
91
105
|
{ match: /argon|gemini.*4/i, alias: "gemini-4-argon-medium" },
|
|
@@ -96,6 +110,14 @@ export const toolConfig = {
|
|
|
96
110
|
"gemini-4-argon-high",
|
|
97
111
|
"gemini-4-argon-medium",
|
|
98
112
|
"gemini-4-argon-low",
|
|
113
|
+
"gemini-4-carbon",
|
|
114
|
+
"gemini-4-carbon-high",
|
|
115
|
+
"gemini-4-carbon-medium",
|
|
116
|
+
"gemini-4-carbon-low",
|
|
117
|
+
"gemini-4-hydrogen",
|
|
118
|
+
"gemini-4-hydrogen-high",
|
|
119
|
+
"gemini-4-hydrogen-medium",
|
|
120
|
+
"gemini-4-hydrogen-low",
|
|
99
121
|
"gemini-3.8-flash-high",
|
|
100
122
|
"gemini-3.8-flash-medium",
|
|
101
123
|
"gemini-3.8-flash-low",
|
|
@@ -88,8 +88,8 @@ export function augmentAntigravityModelsPayload(payload, additionalCandidates) {
|
|
|
88
88
|
primarySort.groups = [];
|
|
89
89
|
}
|
|
90
90
|
// Group helpers
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const geminiGroup = primarySort.groups.find((g) => /gemini/i.test(g.displayName || g.display_name || ""));
|
|
92
|
+
const claudeGroup = primarySort.groups.find((g) => /claude/i.test(g.displayName || g.display_name || ""));
|
|
93
93
|
let mapigateGroup = primarySort.groups.find((g) => /mapigate|custom/i.test(g.displayName || g.display_name || ""));
|
|
94
94
|
if (!mapigateGroup) {
|
|
95
95
|
mapigateGroup = { displayName: "Mapigate Models", modelIds: [] };
|