@blockrun/clawrouter 0.12.306 → 0.12.308
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 +33 -30
- package/dist/cli.js +146 -37
- package/dist/index.d.ts +2 -1
- package/dist/index.js +144 -35
- package/docs/9-free-ai-models-zero-cost-blockrun.md +33 -16
- package/docs/anthropic-cost-savings.md +3 -3
- package/docs/anthropic-third-party-harness-changes.md +3 -3
- package/docs/clawrouter-vs-openrouter-llm-routing-comparison.md +3 -3
- package/docs/configuration.md +5 -2
- package/docs/routing-profiles.md +3 -3
- package/package.json +2 -2
- package/scripts/reinstall.sh +2 -2
- package/skills/clawrouter/SKILL.md +3 -3
- package/src/top-models.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -6840,7 +6840,8 @@ var init_top_models = __esm({
|
|
|
6840
6840
|
"free/north-mini-code",
|
|
6841
6841
|
"free/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
6842
6842
|
"free/nemotron-3-ultra-550b",
|
|
6843
|
-
"free/
|
|
6843
|
+
"free/nemotron-3.5-bolt",
|
|
6844
|
+
"free/nemotron-3-super-120b",
|
|
6844
6845
|
"free/muse-glimmer-30b"
|
|
6845
6846
|
];
|
|
6846
6847
|
}
|
|
@@ -7328,10 +7329,10 @@ var init_models = __esm({
|
|
|
7328
7329
|
"mistral-free": "free/nemotron-3.5-lightning",
|
|
7329
7330
|
"glm-free": "free/nemotron-3.5-lightning",
|
|
7330
7331
|
// seed-oss-36b (the prior target) EOL'd 2026-08-03
|
|
7331
|
-
//
|
|
7332
|
-
//
|
|
7333
|
-
|
|
7334
|
-
|
|
7332
|
+
// No free Llama is left: NVIDIA deprovisioned Llama 3.2 11B Vision on 2026-11-02.
|
|
7333
|
+
// blockrun's /free-llama page now leads with Muse, so the shorthand follows it.
|
|
7334
|
+
"llama-free": "free/muse-glimmer-30b",
|
|
7335
|
+
// no free Llama left; Muse is Meta's open line after it
|
|
7335
7336
|
// qwen3-coder-480b retired 2026-06-14 → seed-oss-36b, which then EOL'd 2026-08-03.
|
|
7336
7337
|
// Follow the gateway's own retarget rather than chaining to a second dead model.
|
|
7337
7338
|
"qwen-coder": "free/nemotron-3.5-lightning",
|
|
@@ -7370,11 +7371,8 @@ var init_models = __esm({
|
|
|
7370
7371
|
// Vision-capable free models
|
|
7371
7372
|
"nemotron-omni": "free/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
7372
7373
|
"nano-omni": "free/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
7373
|
-
// `vision-free`
|
|
7374
|
-
|
|
7375
|
-
// claims working image input on either chain (see the catalog note). Do not
|
|
7376
|
-
// advertise this alias as a way to get free vision.
|
|
7377
|
-
"vision-free": "free/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
7374
|
+
// `vision-free` names the one free model that proved it reads images.
|
|
7375
|
+
"vision-free": "free/nemotron-3.5-bolt",
|
|
7378
7376
|
// Retired shorthand aliases redirect to live successors. The catch-all target
|
|
7379
7377
|
// moved llama-4-maverick → gpt-oss-120b (2026-07-17) → step-3.7-flash
|
|
7380
7378
|
// (2026-08-29) → nemotron-3.5-lightning (2026-08-30, blockrun #448).
|
|
@@ -7382,7 +7380,8 @@ var init_models = __esm({
|
|
|
7382
7380
|
// strongest live Nemotron
|
|
7383
7381
|
"nemotron-ultra": "free/nemotron-3.5-lightning",
|
|
7384
7382
|
"nemotron-253b": "free/nemotron-3.5-lightning",
|
|
7385
|
-
"nemotron-super": "free/nemotron-3
|
|
7383
|
+
"nemotron-super": "free/nemotron-3-super-120b",
|
|
7384
|
+
// now names a real free model
|
|
7386
7385
|
"nemotron-49b": "free/nemotron-3.5-lightning",
|
|
7387
7386
|
"nemotron-120b": "free/nemotron-3.5-lightning",
|
|
7388
7387
|
devstral: "free/nemotron-3.5-lightning",
|
|
@@ -7427,6 +7426,12 @@ var init_models = __esm({
|
|
|
7427
7426
|
// free on NVIDIA. A reasoning model: a small max_tokens is spent entirely in
|
|
7428
7427
|
// reasoning and returns empty content.
|
|
7429
7428
|
"nvidia/muse-glimmer-30b": "free/muse-glimmer-30b",
|
|
7429
|
+
"nvidia/nemotron-3.5-bolt": "free/nemotron-3.5-bolt",
|
|
7430
|
+
"nemotron-3.5-bolt": "free/nemotron-3.5-bolt",
|
|
7431
|
+
bolt: "free/nemotron-3.5-bolt",
|
|
7432
|
+
"nvidia/nemotron-3-super-120b": "free/nemotron-3-super-120b",
|
|
7433
|
+
"nemotron-3-super-120b": "free/nemotron-3-super-120b",
|
|
7434
|
+
"super-120b": "free/nemotron-3-super-120b",
|
|
7430
7435
|
muse: "free/muse-glimmer-30b",
|
|
7431
7436
|
"muse-glimmer": "free/muse-glimmer-30b",
|
|
7432
7437
|
"muse-glimmer-30b": "free/muse-glimmer-30b",
|
|
@@ -9145,7 +9150,9 @@ var init_models = __esm({
|
|
|
9145
9150
|
// (Llama-3.3-based) hit NVIDIA's 410 EOL. A 12-model sweep found exactly two
|
|
9146
9151
|
// survivors and only the 11B finishes a real completion. Older than the rest
|
|
9147
9152
|
// of the tier and deliberately so: it is a real Llama that actually answers.
|
|
9148
|
-
//
|
|
9153
|
+
// Retired 2026-11-02: NVIDIA deprovisioned it and blockrun delisted it. Entry
|
|
9154
|
+
// kept so explicit pins stay routable;
|
|
9155
|
+
// off the picker, the FREE_MODELS cascade and every default.
|
|
9149
9156
|
id: "free/llama-3.2-11b-vision",
|
|
9150
9157
|
name: "[Free] Llama 3.2 11B Vision",
|
|
9151
9158
|
version: "3.2-11b-vision",
|
|
@@ -9205,6 +9212,35 @@ var init_models = __esm({
|
|
|
9205
9212
|
maxOutput: 16384,
|
|
9206
9213
|
reasoning: true
|
|
9207
9214
|
},
|
|
9215
|
+
{
|
|
9216
|
+
// Nemotron 3.5 Bolt (blockrun 2026-11-04): about a second to answer, no
|
|
9217
|
+
// thinking pass. The one free model flagged for vision. 2026-11-05, 64x64
|
|
9218
|
+
// solid-colour PNGs: 8 of 8 correct across Base and Solana, and every
|
|
9219
|
+
// response's `model` field named Bolt itself, so no rescue did the reading.
|
|
9220
|
+
id: "free/nemotron-3.5-bolt",
|
|
9221
|
+
name: "[Free] Nemotron 3.5 Bolt",
|
|
9222
|
+
version: "3.5-bolt",
|
|
9223
|
+
inputPrice: 0,
|
|
9224
|
+
outputPrice: 0,
|
|
9225
|
+
contextWindow: 131072,
|
|
9226
|
+
maxOutput: 16384,
|
|
9227
|
+
vision: true
|
|
9228
|
+
},
|
|
9229
|
+
{
|
|
9230
|
+
// Nemotron 3.5 Super, served under its older 3-super-120b id (blockrun
|
|
9231
|
+
// 2026-11-04). Reasoning, and the gateway's redirect target for the retired
|
|
9232
|
+
// Llama. NO `vision`, although blockrun tags it: on 2026-11-05 only 2 of 8
|
|
9233
|
+
// image probes were answered by this model; the rest were rescued by
|
|
9234
|
+
// nano-omni or refused with a capacity 429, which proves nothing about it.
|
|
9235
|
+
id: "free/nemotron-3-super-120b",
|
|
9236
|
+
name: "[Free] Nemotron 3 Super 120B",
|
|
9237
|
+
version: "3-super-120b",
|
|
9238
|
+
inputPrice: 0,
|
|
9239
|
+
outputPrice: 0,
|
|
9240
|
+
contextWindow: 131072,
|
|
9241
|
+
maxOutput: 16384,
|
|
9242
|
+
reasoning: true
|
|
9243
|
+
},
|
|
9208
9244
|
// ── 2026-08-30 paid catalog refresh (blockrun #449) ─────────────────────
|
|
9209
9245
|
// Three additions, each probe-verified upstream with a real completion AND a
|
|
9210
9246
|
// real image before listing. All three carry `vision: true` on that evidence
|
|
@@ -89302,7 +89338,7 @@ function usdToMicros(usd2) {
|
|
|
89302
89338
|
function microsToUsd(micros) {
|
|
89303
89339
|
return Number(micros) / 1e6;
|
|
89304
89340
|
}
|
|
89305
|
-
var SessionSpend, CostCapError;
|
|
89341
|
+
var SessionSpend, CostCapError, ZERO_CAP_REFUSAL;
|
|
89306
89342
|
var init_session_spend = __esm({
|
|
89307
89343
|
"src/session-spend.ts"() {
|
|
89308
89344
|
"use strict";
|
|
@@ -89442,6 +89478,7 @@ var init_session_spend = __esm({
|
|
|
89442
89478
|
this.name = "CostCapError";
|
|
89443
89479
|
}
|
|
89444
89480
|
};
|
|
89481
|
+
ZERO_CAP_REFUSAL = "ClawRouter cost cap: maxCostPerRun is 0, so no paid call is made";
|
|
89445
89482
|
}
|
|
89446
89483
|
});
|
|
89447
89484
|
|
|
@@ -122278,12 +122315,19 @@ function isBlockedSsrfHost(hostname3) {
|
|
|
122278
122315
|
}
|
|
122279
122316
|
const embedded = h.match(/^64:ff9b::(.+)$/) ?? h.match(/::ffff:(.+)$/);
|
|
122280
122317
|
if (embedded) {
|
|
122281
|
-
const
|
|
122318
|
+
const rawTail = embedded[1];
|
|
122319
|
+
const tail = rawTail.startsWith("0:") && (rawTail.includes(".") || rawTail.split(":").length > 2) ? rawTail.slice(2) : rawTail;
|
|
122282
122320
|
if (tail.includes(".")) return isBlockedSsrfHost(tail);
|
|
122283
122321
|
const seg = tail.split(":");
|
|
122284
122322
|
if (seg.length === 2)
|
|
122285
122323
|
return isBlockedSsrfHost(v4FromHex(parseInt(seg[0], 16), parseInt(seg[1], 16)));
|
|
122286
122324
|
}
|
|
122325
|
+
const compat = h.match(/^::(?:0:)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
|
|
122326
|
+
if (compat) return isBlockedSsrfHost(compat[1]);
|
|
122327
|
+
const compatHex = h.match(/^::([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
|
|
122328
|
+
if (compatHex) {
|
|
122329
|
+
return isBlockedSsrfHost(v4FromHex(parseInt(compatHex[1], 16), parseInt(compatHex[2], 16)));
|
|
122330
|
+
}
|
|
122287
122331
|
return false;
|
|
122288
122332
|
}
|
|
122289
122333
|
const m = h.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
@@ -155591,6 +155635,42 @@ function gatewaySettledCostUsd(response) {
|
|
|
155591
155635
|
if (!Number.isFinite(value) || value < 0) return void 0;
|
|
155592
155636
|
return value;
|
|
155593
155637
|
}
|
|
155638
|
+
function refuseOverCostCap(res, err) {
|
|
155639
|
+
if (!(err instanceof CostCapError) || res.headersSent) return false;
|
|
155640
|
+
res.writeHead(429, {
|
|
155641
|
+
"Content-Type": "application/json",
|
|
155642
|
+
"X-ClawRouter-Cost-Cap-Exceeded": "1"
|
|
155643
|
+
});
|
|
155644
|
+
res.end(
|
|
155645
|
+
JSON.stringify({
|
|
155646
|
+
error: { message: err.message, type: "cost_cap_exceeded", code: "cost_cap_exceeded" }
|
|
155647
|
+
})
|
|
155648
|
+
);
|
|
155649
|
+
return true;
|
|
155650
|
+
}
|
|
155651
|
+
function withZeroCapGuard(inner, isFree) {
|
|
155652
|
+
return async (input2, init2) => {
|
|
155653
|
+
const { pathname } = new URL(input2 instanceof Request ? input2.url : String(input2));
|
|
155654
|
+
const path8 = pathname.slice(Math.max(pathname.indexOf("/v1/"), 0));
|
|
155655
|
+
const method = (init2?.method ?? "GET").toUpperCase();
|
|
155656
|
+
let allowed;
|
|
155657
|
+
if (/^\/v1\/(?:chat\/completions|messages)$/.test(path8)) {
|
|
155658
|
+
const body = init2?.body;
|
|
155659
|
+
let model;
|
|
155660
|
+
try {
|
|
155661
|
+
const text = typeof body === "string" ? body : body instanceof Uint8Array ? Buffer.from(body).toString() : "";
|
|
155662
|
+
model = JSON.parse(text).model;
|
|
155663
|
+
} catch {
|
|
155664
|
+
model = void 0;
|
|
155665
|
+
}
|
|
155666
|
+
allowed = typeof model === "string" && isFree(model);
|
|
155667
|
+
} else {
|
|
155668
|
+
allowed = ZERO_CAP_FREE_READ.test(path8) && (method === "GET" || method === "HEAD");
|
|
155669
|
+
}
|
|
155670
|
+
if (!allowed) throw new CostCapError(ZERO_CAP_REFUSAL);
|
|
155671
|
+
return inner(input2, init2);
|
|
155672
|
+
};
|
|
155673
|
+
}
|
|
155594
155674
|
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet") {
|
|
155595
155675
|
const startTime = Date.now();
|
|
155596
155676
|
const upstreamUrl = `${apiBase}${req.url}`;
|
|
@@ -155755,6 +155835,12 @@ function assertExistingProxyBillsUs(existing, requested) {
|
|
|
155755
155835
|
}
|
|
155756
155836
|
}
|
|
155757
155837
|
async function startProxy(options) {
|
|
155838
|
+
if (options.maxCostPerRunUsd !== void 0 && !Number.isFinite(options.maxCostPerRunUsd)) {
|
|
155839
|
+
console.warn(
|
|
155840
|
+
`[ClawRouter] Ignoring maxCostPerRun: ${String(options.maxCostPerRunUsd)} is not a finite number`
|
|
155841
|
+
);
|
|
155842
|
+
options = { ...options, maxCostPerRunUsd: void 0 };
|
|
155843
|
+
}
|
|
155758
155844
|
const upstreamProxy = await applyUpstreamProxy(options.upstreamProxy);
|
|
155759
155845
|
if (upstreamProxy) {
|
|
155760
155846
|
console.log(`[ClawRouter] Upstream proxy: ${upstreamProxy}`);
|
|
@@ -155855,6 +155941,7 @@ async function startProxy(options) {
|
|
|
155855
155941
|
const account = walletKey ? privateKeyToAccount(walletKey) : void 0;
|
|
155856
155942
|
const x402 = authMode === "wallet" ? new x402Client().setSpendControls(false) : void 0;
|
|
155857
155943
|
const registerCostCapHook = (client) => client.onBeforePaymentCreation(async (context) => {
|
|
155944
|
+
if (options.maxCostPerRunUsd === 0) throw new CostCapError(ZERO_CAP_REFUSAL);
|
|
155858
155945
|
const spend = paymentStore.getStore()?.sessionSpend;
|
|
155859
155946
|
if (!spend?.isStrict) return;
|
|
155860
155947
|
const quote = parseQuotedAmountMicros(context.selectedRequirements);
|
|
@@ -155976,8 +156063,12 @@ async function startProxy(options) {
|
|
|
155976
156063
|
);
|
|
155977
156064
|
}
|
|
155978
156065
|
const requestOptions = solanaBatch ? { ...options, _solanaBatchActive: true } : options;
|
|
156066
|
+
const keyFetch = apiKey ? createApiKeyFetch(apiKey, fetch, apiBase) : void 0;
|
|
155979
156067
|
const payFetch = authMode === "api-key" ? withSpendPolicy(
|
|
155980
|
-
|
|
156068
|
+
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, (model) => {
|
|
156069
|
+
const { freeIds } = catalog.current();
|
|
156070
|
+
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
156071
|
+
}) : keyFetch,
|
|
155981
156072
|
options.spendControl ?? getSharedSpendControl(),
|
|
155982
156073
|
() => {
|
|
155983
156074
|
const store = paymentStore.getStore();
|
|
@@ -156546,6 +156637,7 @@ async function startProxy(options) {
|
|
|
156546
156637
|
res.end(JSON.stringify(result));
|
|
156547
156638
|
} catch (err) {
|
|
156548
156639
|
if (clientAbort.signal.aborted) return;
|
|
156640
|
+
if (refuseOverCostCap(res, err)) return;
|
|
156549
156641
|
const msg = err instanceof Error ? err.message : String(err);
|
|
156550
156642
|
console.error(`[ClawRouter] Image generation error: ${msg}`);
|
|
156551
156643
|
if (!res.headersSent) {
|
|
@@ -156683,6 +156775,7 @@ async function startProxy(options) {
|
|
|
156683
156775
|
res.end(JSON.stringify(result));
|
|
156684
156776
|
} catch (err) {
|
|
156685
156777
|
if (clientAbort.signal.aborted) return;
|
|
156778
|
+
if (refuseOverCostCap(res, err)) return;
|
|
156686
156779
|
const msg = err instanceof Error ? err.message : String(err);
|
|
156687
156780
|
console.error(`[ClawRouter] Image editing error: ${msg}`);
|
|
156688
156781
|
if (!res.headersSent) {
|
|
@@ -156779,6 +156872,7 @@ async function startProxy(options) {
|
|
|
156779
156872
|
res.end(JSON.stringify(result));
|
|
156780
156873
|
} catch (err) {
|
|
156781
156874
|
if (clientAbort.signal.aborted) return;
|
|
156875
|
+
if (refuseOverCostCap(res, err)) return;
|
|
156782
156876
|
const msg = err instanceof Error ? err.message : String(err);
|
|
156783
156877
|
console.error(`[ClawRouter] Audio generation error: ${msg}`);
|
|
156784
156878
|
if (!res.headersSent) {
|
|
@@ -156945,6 +157039,7 @@ async function startProxy(options) {
|
|
|
156945
157039
|
res.end(JSON.stringify(finalResult));
|
|
156946
157040
|
} catch (err) {
|
|
156947
157041
|
if (clientAbort.signal.aborted) return;
|
|
157042
|
+
if (refuseOverCostCap(res, err)) return;
|
|
156948
157043
|
const msg = err instanceof Error ? err.message : String(err);
|
|
156949
157044
|
console.error(`[ClawRouter] Video generation error: ${msg}`);
|
|
156950
157045
|
if (!res.headersSent) {
|
|
@@ -156955,9 +157050,7 @@ async function startProxy(options) {
|
|
|
156955
157050
|
return;
|
|
156956
157051
|
}
|
|
156957
157052
|
const isVerbatimGatewayPath = req.url === "/v1/messages" || (req.url?.startsWith("/v1/messages?") ?? false) || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
|
|
156958
|
-
if (isVerbatimGatewayPath || req.url?.match(
|
|
156959
|
-
/^\/v1\/(?:partner|pm|exa|modal|stocks|usstock|crypto|fx|commodity|phone|voice)\//
|
|
156960
|
-
)) {
|
|
157053
|
+
if (isVerbatimGatewayPath || req.url?.match(PAID_API_PATH)) {
|
|
156961
157054
|
try {
|
|
156962
157055
|
await proxyPaidApiRequest(
|
|
156963
157056
|
req,
|
|
@@ -156969,6 +157062,7 @@ async function startProxy(options) {
|
|
|
156969
157062
|
authMode
|
|
156970
157063
|
);
|
|
156971
157064
|
} catch (err) {
|
|
157065
|
+
if (refuseOverCostCap(res, err)) return;
|
|
156972
157066
|
const error62 = err instanceof Error ? err : new Error(String(err));
|
|
156973
157067
|
options.onError?.(error62);
|
|
156974
157068
|
if (!res.headersSent) {
|
|
@@ -157001,6 +157095,7 @@ async function startProxy(options) {
|
|
|
157001
157095
|
authMode
|
|
157002
157096
|
);
|
|
157003
157097
|
} catch (err) {
|
|
157098
|
+
if (refuseOverCostCap(res, err)) return;
|
|
157004
157099
|
const error62 = err instanceof Error ? err : new Error(String(err));
|
|
157005
157100
|
options.onError?.(error62);
|
|
157006
157101
|
if (!res.headersSent) {
|
|
@@ -157793,6 +157888,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
157793
157888
|
}
|
|
157794
157889
|
} catch (err) {
|
|
157795
157890
|
if (imagegenAbort.signal.aborted) return;
|
|
157891
|
+
if (refuseOverCostCap(res, err)) return;
|
|
157796
157892
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
157797
157893
|
console.error(`[ClawRouter] /imagegen error: ${errMsg}`);
|
|
157798
157894
|
if (!res.headersSent) {
|
|
@@ -157999,6 +158095,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
157999
158095
|
sendImg2ImgText(responseText);
|
|
158000
158096
|
} catch (err) {
|
|
158001
158097
|
if (img2imgAbort.signal.aborted) return;
|
|
158098
|
+
if (refuseOverCostCap(res, err)) return;
|
|
158002
158099
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
158003
158100
|
console.error(`[ClawRouter] /img2img error: ${errMsg}`);
|
|
158004
158101
|
if (!res.headersSent) {
|
|
@@ -158422,13 +158519,20 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
158422
158519
|
}
|
|
158423
158520
|
}
|
|
158424
158521
|
let sessionSpend;
|
|
158425
|
-
if (options.maxCostPerRunUsd
|
|
158522
|
+
if (options.maxCostPerRunUsd !== void 0 && !effectiveSessionId) {
|
|
158523
|
+
effectiveSessionId = NO_SESSION_ID;
|
|
158524
|
+
}
|
|
158525
|
+
if (options.maxCostPerRunUsd !== void 0 && effectiveSessionId && !isFreeModel && (options.maxCostPerRunMode ?? "graceful") === "strict") {
|
|
158426
158526
|
const thisReqEstStr = estimatedCostMicros !== void 0 ? estimatedCostMicros.toString() : modelId ? estimate(modelId, body.length, maxTokens) : void 0;
|
|
158427
158527
|
const admission = SessionSpend.admit(
|
|
158428
158528
|
sessionStore,
|
|
158429
158529
|
effectiveSessionId,
|
|
158430
158530
|
usdToMicros(options.maxCostPerRunUsd),
|
|
158431
|
-
|
|
158531
|
+
// No local price usually means zero here: on the wallet rail the signing
|
|
158532
|
+
// check still reads the real quote, and eco's free rungs carry no estimate.
|
|
158533
|
+
// The key rail has nothing behind this check, so count one micro, which
|
|
158534
|
+
// refuses a model it cannot price once the session has nothing left.
|
|
158535
|
+
parseMicros(thisReqEstStr) ?? (options.apiKey?.trim() && !catalog.freeIds.has(resolveModelAlias(modelId ?? "")) ? 1n : 0n)
|
|
158432
158536
|
);
|
|
158433
158537
|
if (!admission.admitted) {
|
|
158434
158538
|
const spentUsd = microsToUsd(admission.spentMicros);
|
|
@@ -158456,12 +158560,12 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
158456
158560
|
return;
|
|
158457
158561
|
}
|
|
158458
158562
|
sessionSpend = admission.spend;
|
|
158459
|
-
} else if (options.maxCostPerRunUsd && effectiveSessionId) {
|
|
158563
|
+
} else if (options.maxCostPerRunUsd !== void 0 && effectiveSessionId) {
|
|
158460
158564
|
sessionSpend = SessionSpend.track(sessionStore, effectiveSessionId);
|
|
158461
158565
|
}
|
|
158462
158566
|
const requestStore = paymentStore.getStore();
|
|
158463
158567
|
if (requestStore) requestStore.sessionSpend = sessionSpend;
|
|
158464
|
-
if (options.maxCostPerRunUsd && effectiveSessionId && !isFreeModel && (options.maxCostPerRunMode ?? "graceful") === "graceful") {
|
|
158568
|
+
if (options.maxCostPerRunUsd !== void 0 && effectiveSessionId && !isFreeModel && (options.maxCostPerRunMode ?? "graceful") === "graceful") {
|
|
158465
158569
|
const runCostUsd = sessionStore.getSessionCostUsd(effectiveSessionId);
|
|
158466
158570
|
const remainingUsd = options.maxCostPerRunUsd - runCostUsd;
|
|
158467
158571
|
const isComplexOrAgentic = hasTools || routingDecision?.tier === "COMPLEX" || routingDecision?.tier === "REASONING";
|
|
@@ -158494,7 +158598,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
158494
158598
|
}
|
|
158495
158599
|
} else if (!routingDecision && modelId && !catalog.freeIds.has(modelId)) {
|
|
158496
158600
|
const est = estimate(modelId, body.length, maxTokens);
|
|
158497
|
-
const canAfford =
|
|
158601
|
+
const canAfford = est ? Number(est) / 1e6 <= remainingUsd : remainingUsd > 0;
|
|
158498
158602
|
if (!canAfford) {
|
|
158499
158603
|
console.log(
|
|
158500
158604
|
`[ClawRouter] Budget insufficient for explicit model ${modelId} in session ${effectiveSessionId.slice(0, 8)}...: $${Math.max(0, remainingUsd).toFixed(4)} remaining \u2014 blocking (user explicitly chose ${modelId})`
|
|
@@ -158724,14 +158828,14 @@ data: [DONE]
|
|
|
158724
158828
|
modelsToTry.push(freeFallback);
|
|
158725
158829
|
}
|
|
158726
158830
|
}
|
|
158727
|
-
if (options.maxCostPerRunUsd && effectiveSessionId && !isFreeModel && (options.maxCostPerRunMode ?? "graceful") === "graceful") {
|
|
158831
|
+
if (options.maxCostPerRunUsd !== void 0 && effectiveSessionId && !isFreeModel && (options.maxCostPerRunMode ?? "graceful") === "graceful") {
|
|
158728
158832
|
const runCostUsd = sessionStore.getSessionCostUsd(effectiveSessionId);
|
|
158729
158833
|
const remainingUsd = options.maxCostPerRunUsd - runCostUsd;
|
|
158730
158834
|
const beforeFilter = [...modelsToTry];
|
|
158731
158835
|
modelsToTry = modelsToTry.filter((m) => {
|
|
158732
|
-
if (catalog.freeIds.has(m)) return true;
|
|
158836
|
+
if (catalog.freeIds.has(resolveModelAlias(m))) return true;
|
|
158733
158837
|
const est = estimate(m, body.length, maxTokens);
|
|
158734
|
-
if (!est) return
|
|
158838
|
+
if (!est) return remainingUsd > 0;
|
|
158735
158839
|
return Number(est) / 1e6 <= remainingUsd;
|
|
158736
158840
|
});
|
|
158737
158841
|
const excluded = beforeFilter.filter((m) => !modelsToTry.includes(m));
|
|
@@ -158770,14 +158874,16 @@ data: [DONE]
|
|
|
158770
158874
|
res.removeListener("close", onClientClose);
|
|
158771
158875
|
return;
|
|
158772
158876
|
}
|
|
158773
|
-
if (excluded.length > 0) {
|
|
158877
|
+
if (excluded.length > 0 && modelsToTry[0] !== beforeFilter[0]) {
|
|
158774
158878
|
const budgetSummary = remainingUsd > 0 ? `$${remainingUsd.toFixed(4)} remaining` : `budget exhausted ($${runCostUsd.toFixed(4)}/$${options.maxCostPerRunUsd})`;
|
|
158775
158879
|
console.log(
|
|
158776
158880
|
`[ClawRouter] Budget downgrade (${budgetSummary}): excluded ${excluded.join(", ")}`
|
|
158777
158881
|
);
|
|
158778
158882
|
const fromModel = excluded[0];
|
|
158779
158883
|
const usingFree = modelsToTry.length === 1 && catalog.freeIds.has(modelsToTry[0]);
|
|
158780
|
-
if (
|
|
158884
|
+
if (options.maxCostPerRunUsd === 0) {
|
|
158885
|
+
budgetDowngradeNotice = void 0;
|
|
158886
|
+
} else if (usingFree) {
|
|
158781
158887
|
budgetDowngradeNotice = `> **\u26A0\uFE0F Budget cap reached** ($${runCostUsd.toFixed(4)}/$${options.maxCostPerRunUsd}) \u2014 downgraded to free model. Quality may be reduced. Increase \`maxCostPerRun\` to continue with ${fromModel}.
|
|
158782
158888
|
|
|
158783
158889
|
`;
|
|
@@ -159688,7 +159794,7 @@ data: [DONE]
|
|
|
159688
159794
|
});
|
|
159689
159795
|
}
|
|
159690
159796
|
}
|
|
159691
|
-
var paymentStore, SOLANA_PUBLIC_RPC, BLOCKRUN_API, BLOCKRUN_SOLANA_API, BLOCKRUN_ARC_API, DESKTOP_SERVICE_TOKEN_FILE, IMAGE_DIR, AUDIO_DIR, VIDEO_DIR, AUTO_MODEL, ROUTING_PROFILES, FREE_MODELS, gatewayModelIds, FREE_MODEL, FREE_UPSTREAM_OVERRIDES, MAX_MESSAGES, CONTEXT_LIMIT_KB, HEARTBEAT_INTERVAL_MS, BALANCE_CHECK_TIMEOUT_MS, GATEWAY_CATALOG_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, PER_MODEL_TIMEOUT_MS, REASONING_MODEL_TIMEOUT_MS, MAX_FALLBACK_ATTEMPTS, HEALTH_CHECK_TIMEOUT_MS, RATE_LIMIT_COOLDOWN_MS, OVERLOAD_COOLDOWN_MS, PORT_RETRY_ATTEMPTS, PORT_RETRY_DELAY_MS, MODEL_BODY_READ_TIMEOUT_MS, ERROR_BODY_READ_TIMEOUT_MS, ClientDisconnectedError, rateLimitedModels, overloadedModels, perProviderErrors, BALANCE_CHECK_BUFFER, BALANCE_PREFLIGHT_OUTPUT_TOKEN_CAP, PROVIDER_ERROR_PATTERNS, DEGRADED_RESPONSE_PATTERNS, DEGRADED_LOOP_PATTERNS, VALID_ROLES, ROLE_MAPPINGS, VALID_TOOL_ID_PATTERN, KIMI_BLOCK_RE, KIMI_TOKEN_RE, THINKING_TAG_RE, THINKING_BLOCK_RE, BLOCKRUN_MODEL_BY_ID, IMAGE_PRICING, IMAGE_MODEL_IDS, IMAGE_MODEL_SIZES, IMAGE_MODEL_ALIASES, VIDEO_PRICING, PHONE_PRICING, LOW_CREDIT_USD, lowCreditWarned;
|
|
159797
|
+
var paymentStore, SOLANA_PUBLIC_RPC, BLOCKRUN_API, BLOCKRUN_SOLANA_API, BLOCKRUN_ARC_API, DESKTOP_SERVICE_TOKEN_FILE, IMAGE_DIR, AUDIO_DIR, VIDEO_DIR, AUTO_MODEL, ROUTING_PROFILES, FREE_MODELS, gatewayModelIds, FREE_MODEL, FREE_UPSTREAM_OVERRIDES, MAX_MESSAGES, CONTEXT_LIMIT_KB, HEARTBEAT_INTERVAL_MS, BALANCE_CHECK_TIMEOUT_MS, GATEWAY_CATALOG_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, PER_MODEL_TIMEOUT_MS, REASONING_MODEL_TIMEOUT_MS, MAX_FALLBACK_ATTEMPTS, HEALTH_CHECK_TIMEOUT_MS, RATE_LIMIT_COOLDOWN_MS, OVERLOAD_COOLDOWN_MS, PORT_RETRY_ATTEMPTS, PORT_RETRY_DELAY_MS, MODEL_BODY_READ_TIMEOUT_MS, ERROR_BODY_READ_TIMEOUT_MS, ClientDisconnectedError, rateLimitedModels, overloadedModels, perProviderErrors, BALANCE_CHECK_BUFFER, BALANCE_PREFLIGHT_OUTPUT_TOKEN_CAP, PROVIDER_ERROR_PATTERNS, DEGRADED_RESPONSE_PATTERNS, DEGRADED_LOOP_PATTERNS, VALID_ROLES, ROLE_MAPPINGS, VALID_TOOL_ID_PATTERN, KIMI_BLOCK_RE, KIMI_TOKEN_RE, THINKING_TAG_RE, THINKING_BLOCK_RE, BLOCKRUN_MODEL_BY_ID, IMAGE_PRICING, IMAGE_MODEL_IDS, IMAGE_MODEL_SIZES, IMAGE_MODEL_ALIASES, VIDEO_PRICING, PHONE_PRICING, LOW_CREDIT_USD, lowCreditWarned, NO_SESSION_ID, PAID_API_PATH, ZERO_CAP_FREE_READ;
|
|
159692
159798
|
var init_proxy = __esm({
|
|
159693
159799
|
"src/proxy.ts"() {
|
|
159694
159800
|
"use strict";
|
|
@@ -159756,12 +159862,14 @@ var init_proxy = __esm({
|
|
|
159756
159862
|
// coding, ~161 tok/s — on our NVIDIA key
|
|
159757
159863
|
"free/north-mini-code",
|
|
159758
159864
|
// coding, 607ms median — OpenRouter $0 pool
|
|
159865
|
+
"free/nemotron-3.5-bolt",
|
|
159866
|
+
// about a second, reads images
|
|
159759
159867
|
"free/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
159760
|
-
//
|
|
159761
|
-
"free/nemotron-3-
|
|
159868
|
+
// 256K ctx, reasoning
|
|
159869
|
+
"free/nemotron-3-super-120b",
|
|
159870
|
+
// reasoning; rescued often when capacity is short
|
|
159871
|
+
"free/nemotron-3-ultra-550b"
|
|
159762
159872
|
// largest free model, 1M ctx — but slow + flaky
|
|
159763
|
-
"free/llama-3.2-11b-vision"
|
|
159764
|
-
// only free Llama left; slowest, so last
|
|
159765
159873
|
]);
|
|
159766
159874
|
FREE_MODEL = "free/nemotron-3.5-lightning";
|
|
159767
159875
|
FREE_UPSTREAM_OVERRIDES = {
|
|
@@ -159966,9 +160074,7 @@ var init_proxy = __esm({
|
|
|
159966
160074
|
"bytedance/seedance-2.5": {
|
|
159967
160075
|
pricePerSecond: 0.315,
|
|
159968
160076
|
defaultDurationSeconds: 5
|
|
159969
|
-
}
|
|
159970
|
-
// Sora 2 via Azure AI Foundry — flat $0.10/s for both t2v and i2v.
|
|
159971
|
-
"azure/sora-2": { pricePerSecond: 0.1, defaultDurationSeconds: 4 }
|
|
160077
|
+
}
|
|
159972
160078
|
};
|
|
159973
160079
|
PHONE_PRICING = {
|
|
159974
160080
|
"phone/lookup/fraud": 0.05,
|
|
@@ -159981,6 +160087,9 @@ var init_proxy = __esm({
|
|
|
159981
160087
|
};
|
|
159982
160088
|
LOW_CREDIT_USD = 1;
|
|
159983
160089
|
lowCreditWarned = false;
|
|
160090
|
+
NO_SESSION_ID = "no-session";
|
|
160091
|
+
PAID_API_PATH = /^\/v1\/(?:partner|pm|exa|modal|stocks|usstock|crypto|fx|commodity|phone|voice)\//;
|
|
160092
|
+
ZERO_CAP_FREE_READ = /^\/v1\/(?:models|usage|balance|audio\/models|audio\/voices|images\/models|video\/models|health\/[^/]+)$/;
|
|
159984
160093
|
}
|
|
159985
160094
|
});
|
|
159986
160095
|
|
|
@@ -310496,7 +310605,7 @@ async function startProxyInBackground(api, startupGeneration) {
|
|
|
310496
310605
|
api.logger.info(`Using wallet from BLOCKRUN_WALLET_KEY: ${wallet.address}`);
|
|
310497
310606
|
}
|
|
310498
310607
|
const routingConfig = api.pluginConfig?.routing;
|
|
310499
|
-
const maxCostPerRunUsd = typeof api.pluginConfig?.maxCostPerRun === "number" ? api.pluginConfig.maxCostPerRun : void 0;
|
|
310608
|
+
const maxCostPerRunUsd = typeof api.pluginConfig?.maxCostPerRun === "number" && Number.isFinite(api.pluginConfig.maxCostPerRun) ? api.pluginConfig.maxCostPerRun : void 0;
|
|
310500
310609
|
const maxCostPerRunMode = api.pluginConfig?.maxCostPerRunMode === "strict" ? "strict" : "graceful";
|
|
310501
310610
|
if (maxCostPerRunUsd !== void 0) {
|
|
310502
310611
|
api.logger.info(
|
package/dist/index.d.ts
CHANGED
|
@@ -1353,7 +1353,8 @@ type ProxyOptions = {
|
|
|
1353
1353
|
cacheConfig?: ResponseCacheConfig;
|
|
1354
1354
|
/**
|
|
1355
1355
|
* Maximum total spend (in USD) per session run.
|
|
1356
|
-
* Default: undefined (no limit). Example: 0.5 = $0.50 per session.
|
|
1356
|
+
* Default: undefined (no limit). Example: 0.5 = $0.50 per session. A positive cap
|
|
1357
|
+
* covers chat completions only; 0 refuses every paid call on every endpoint.
|
|
1357
1358
|
*/
|
|
1358
1359
|
maxCostPerRunUsd?: number;
|
|
1359
1360
|
/**
|