@blockrun/clawrouter 0.12.308 → 0.12.309
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 +2 -2
- package/dist/cli.js +101 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.js +101 -10
- package/docs/configuration.md +5 -3
- package/docs/routing-profiles.md +1 -1
- package/package.json +1 -1
- package/skills/clawrouter/SKILL.md +6 -6
package/README.md
CHANGED
|
@@ -376,7 +376,7 @@ Live per-model prices: [blockrun.ai/pricing](https://blockrun.ai/pricing) (agent
|
|
|
376
376
|
| `xai/grok-imagine-video` | xAI Grok Imagine | 8s default, up to 15s |
|
|
377
377
|
| `xai/grok-imagine-video-1.5` | xAI Grok Imagine | 8s default, up to 15s |
|
|
378
378
|
|
|
379
|
-
Seedance is **token-priced upstream** at ~20,256 tokens/sec — the blockrun videos route now defaults Seedance to `resolution=720p` with `generate_audio=true` for text-to-video (2× the per-second token count of the older 480p baseline; audio is included in that rate). The quote is `duration × tokens/sec × $/1M tokens × 1.05 margin`. Image-to-video is priced the same as text-to-video (the earlier ~40% i2v discount was removed upstream on 2026-06-01; only video-to-video remains cheaper).
|
|
379
|
+
Seedance is **token-priced upstream** at ~20,256 tokens/sec — the blockrun videos route now defaults Seedance to `resolution=720p` with `generate_audio=true` for text-to-video (2× the per-second token count of the older 480p baseline; audio is included in that rate). The quote is `duration × tokens/sec × $/1M tokens × 1.05 margin`. Image-to-video is priced the same as text-to-video (the earlier ~40% i2v discount was removed upstream on 2026-06-01; only video-to-video remains cheaper). For real people in reference images, use Seedance + RealFace. Calls block for 30–120s while the upstream polls the job. Seedance 2.0 Fast typically returns in 60–80s; 2.0 Pro trades latency for quality.
|
|
380
380
|
|
|
381
381
|
### BytePlus RealFace (Seedance 2.0 only)
|
|
382
382
|
|
|
@@ -965,7 +965,7 @@ wallet, no key, no signup. See [Paying with a credit card](#paying-with-a-credit
|
|
|
965
965
|
|
|
966
966
|
### Is ClawRouter free?
|
|
967
967
|
|
|
968
|
-
ClawRouter itself is free and MIT licensed. You pay only for the LLM API calls routed through it — and several open-weight models (`nemotron-3.5-lightning`, `laguna-xs-2.1`, `north-mini-code`, `nemotron-3-nano-omni-30b-a3b-reasoning`, `nemotron-3-
|
|
968
|
+
ClawRouter itself is free and MIT licensed. You pay only for the LLM API calls routed through it — and several open-weight models (`nemotron-3.5-lightning`, `laguna-xs-2.1`, `north-mini-code`, `nemotron-3.5-bolt`, `nemotron-3-nano-omni-30b-a3b-reasoning`, `nemotron-3-super-120b`, `nemotron-3-ultra-550b`, `muse-glimmer-30b`) are completely free, and Bolt also reads images. Use `/model free` for the free default, or pick any by name.
|
|
969
969
|
|
|
970
970
|
---
|
|
971
971
|
|
package/dist/cli.js
CHANGED
|
@@ -89473,9 +89473,12 @@ var init_session_spend = __esm({
|
|
|
89473
89473
|
}
|
|
89474
89474
|
};
|
|
89475
89475
|
CostCapError = class extends SpendPolicyError {
|
|
89476
|
-
|
|
89476
|
+
/** A graceful-mode refusal: the budget ran out, and nothing cheaper may be swapped in. */
|
|
89477
|
+
budgetExhausted;
|
|
89478
|
+
constructor(reason, budgetExhausted = false) {
|
|
89477
89479
|
super(reason);
|
|
89478
89480
|
this.name = "CostCapError";
|
|
89481
|
+
this.budgetExhausted = budgetExhausted;
|
|
89479
89482
|
}
|
|
89480
89483
|
};
|
|
89481
89484
|
ZERO_CAP_REFUSAL = "ClawRouter cost cap: maxCostPerRun is 0, so no paid call is made";
|
|
@@ -155639,15 +155642,88 @@ function refuseOverCostCap(res, err) {
|
|
|
155639
155642
|
if (!(err instanceof CostCapError) || res.headersSent) return false;
|
|
155640
155643
|
res.writeHead(429, {
|
|
155641
155644
|
"Content-Type": "application/json",
|
|
155642
|
-
"X-ClawRouter-Cost-Cap-Exceeded": "1"
|
|
155645
|
+
"X-ClawRouter-Cost-Cap-Exceeded": "1",
|
|
155646
|
+
...err.budgetExhausted ? { "X-ClawRouter-Budget-Mode": "blocked" } : {}
|
|
155643
155647
|
});
|
|
155644
155648
|
res.end(
|
|
155645
155649
|
JSON.stringify({
|
|
155646
|
-
error: {
|
|
155650
|
+
error: {
|
|
155651
|
+
message: err.message,
|
|
155652
|
+
type: "cost_cap_exceeded",
|
|
155653
|
+
code: err.budgetExhausted ? "budget_exhausted" : "cost_cap_exceeded"
|
|
155654
|
+
}
|
|
155647
155655
|
})
|
|
155648
155656
|
);
|
|
155649
155657
|
return true;
|
|
155650
155658
|
}
|
|
155659
|
+
function capMessagesRequest(body, headers, cap) {
|
|
155660
|
+
let parsed = {};
|
|
155661
|
+
try {
|
|
155662
|
+
const value = JSON.parse(body.toString());
|
|
155663
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
155664
|
+
parsed = value;
|
|
155665
|
+
}
|
|
155666
|
+
} catch {
|
|
155667
|
+
}
|
|
155668
|
+
const messages = Array.isArray(parsed.messages) ? parsed.messages.filter(
|
|
155669
|
+
(m) => typeof m?.role === "string" && m.content !== void 0
|
|
155670
|
+
) : [];
|
|
155671
|
+
const sessionId = getSessionId(headers) ?? deriveSessionId(messages) ?? NO_SESSION_ID;
|
|
155672
|
+
const store = paymentStore.getStore();
|
|
155673
|
+
const track = () => {
|
|
155674
|
+
const spend2 = SessionSpend.track(cap.sessions, sessionId);
|
|
155675
|
+
if (store) store.sessionSpend = spend2;
|
|
155676
|
+
return spend2;
|
|
155677
|
+
};
|
|
155678
|
+
const model = typeof parsed.model === "string" ? parsed.model : void 0;
|
|
155679
|
+
if (model !== void 0 && cap.isFree(model)) {
|
|
155680
|
+
track();
|
|
155681
|
+
return { recordSuccess: () => {
|
|
155682
|
+
} };
|
|
155683
|
+
}
|
|
155684
|
+
const estimate = parseMicros(
|
|
155685
|
+
model === void 0 ? void 0 : estimateAmount(
|
|
155686
|
+
resolveModelAlias(model),
|
|
155687
|
+
body.length,
|
|
155688
|
+
resolveMaxTokens(parsed),
|
|
155689
|
+
new Map(cap.models.map((m) => [m.id, m]))
|
|
155690
|
+
)
|
|
155691
|
+
);
|
|
155692
|
+
let spend;
|
|
155693
|
+
if (cap.mode === "strict") {
|
|
155694
|
+
const admission = SessionSpend.admit(
|
|
155695
|
+
cap.sessions,
|
|
155696
|
+
sessionId,
|
|
155697
|
+
usdToMicros(cap.usd),
|
|
155698
|
+
// As on the chat path: the key rail has no signing check behind this one, so
|
|
155699
|
+
// one micro refuses a model it can't price once the session has nothing left.
|
|
155700
|
+
estimate ?? (cap.authMode === "api-key" ? 1n : 0n)
|
|
155701
|
+
);
|
|
155702
|
+
if (!admission.admitted) {
|
|
155703
|
+
const projected = admission.spentMicros + admission.heldMicros + admission.estimateMicros;
|
|
155704
|
+
throw new CostCapError(
|
|
155705
|
+
`ClawRouter cost cap exceeded: projected spend $${microsToUsd(projected).toFixed(4)} would exceed limit $${cap.usd}`
|
|
155706
|
+
);
|
|
155707
|
+
}
|
|
155708
|
+
spend = admission.spend;
|
|
155709
|
+
if (store) store.sessionSpend = spend;
|
|
155710
|
+
} else {
|
|
155711
|
+
const remainingUsd = cap.usd - cap.sessions.getSessionCostUsd(sessionId);
|
|
155712
|
+
const canAfford = estimate !== void 0 ? microsToUsd(estimate) <= remainingUsd : remainingUsd > 0;
|
|
155713
|
+
if (!canAfford) {
|
|
155714
|
+
throw new CostCapError(
|
|
155715
|
+
`ClawRouter budget exhausted: $${Math.max(0, remainingUsd).toFixed(4)} remaining (limit: $${cap.usd}). Increase maxCostPerRun to continue.`,
|
|
155716
|
+
true
|
|
155717
|
+
);
|
|
155718
|
+
}
|
|
155719
|
+
spend = track();
|
|
155720
|
+
}
|
|
155721
|
+
return {
|
|
155722
|
+
recordSuccess: () => {
|
|
155723
|
+
if (estimate !== void 0) spend.recordSuccess(estimate);
|
|
155724
|
+
}
|
|
155725
|
+
};
|
|
155726
|
+
}
|
|
155651
155727
|
function withZeroCapGuard(inner, isFree) {
|
|
155652
155728
|
return async (input2, init2) => {
|
|
155653
155729
|
const { pathname } = new URL(input2 instanceof Request ? input2.url : String(input2));
|
|
@@ -155671,7 +155747,7 @@ function withZeroCapGuard(inner, isFree) {
|
|
|
155671
155747
|
return inner(input2, init2);
|
|
155672
155748
|
};
|
|
155673
155749
|
}
|
|
155674
|
-
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet") {
|
|
155750
|
+
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet", capRequest) {
|
|
155675
155751
|
const startTime = Date.now();
|
|
155676
155752
|
const upstreamUrl = `${apiBase}${req.url}`;
|
|
155677
155753
|
const isBlockrunExa = req.url?.startsWith("/v1/exa/") ?? false;
|
|
@@ -155683,6 +155759,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155683
155759
|
bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
155684
155760
|
}
|
|
155685
155761
|
const body = Buffer.concat(bodyChunks);
|
|
155762
|
+
const capped = capRequest?.(body);
|
|
155686
155763
|
const headers = {};
|
|
155687
155764
|
for (const [key3, value] of Object.entries(req.headers)) {
|
|
155688
155765
|
if (key3 === "host" || key3 === "connection" || key3 === "transfer-encoding" || key3 === "content-length")
|
|
@@ -155704,6 +155781,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155704
155781
|
body: body.length > 0 ? new Uint8Array(body) : void 0,
|
|
155705
155782
|
signal: clientAbort.signal
|
|
155706
155783
|
});
|
|
155784
|
+
if (upstream.ok) capped?.recordSuccess();
|
|
155707
155785
|
const responseHeaders = {};
|
|
155708
155786
|
upstream.headers.forEach((value, key3) => {
|
|
155709
155787
|
if (key3 === "transfer-encoding" || key3 === "connection" || key3 === "content-encoding" || key3 === "content-length")
|
|
@@ -156064,11 +156142,12 @@ async function startProxy(options) {
|
|
|
156064
156142
|
}
|
|
156065
156143
|
const requestOptions = solanaBatch ? { ...options, _solanaBatchActive: true } : options;
|
|
156066
156144
|
const keyFetch = apiKey ? createApiKeyFetch(apiKey, fetch, apiBase) : void 0;
|
|
156145
|
+
const isFreeForCap = (model) => {
|
|
156146
|
+
const { freeIds } = catalog.current();
|
|
156147
|
+
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
156148
|
+
};
|
|
156067
156149
|
const payFetch = authMode === "api-key" ? withSpendPolicy(
|
|
156068
|
-
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch,
|
|
156069
|
-
const { freeIds } = catalog.current();
|
|
156070
|
-
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
156071
|
-
}) : keyFetch,
|
|
156150
|
+
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
|
|
156072
156151
|
options.spendControl ?? getSharedSpendControl(),
|
|
156073
156152
|
() => {
|
|
156074
156153
|
const store = paymentStore.getStore();
|
|
@@ -157049,7 +157128,8 @@ async function startProxy(options) {
|
|
|
157049
157128
|
}
|
|
157050
157129
|
return;
|
|
157051
157130
|
}
|
|
157052
|
-
const
|
|
157131
|
+
const isMessagesPath = req.url === "/v1/messages" || (req.url?.startsWith("/v1/messages?") ?? false);
|
|
157132
|
+
const isVerbatimGatewayPath = isMessagesPath || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
|
|
157053
157133
|
if (isVerbatimGatewayPath || req.url?.match(PAID_API_PATH)) {
|
|
157054
157134
|
try {
|
|
157055
157135
|
await proxyPaidApiRequest(
|
|
@@ -157059,7 +157139,16 @@ async function startProxy(options) {
|
|
|
157059
157139
|
payFetch,
|
|
157060
157140
|
() => paymentStore.getStore()?.amountUsd ?? 0,
|
|
157061
157141
|
false,
|
|
157062
|
-
authMode
|
|
157142
|
+
authMode,
|
|
157143
|
+
// $0 is enforced below this, where calls are signed or fetched.
|
|
157144
|
+
isMessagesPath && options.maxCostPerRunUsd !== void 0 && options.maxCostPerRunUsd !== 0 ? (body) => capMessagesRequest(body, req.headers, {
|
|
157145
|
+
usd: options.maxCostPerRunUsd,
|
|
157146
|
+
mode: options.maxCostPerRunMode ?? "graceful",
|
|
157147
|
+
authMode,
|
|
157148
|
+
sessions: sessionStore,
|
|
157149
|
+
models: catalog.current().models,
|
|
157150
|
+
isFree: isFreeForCap
|
|
157151
|
+
}) : void 0
|
|
157063
157152
|
);
|
|
157064
157153
|
} catch (err) {
|
|
157065
157154
|
if (refuseOverCostCap(res, err)) return;
|
|
@@ -157075,6 +157164,8 @@ async function startProxy(options) {
|
|
|
157075
157164
|
} else if (!res.writableEnded) {
|
|
157076
157165
|
res.end();
|
|
157077
157166
|
}
|
|
157167
|
+
} finally {
|
|
157168
|
+
paymentStore.getStore()?.sessionSpend?.release();
|
|
157078
157169
|
}
|
|
157079
157170
|
return;
|
|
157080
157171
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1354,7 +1354,8 @@ type ProxyOptions = {
|
|
|
1354
1354
|
/**
|
|
1355
1355
|
* Maximum total spend (in USD) per session run.
|
|
1356
1356
|
* Default: undefined (no limit). Example: 0.5 = $0.50 per session. A positive cap
|
|
1357
|
-
* covers chat
|
|
1357
|
+
* covers /v1/chat/completions and /v1/messages; 0 refuses every paid call on every
|
|
1358
|
+
* endpoint.
|
|
1358
1359
|
*/
|
|
1359
1360
|
maxCostPerRunUsd?: number;
|
|
1360
1361
|
/**
|
package/dist/index.js
CHANGED
|
@@ -287452,9 +287452,12 @@ var SessionSpend = class _SessionSpend {
|
|
|
287452
287452
|
}
|
|
287453
287453
|
};
|
|
287454
287454
|
var CostCapError = class extends SpendPolicyError {
|
|
287455
|
-
|
|
287455
|
+
/** A graceful-mode refusal: the budget ran out, and nothing cheaper may be swapped in. */
|
|
287456
|
+
budgetExhausted;
|
|
287457
|
+
constructor(reason, budgetExhausted = false) {
|
|
287456
287458
|
super(reason);
|
|
287457
287459
|
this.name = "CostCapError";
|
|
287460
|
+
this.budgetExhausted = budgetExhausted;
|
|
287458
287461
|
}
|
|
287459
287462
|
};
|
|
287460
287463
|
var ZERO_CAP_REFUSAL = "ClawRouter cost cap: maxCostPerRun is 0, so no paid call is made";
|
|
@@ -290982,15 +290985,88 @@ function refuseOverCostCap(res, err) {
|
|
|
290982
290985
|
if (!(err instanceof CostCapError) || res.headersSent) return false;
|
|
290983
290986
|
res.writeHead(429, {
|
|
290984
290987
|
"Content-Type": "application/json",
|
|
290985
|
-
"X-ClawRouter-Cost-Cap-Exceeded": "1"
|
|
290988
|
+
"X-ClawRouter-Cost-Cap-Exceeded": "1",
|
|
290989
|
+
...err.budgetExhausted ? { "X-ClawRouter-Budget-Mode": "blocked" } : {}
|
|
290986
290990
|
});
|
|
290987
290991
|
res.end(
|
|
290988
290992
|
JSON.stringify({
|
|
290989
|
-
error: {
|
|
290993
|
+
error: {
|
|
290994
|
+
message: err.message,
|
|
290995
|
+
type: "cost_cap_exceeded",
|
|
290996
|
+
code: err.budgetExhausted ? "budget_exhausted" : "cost_cap_exceeded"
|
|
290997
|
+
}
|
|
290990
290998
|
})
|
|
290991
290999
|
);
|
|
290992
291000
|
return true;
|
|
290993
291001
|
}
|
|
291002
|
+
function capMessagesRequest(body, headers, cap) {
|
|
291003
|
+
let parsed = {};
|
|
291004
|
+
try {
|
|
291005
|
+
const value = JSON.parse(body.toString());
|
|
291006
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
291007
|
+
parsed = value;
|
|
291008
|
+
}
|
|
291009
|
+
} catch {
|
|
291010
|
+
}
|
|
291011
|
+
const messages = Array.isArray(parsed.messages) ? parsed.messages.filter(
|
|
291012
|
+
(m) => typeof m?.role === "string" && m.content !== void 0
|
|
291013
|
+
) : [];
|
|
291014
|
+
const sessionId = getSessionId(headers) ?? deriveSessionId(messages) ?? NO_SESSION_ID;
|
|
291015
|
+
const store = paymentStore.getStore();
|
|
291016
|
+
const track = () => {
|
|
291017
|
+
const spend2 = SessionSpend.track(cap.sessions, sessionId);
|
|
291018
|
+
if (store) store.sessionSpend = spend2;
|
|
291019
|
+
return spend2;
|
|
291020
|
+
};
|
|
291021
|
+
const model = typeof parsed.model === "string" ? parsed.model : void 0;
|
|
291022
|
+
if (model !== void 0 && cap.isFree(model)) {
|
|
291023
|
+
track();
|
|
291024
|
+
return { recordSuccess: () => {
|
|
291025
|
+
} };
|
|
291026
|
+
}
|
|
291027
|
+
const estimate = parseMicros(
|
|
291028
|
+
model === void 0 ? void 0 : estimateAmount(
|
|
291029
|
+
resolveModelAlias(model),
|
|
291030
|
+
body.length,
|
|
291031
|
+
resolveMaxTokens(parsed),
|
|
291032
|
+
new Map(cap.models.map((m) => [m.id, m]))
|
|
291033
|
+
)
|
|
291034
|
+
);
|
|
291035
|
+
let spend;
|
|
291036
|
+
if (cap.mode === "strict") {
|
|
291037
|
+
const admission = SessionSpend.admit(
|
|
291038
|
+
cap.sessions,
|
|
291039
|
+
sessionId,
|
|
291040
|
+
usdToMicros(cap.usd),
|
|
291041
|
+
// As on the chat path: the key rail has no signing check behind this one, so
|
|
291042
|
+
// one micro refuses a model it can't price once the session has nothing left.
|
|
291043
|
+
estimate ?? (cap.authMode === "api-key" ? 1n : 0n)
|
|
291044
|
+
);
|
|
291045
|
+
if (!admission.admitted) {
|
|
291046
|
+
const projected = admission.spentMicros + admission.heldMicros + admission.estimateMicros;
|
|
291047
|
+
throw new CostCapError(
|
|
291048
|
+
`ClawRouter cost cap exceeded: projected spend $${microsToUsd(projected).toFixed(4)} would exceed limit $${cap.usd}`
|
|
291049
|
+
);
|
|
291050
|
+
}
|
|
291051
|
+
spend = admission.spend;
|
|
291052
|
+
if (store) store.sessionSpend = spend;
|
|
291053
|
+
} else {
|
|
291054
|
+
const remainingUsd = cap.usd - cap.sessions.getSessionCostUsd(sessionId);
|
|
291055
|
+
const canAfford = estimate !== void 0 ? microsToUsd(estimate) <= remainingUsd : remainingUsd > 0;
|
|
291056
|
+
if (!canAfford) {
|
|
291057
|
+
throw new CostCapError(
|
|
291058
|
+
`ClawRouter budget exhausted: $${Math.max(0, remainingUsd).toFixed(4)} remaining (limit: $${cap.usd}). Increase maxCostPerRun to continue.`,
|
|
291059
|
+
true
|
|
291060
|
+
);
|
|
291061
|
+
}
|
|
291062
|
+
spend = track();
|
|
291063
|
+
}
|
|
291064
|
+
return {
|
|
291065
|
+
recordSuccess: () => {
|
|
291066
|
+
if (estimate !== void 0) spend.recordSuccess(estimate);
|
|
291067
|
+
}
|
|
291068
|
+
};
|
|
291069
|
+
}
|
|
290994
291070
|
var ZERO_CAP_FREE_READ = /^\/v1\/(?:models|usage|balance|audio\/models|audio\/voices|images\/models|video\/models|health\/[^/]+)$/;
|
|
290995
291071
|
function withZeroCapGuard(inner, isFree) {
|
|
290996
291072
|
return async (input2, init2) => {
|
|
@@ -291015,7 +291091,7 @@ function withZeroCapGuard(inner, isFree) {
|
|
|
291015
291091
|
return inner(input2, init2);
|
|
291016
291092
|
};
|
|
291017
291093
|
}
|
|
291018
|
-
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet") {
|
|
291094
|
+
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet", capRequest) {
|
|
291019
291095
|
const startTime = Date.now();
|
|
291020
291096
|
const upstreamUrl = `${apiBase}${req.url}`;
|
|
291021
291097
|
const isBlockrunExa = req.url?.startsWith("/v1/exa/") ?? false;
|
|
@@ -291027,6 +291103,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291027
291103
|
bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
291028
291104
|
}
|
|
291029
291105
|
const body = Buffer.concat(bodyChunks);
|
|
291106
|
+
const capped = capRequest?.(body);
|
|
291030
291107
|
const headers = {};
|
|
291031
291108
|
for (const [key3, value] of Object.entries(req.headers)) {
|
|
291032
291109
|
if (key3 === "host" || key3 === "connection" || key3 === "transfer-encoding" || key3 === "content-length")
|
|
@@ -291048,6 +291125,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291048
291125
|
body: body.length > 0 ? new Uint8Array(body) : void 0,
|
|
291049
291126
|
signal: clientAbort.signal
|
|
291050
291127
|
});
|
|
291128
|
+
if (upstream.ok) capped?.recordSuccess();
|
|
291051
291129
|
const responseHeaders = {};
|
|
291052
291130
|
upstream.headers.forEach((value, key3) => {
|
|
291053
291131
|
if (key3 === "transfer-encoding" || key3 === "connection" || key3 === "content-encoding" || key3 === "content-length")
|
|
@@ -291408,11 +291486,12 @@ async function startProxy(options) {
|
|
|
291408
291486
|
}
|
|
291409
291487
|
const requestOptions = solanaBatch ? { ...options, _solanaBatchActive: true } : options;
|
|
291410
291488
|
const keyFetch = apiKey ? createApiKeyFetch(apiKey, fetch, apiBase) : void 0;
|
|
291489
|
+
const isFreeForCap = (model) => {
|
|
291490
|
+
const { freeIds } = catalog.current();
|
|
291491
|
+
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
291492
|
+
};
|
|
291411
291493
|
const payFetch = authMode === "api-key" ? withSpendPolicy(
|
|
291412
|
-
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch,
|
|
291413
|
-
const { freeIds } = catalog.current();
|
|
291414
|
-
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
291415
|
-
}) : keyFetch,
|
|
291494
|
+
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
|
|
291416
291495
|
options.spendControl ?? getSharedSpendControl(),
|
|
291417
291496
|
() => {
|
|
291418
291497
|
const store = paymentStore.getStore();
|
|
@@ -292393,7 +292472,8 @@ async function startProxy(options) {
|
|
|
292393
292472
|
}
|
|
292394
292473
|
return;
|
|
292395
292474
|
}
|
|
292396
|
-
const
|
|
292475
|
+
const isMessagesPath = req.url === "/v1/messages" || (req.url?.startsWith("/v1/messages?") ?? false);
|
|
292476
|
+
const isVerbatimGatewayPath = isMessagesPath || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
|
|
292397
292477
|
if (isVerbatimGatewayPath || req.url?.match(PAID_API_PATH)) {
|
|
292398
292478
|
try {
|
|
292399
292479
|
await proxyPaidApiRequest(
|
|
@@ -292403,7 +292483,16 @@ async function startProxy(options) {
|
|
|
292403
292483
|
payFetch,
|
|
292404
292484
|
() => paymentStore.getStore()?.amountUsd ?? 0,
|
|
292405
292485
|
false,
|
|
292406
|
-
authMode
|
|
292486
|
+
authMode,
|
|
292487
|
+
// $0 is enforced below this, where calls are signed or fetched.
|
|
292488
|
+
isMessagesPath && options.maxCostPerRunUsd !== void 0 && options.maxCostPerRunUsd !== 0 ? (body) => capMessagesRequest(body, req.headers, {
|
|
292489
|
+
usd: options.maxCostPerRunUsd,
|
|
292490
|
+
mode: options.maxCostPerRunMode ?? "graceful",
|
|
292491
|
+
authMode,
|
|
292492
|
+
sessions: sessionStore,
|
|
292493
|
+
models: catalog.current().models,
|
|
292494
|
+
isFree: isFreeForCap
|
|
292495
|
+
}) : void 0
|
|
292407
292496
|
);
|
|
292408
292497
|
} catch (err) {
|
|
292409
292498
|
if (refuseOverCostCap(res, err)) return;
|
|
@@ -292419,6 +292508,8 @@ async function startProxy(options) {
|
|
|
292419
292508
|
} else if (!res.writableEnded) {
|
|
292420
292509
|
res.end();
|
|
292421
292510
|
}
|
|
292511
|
+
} finally {
|
|
292512
|
+
paymentStore.getStore()?.sessionSpend?.release();
|
|
292422
292513
|
}
|
|
292423
292514
|
return;
|
|
292424
292515
|
}
|
package/docs/configuration.md
CHANGED
|
@@ -554,9 +554,11 @@ plugins:
|
|
|
554
554
|
# fallbacks) is checked against the cap before it is signed.
|
|
555
555
|
maxCostPerRunMode: graceful # or: strict
|
|
556
556
|
|
|
557
|
-
# Note: a positive cap applies to /v1/chat/completions
|
|
558
|
-
#
|
|
559
|
-
#
|
|
557
|
+
# Note: a positive cap applies to /v1/chat/completions and /v1/messages, which share
|
|
558
|
+
# a session's budget. /v1/messages forwards the model you asked for and never
|
|
559
|
+
# downgrades, so it answers 429 in either mode when the budget can't cover a paid call.
|
|
560
|
+
# Image, video, music and speech generation and the partner and data APIs bypass the
|
|
561
|
+
# cap. Their cost is charged directly and is not tracked per-session.
|
|
560
562
|
|
|
561
563
|
routing:
|
|
562
564
|
# Strategy. Default: portfolio (Router Core V3.4 — constraint-first ranking
|
package/docs/routing-profiles.md
CHANGED
|
@@ -75,7 +75,7 @@ Set `routing.overrides.agenticMode: false` to disable the agentic tier set, or `
|
|
|
75
75
|
|
|
76
76
|
## FREE (`/model free`)
|
|
77
77
|
|
|
78
|
-
`free` is an alias, not a routed profile: it pins the free-tier default, currently **`free/nemotron-3.5-lightning`** — the same model that opens ECO SIMPLE. If that model is excluded (`/exclude add lightning`) or the budget cap forces a free fallback, the proxy walks the free cascade in this order: nemotron-3.5-lightning → laguna-xs-2.1 → north-mini-code → nemotron-3-nano-omni-30b-a3b-reasoning → nemotron-3-
|
|
78
|
+
`free` is an alias, not a routed profile: it pins the free-tier default, currently **`free/nemotron-3.5-lightning`** — the same model that opens ECO SIMPLE. If that model is excluded (`/exclude add lightning`) or the budget cap forces a free fallback, the proxy walks the free cascade in this order: nemotron-3.5-lightning → laguna-xs-2.1 → north-mini-code → nemotron-3.5-bolt → nemotron-3-nano-omni-30b-a3b-reasoning → nemotron-3-super-120b → nemotron-3-ultra-550b. All seven are $0.00 and need no USDC, and only Bolt is treated as reading images — see the vision note below.
|
|
79
79
|
|
|
80
80
|
The order is not arbitrary. The head is whatever the gateway itself redirects the previous head to, so the proxy and the gateway never name different models. After it come the two sub-second coders — adjacent on purpose, because they sit on _different_ capacity pools (our own NVIDIA key vs OpenRouter's $0 pool), so one pool's outage cannot take both. The vision model sits mid-chain, and the largest, slowest rung goes last. The tier stopped being NVIDIA-only on 2026-08-30: two of the eight come from Cohere and Poolside. The fastest rung, `nemotron-3-nano-30b`, left on 2026-09-08 when NVIDIA deprovisioned it for blockrun's account; its aliases (`nano-30b`, `nemotron-nano`) now follow the gateway's redirect to `nemotron-3-nano-omni`.
|
|
81
81
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockrun/clawrouter",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.309",
|
|
4
4
|
"description": "Smart LLM router — save 84% on inference costs. 91 models (8 free). Pay by credit card (API key) or USDC (x402 wallet).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -140,7 +140,7 @@ it against a baseline nobody wrote down. See
|
|
|
140
140
|
|
|
141
141
|
## Available Models
|
|
142
142
|
|
|
143
|
-
<!-- br:models.chatVisible -->91<!-- /br:models.chatVisible --> models including: gpt-6-astra [GPT-6 flagship, 1M ctx], gpt-6-sol, gpt-6.1-sol [refreshed Sol], gpt-6-luna [fast], gpt-5.6-terra [balanced, stable default], gpt-5.6-sol [flagship], gpt-5.6-luna [cost-efficient], gpt-5.6-sol/terra/luna-pro [pro reasoning tiers], gpt-5.5, gpt-5.5-pro [max compute], chat-latest [ChatGPT Instant], gpt-5.4, gpt-5.1, gpt-4o, o3, claude-fable-5.1, claude-fable-5, claude-opus-5.5 [newest Opus], claude-opus-5 [1M ctx], claude-opus-4.8, claude-opus-4.7, claude-opus-4.5, claude-sonnet-5.5, claude-sonnet-5, claude-sonnet-4.6, gemini-3.1-pro, gemini-3.6-flash, gemini-3.5-flash-lite, gemini-2.5-flash, deepseek-v4-pro, deepseek-chat, grok-4.7, grok-4.6, grok-4.5, grok-4.3, grok-build-0.1, glm-5.3 [Z.AI flagship, 1M ctx], glm-5.3-flash [natively multimodal, 1M ctx], glm-5.2, minimax-m3, kimi-k3 [1M ctx flagship], kimi-k2.7, qwen3.8-max [Qwen 3.8 flagship, 1M ctx], qwen3.7-max, qwen3.7-plus, qwen3.7-flash, mimo [Xiaomi MiMo-V2.5 Pro, 1M ctx], mistral-large-4 [Mistral flagship, 512K ctx, vision], hy4-preview [Tencent, 770B MoE], laguna-s-2.1 [Poolside, coding], and <!-- br:models.free -->8<!-- /br:models.free --> free open-weight models (nemotron-3.5-lightning [1M ctx, thinking mode — the free default], nemotron-3-ultra-550b [550B/55B MoE, 1M ctx — the largest free model], nemotron-3-
|
|
143
|
+
<!-- br:models.chatVisible -->91<!-- /br:models.chatVisible --> models including: gpt-6-astra [GPT-6 flagship, 1M ctx], gpt-6-sol, gpt-6.1-sol [refreshed Sol], gpt-6-luna [fast], gpt-5.6-terra [balanced, stable default], gpt-5.6-sol [flagship], gpt-5.6-luna [cost-efficient], gpt-5.6-sol/terra/luna-pro [pro reasoning tiers], gpt-5.5, gpt-5.5-pro [max compute], chat-latest [ChatGPT Instant], gpt-5.4, gpt-5.1, gpt-4o, o3, claude-fable-5.1, claude-fable-5, claude-opus-5.5 [newest Opus], claude-opus-5 [1M ctx], claude-opus-4.8, claude-opus-4.7, claude-opus-4.5, claude-sonnet-5.5, claude-sonnet-5, claude-sonnet-4.6, gemini-3.1-pro, gemini-3.6-flash, gemini-3.5-flash-lite, gemini-2.5-flash, deepseek-v4-pro, deepseek-chat, grok-4.7, grok-4.6, grok-4.5, grok-4.3, grok-build-0.1, glm-5.3 [Z.AI flagship, 1M ctx], glm-5.3-flash [natively multimodal, 1M ctx], glm-5.2, minimax-m3, kimi-k3 [1M ctx flagship], kimi-k2.7, qwen3.8-max [Qwen 3.8 flagship, 1M ctx], qwen3.7-max, qwen3.7-plus, qwen3.7-flash, mimo [Xiaomi MiMo-V2.5 Pro, 1M ctx], mistral-large-4 [Mistral flagship, 512K ctx, vision], hy4-preview [Tencent, 770B MoE], laguna-s-2.1 [Poolside, coding], and <!-- br:models.free -->8<!-- /br:models.free --> free open-weight models (nemotron-3.5-lightning [1M ctx, thinking mode — the free default], nemotron-3-ultra-550b [550B/55B MoE, 1M ctx — the largest free model], nemotron-3.5-bolt [about a second to answer, reads images], nemotron-3-super-120b [reasoning], nemotron-3-nano-omni-30b-a3b-reasoning [256K ctx], north-mini-code [Cohere, coding, sub-second], laguna-xs-2.1 [Poolside, coding, ~161 tok/s], muse-glimmer-30b [Meta Muse, reasoning]). Only Bolt is flagged for vision: pin it with `/model vision-free`. Otherwise image turns route to a paid vision model, because the other free models the catalogs advertise as vision-capable don't pass a solid-colour probe on both chains.
|
|
144
144
|
|
|
145
145
|
## Model Prices — Look Them Up Live
|
|
146
146
|
|
|
@@ -189,11 +189,11 @@ Realtime prices and historical OHLC across every asset class. The agent should c
|
|
|
189
189
|
|
|
190
190
|
### Image & Video Generation
|
|
191
191
|
|
|
192
|
-
| Tool | Purpose
|
|
193
|
-
| --------------------------- |
|
|
194
|
-
| `blockrun_image_generation` | 12 image models — GPT Image 1/2/2.5 (Flare, Sunburst), Nano Banana / 2 / Pro, Seedream 5 Pro, Grok Imagine / 2.0 / Pro, CogView-4
|
|
195
|
-
| `blockrun_image_edit` | Edit / inpaint existing image (GPT Image 1/2, 2.5 Sunburst, Nano Banana; `model` param)
|
|
196
|
-
| `blockrun_video_generation` | Grok Imagine + ByteDance Seedance (1.5-pro
|
|
192
|
+
| Tool | Purpose | Price |
|
|
193
|
+
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
194
|
+
| `blockrun_image_generation` | 12 image models — GPT Image 1/2/2.5 (Flare, Sunburst), Nano Banana / 2 / Pro, Seedream 5 Pro, Grok Imagine / 2.0 / Pro, CogView-4 | per model — see [Model Prices](#model-prices--look-them-up-live) |
|
|
195
|
+
| `blockrun_image_edit` | Edit / inpaint existing image (GPT Image 1/2, 2.5 Sunburst, Nano Banana; `model` param) | per model — see [Model Prices](#model-prices--look-them-up-live) |
|
|
196
|
+
| `blockrun_video_generation` | Grok Imagine (`xai/grok-imagine-video`, `-1.5`, up to 15s) + ByteDance Seedance (1.5-pro up to 12s; 2.0-fast / 2.0-mini / 2.0 up to 15s; 2.5 up to 30s) at 720p with synced audio (t2v default). Seedance is token-priced upstream (~20,256 tokens/sec at the 720p+audio default — 2× the prior 480p rate); `image_url` (image-to-video) costs the same as t2v since 2026-06-01. Seedance 2.0 variants accept optional `real_face_asset_id` (`ta_…`) for BytePlus RealFace character-consistency — mutually exclusive with `image_url`. | per model — see [Model Prices](#model-prices--look-them-up-live) |
|
|
197
197
|
|
|
198
198
|
### Phone & Voice (Twilio + Bland.ai)
|
|
199
199
|
|