@blockrun/clawrouter 0.12.308 → 0.12.310
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 +150 -25
- package/dist/index.d.ts +2 -1
- package/dist/index.js +150 -25
- package/docs/configuration.md +5 -3
- package/docs/features.md +3 -1
- 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
|
@@ -66170,7 +66170,7 @@ var init_response_cache = __esm({
|
|
|
66170
66170
|
*/
|
|
66171
66171
|
shouldCache(body, headers) {
|
|
66172
66172
|
if (!this.config.enabled) return false;
|
|
66173
|
-
if (headers?.["cache-control"]
|
|
66173
|
+
if (/\bno-(?:cache|store)\b/i.test(headers?.["cache-control"] ?? "")) {
|
|
66174
66174
|
return false;
|
|
66175
66175
|
}
|
|
66176
66176
|
try {
|
|
@@ -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";
|
|
@@ -125887,7 +125890,7 @@ var require_webidl = __commonJS({
|
|
|
125887
125890
|
var require_util2 = __commonJS({
|
|
125888
125891
|
"node_modules/undici/lib/web/fetch/util.js"(exports, module) {
|
|
125889
125892
|
"use strict";
|
|
125890
|
-
var { Transform } = __require("stream");
|
|
125893
|
+
var { Transform: Transform2 } = __require("stream");
|
|
125891
125894
|
var zlib2 = __require("zlib");
|
|
125892
125895
|
var { redirectStatusSet, referrerPolicyTokens, badPortsSet } = require_constants3();
|
|
125893
125896
|
var { getGlobalOrigin } = require_global();
|
|
@@ -126481,7 +126484,7 @@ var require_util2 = __commonJS({
|
|
|
126481
126484
|
contentRange += isomorphicEncode(`${fullLength}`);
|
|
126482
126485
|
return contentRange;
|
|
126483
126486
|
}
|
|
126484
|
-
var InflateStream = class extends
|
|
126487
|
+
var InflateStream = class extends Transform2 {
|
|
126485
126488
|
#zlibOptions;
|
|
126486
126489
|
/** @param {zlib.ZlibOptions} [zlibOptions] */
|
|
126487
126490
|
constructor(zlibOptions2) {
|
|
@@ -140326,13 +140329,13 @@ var require_mock_pool = __commonJS({
|
|
|
140326
140329
|
var require_pending_interceptors_formatter = __commonJS({
|
|
140327
140330
|
"node_modules/undici/lib/mock/pending-interceptors-formatter.js"(exports, module) {
|
|
140328
140331
|
"use strict";
|
|
140329
|
-
var { Transform } = __require("stream");
|
|
140332
|
+
var { Transform: Transform2 } = __require("stream");
|
|
140330
140333
|
var { Console } = __require("console");
|
|
140331
140334
|
var PERSISTENT = process.versions.icu ? "\u2705" : "Y ";
|
|
140332
140335
|
var NOT_PERSISTENT = process.versions.icu ? "\u274C" : "N ";
|
|
140333
140336
|
module.exports = class PendingInterceptorsFormatter {
|
|
140334
140337
|
constructor({ disableColors } = {}) {
|
|
140335
|
-
this.transform = new
|
|
140338
|
+
this.transform = new Transform2({
|
|
140336
140339
|
transform(chunk, _enc, cb) {
|
|
140337
140340
|
cb(null, chunk);
|
|
140338
140341
|
}
|
|
@@ -152634,7 +152637,7 @@ var require_eventsource_stream = __commonJS({
|
|
|
152634
152637
|
"node_modules/undici/lib/web/eventsource/eventsource-stream.js"(exports, module) {
|
|
152635
152638
|
"use strict";
|
|
152636
152639
|
var buffer2 = __require("buffer");
|
|
152637
|
-
var { Transform } = __require("stream");
|
|
152640
|
+
var { Transform: Transform2 } = __require("stream");
|
|
152638
152641
|
var { isASCIINumber, isValidLastEventId } = require_util6();
|
|
152639
152642
|
var BOM = [239, 187, 191];
|
|
152640
152643
|
var LF = 10;
|
|
@@ -152684,7 +152687,7 @@ var require_eventsource_stream = __commonJS({
|
|
|
152684
152687
|
error62.aborted = false;
|
|
152685
152688
|
return error62;
|
|
152686
152689
|
}
|
|
152687
|
-
var EventSourceStream = class extends
|
|
152690
|
+
var EventSourceStream = class extends Transform2 {
|
|
152688
152691
|
/**
|
|
152689
152692
|
* @type {eventSourceSettings}
|
|
152690
152693
|
*/
|
|
@@ -154808,7 +154811,7 @@ var init_v1 = __esm({
|
|
|
154808
154811
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
154809
154812
|
import { createHmac } from "crypto";
|
|
154810
154813
|
import { createServer } from "http";
|
|
154811
|
-
import { finished, Readable as Readable2 } from "stream";
|
|
154814
|
+
import { finished, Readable as Readable2, Transform } from "stream";
|
|
154812
154815
|
import { pipeline } from "stream/promises";
|
|
154813
154816
|
import { homedir as homedir13 } from "os";
|
|
154814
154817
|
import { join as join17 } from "path";
|
|
@@ -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,9 +155747,32 @@ function withZeroCapGuard(inner, isFree) {
|
|
|
155671
155747
|
return inner(input2, init2);
|
|
155672
155748
|
};
|
|
155673
155749
|
}
|
|
155674
|
-
|
|
155750
|
+
function isMessagesPath(url3) {
|
|
155751
|
+
return url3 === "/v1/messages" || (url3?.startsWith("/v1/messages?") ?? false);
|
|
155752
|
+
}
|
|
155753
|
+
async function relayWithIdleTimeout(source, destination, idleMs, signal) {
|
|
155754
|
+
let timer2;
|
|
155755
|
+
const arm = () => {
|
|
155756
|
+
clearTimeout(timer2);
|
|
155757
|
+
timer2 = setTimeout(() => watchdog.destroy(new Error("Body read timeout")), idleMs);
|
|
155758
|
+
};
|
|
155759
|
+
const watchdog = new Transform({
|
|
155760
|
+
transform(chunk, _encoding, done) {
|
|
155761
|
+
arm();
|
|
155762
|
+
done(null, chunk);
|
|
155763
|
+
}
|
|
155764
|
+
});
|
|
155765
|
+
arm();
|
|
155766
|
+
try {
|
|
155767
|
+
await pipeline(source, watchdog, destination, { signal });
|
|
155768
|
+
} finally {
|
|
155769
|
+
clearTimeout(timer2);
|
|
155770
|
+
}
|
|
155771
|
+
}
|
|
155772
|
+
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet", capRequest) {
|
|
155675
155773
|
const startTime = Date.now();
|
|
155676
155774
|
const upstreamUrl = `${apiBase}${req.url}`;
|
|
155775
|
+
const isMessages = isMessagesPath(req.url);
|
|
155677
155776
|
const isBlockrunExa = req.url?.startsWith("/v1/exa/") ?? false;
|
|
155678
155777
|
const isModalSandbox = req.url?.startsWith("/v1/modal/") ?? false;
|
|
155679
155778
|
const isPhone = (req.url?.startsWith("/v1/phone/") ?? false) || (req.url?.startsWith("/v1/voice/") ?? false);
|
|
@@ -155683,6 +155782,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155683
155782
|
bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
155684
155783
|
}
|
|
155685
155784
|
const body = Buffer.concat(bodyChunks);
|
|
155785
|
+
const capped = capRequest?.(body);
|
|
155686
155786
|
const headers = {};
|
|
155687
155787
|
for (const [key3, value] of Object.entries(req.headers)) {
|
|
155688
155788
|
if (key3 === "host" || key3 === "connection" || key3 === "transfer-encoding" || key3 === "content-length")
|
|
@@ -155704,6 +155804,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155704
155804
|
body: body.length > 0 ? new Uint8Array(body) : void 0,
|
|
155705
155805
|
signal: clientAbort.signal
|
|
155706
155806
|
});
|
|
155807
|
+
if (upstream.ok) capped?.recordSuccess();
|
|
155707
155808
|
const responseHeaders = {};
|
|
155708
155809
|
upstream.headers.forEach((value, key3) => {
|
|
155709
155810
|
if (key3 === "transfer-encoding" || key3 === "connection" || key3 === "content-encoding" || key3 === "content-length")
|
|
@@ -155713,8 +155814,8 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155713
155814
|
if (accountPassthrough || authMode === "api-key") {
|
|
155714
155815
|
responseHeaders["cache-control"] = "no-store";
|
|
155715
155816
|
}
|
|
155716
|
-
res.writeHead(upstream.status, responseHeaders);
|
|
155717
155817
|
if (accountPassthrough) {
|
|
155818
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
155718
155819
|
if (upstream.body) {
|
|
155719
155820
|
await pipeline(
|
|
155720
155821
|
Readable2.fromWeb(upstream.body),
|
|
@@ -155724,12 +155825,23 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
155724
155825
|
} else {
|
|
155725
155826
|
res.end();
|
|
155726
155827
|
}
|
|
155727
|
-
} else {
|
|
155828
|
+
} else if (isMessages) {
|
|
155829
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
155728
155830
|
if (upstream.body) {
|
|
155729
|
-
|
|
155730
|
-
|
|
155731
|
-
|
|
155732
|
-
|
|
155831
|
+
await relayWithIdleTimeout(
|
|
155832
|
+
Readable2.fromWeb(upstream.body),
|
|
155833
|
+
res,
|
|
155834
|
+
MODEL_BODY_READ_TIMEOUT_MS,
|
|
155835
|
+
clientAbort.signal
|
|
155836
|
+
);
|
|
155837
|
+
} else {
|
|
155838
|
+
res.end();
|
|
155839
|
+
}
|
|
155840
|
+
} else {
|
|
155841
|
+
const chunks = upstream.body ? await readBodyWithTimeout(upstream.body, ERROR_BODY_READ_TIMEOUT_MS) : [];
|
|
155842
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
155843
|
+
for (const chunk of chunks) {
|
|
155844
|
+
safeWrite(res, Buffer.from(chunk));
|
|
155733
155845
|
}
|
|
155734
155846
|
res.end();
|
|
155735
155847
|
}
|
|
@@ -156064,11 +156176,12 @@ async function startProxy(options) {
|
|
|
156064
156176
|
}
|
|
156065
156177
|
const requestOptions = solanaBatch ? { ...options, _solanaBatchActive: true } : options;
|
|
156066
156178
|
const keyFetch = apiKey ? createApiKeyFetch(apiKey, fetch, apiBase) : void 0;
|
|
156179
|
+
const isFreeForCap = (model) => {
|
|
156180
|
+
const { freeIds } = catalog.current();
|
|
156181
|
+
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
156182
|
+
};
|
|
156067
156183
|
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,
|
|
156184
|
+
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
|
|
156072
156185
|
options.spendControl ?? getSharedSpendControl(),
|
|
156073
156186
|
() => {
|
|
156074
156187
|
const store = paymentStore.getStore();
|
|
@@ -157049,7 +157162,8 @@ async function startProxy(options) {
|
|
|
157049
157162
|
}
|
|
157050
157163
|
return;
|
|
157051
157164
|
}
|
|
157052
|
-
const
|
|
157165
|
+
const isMessages = isMessagesPath(req.url);
|
|
157166
|
+
const isVerbatimGatewayPath = isMessages || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
|
|
157053
157167
|
if (isVerbatimGatewayPath || req.url?.match(PAID_API_PATH)) {
|
|
157054
157168
|
try {
|
|
157055
157169
|
await proxyPaidApiRequest(
|
|
@@ -157059,7 +157173,16 @@ async function startProxy(options) {
|
|
|
157059
157173
|
payFetch,
|
|
157060
157174
|
() => paymentStore.getStore()?.amountUsd ?? 0,
|
|
157061
157175
|
false,
|
|
157062
|
-
authMode
|
|
157176
|
+
authMode,
|
|
157177
|
+
// $0 is enforced below this, where calls are signed or fetched.
|
|
157178
|
+
isMessages && options.maxCostPerRunUsd !== void 0 && options.maxCostPerRunUsd !== 0 ? (body) => capMessagesRequest(body, req.headers, {
|
|
157179
|
+
usd: options.maxCostPerRunUsd,
|
|
157180
|
+
mode: options.maxCostPerRunMode ?? "graceful",
|
|
157181
|
+
authMode,
|
|
157182
|
+
sessions: sessionStore,
|
|
157183
|
+
models: catalog.current().models,
|
|
157184
|
+
isFree: isFreeForCap
|
|
157185
|
+
}) : void 0
|
|
157063
157186
|
);
|
|
157064
157187
|
} catch (err) {
|
|
157065
157188
|
if (refuseOverCostCap(res, err)) return;
|
|
@@ -157075,6 +157198,8 @@ async function startProxy(options) {
|
|
|
157075
157198
|
} else if (!res.writableEnded) {
|
|
157076
157199
|
res.end();
|
|
157077
157200
|
}
|
|
157201
|
+
} finally {
|
|
157202
|
+
paymentStore.getStore()?.sessionSpend?.release();
|
|
157078
157203
|
}
|
|
157079
157204
|
return;
|
|
157080
157205
|
}
|
|
@@ -159655,7 +159780,7 @@ data: [DONE]
|
|
|
159655
159780
|
body: responseBody,
|
|
159656
159781
|
completedAt: Date.now()
|
|
159657
159782
|
});
|
|
159658
|
-
if (upstream.status === 200 && responseCache2.shouldCache(body)) {
|
|
159783
|
+
if (upstream.status === 200 && responseCache2.shouldCache(body, reqHeaders)) {
|
|
159659
159784
|
responseCache2.set(cacheKey3, {
|
|
159660
159785
|
body: responseBody,
|
|
159661
159786
|
status: upstream.status,
|
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
|
@@ -101767,7 +101767,7 @@ var require_webidl = __commonJS({
|
|
|
101767
101767
|
var require_util2 = __commonJS({
|
|
101768
101768
|
"node_modules/undici/lib/web/fetch/util.js"(exports, module) {
|
|
101769
101769
|
"use strict";
|
|
101770
|
-
var { Transform } = __require("stream");
|
|
101770
|
+
var { Transform: Transform2 } = __require("stream");
|
|
101771
101771
|
var zlib2 = __require("zlib");
|
|
101772
101772
|
var { redirectStatusSet, referrerPolicyTokens, badPortsSet } = require_constants3();
|
|
101773
101773
|
var { getGlobalOrigin } = require_global();
|
|
@@ -102361,7 +102361,7 @@ var require_util2 = __commonJS({
|
|
|
102361
102361
|
contentRange += isomorphicEncode(`${fullLength}`);
|
|
102362
102362
|
return contentRange;
|
|
102363
102363
|
}
|
|
102364
|
-
var InflateStream = class extends
|
|
102364
|
+
var InflateStream = class extends Transform2 {
|
|
102365
102365
|
#zlibOptions;
|
|
102366
102366
|
/** @param {zlib.ZlibOptions} [zlibOptions] */
|
|
102367
102367
|
constructor(zlibOptions2) {
|
|
@@ -116206,13 +116206,13 @@ var require_mock_pool = __commonJS({
|
|
|
116206
116206
|
var require_pending_interceptors_formatter = __commonJS({
|
|
116207
116207
|
"node_modules/undici/lib/mock/pending-interceptors-formatter.js"(exports, module) {
|
|
116208
116208
|
"use strict";
|
|
116209
|
-
var { Transform } = __require("stream");
|
|
116209
|
+
var { Transform: Transform2 } = __require("stream");
|
|
116210
116210
|
var { Console } = __require("console");
|
|
116211
116211
|
var PERSISTENT = process.versions.icu ? "\u2705" : "Y ";
|
|
116212
116212
|
var NOT_PERSISTENT = process.versions.icu ? "\u274C" : "N ";
|
|
116213
116213
|
module.exports = class PendingInterceptorsFormatter {
|
|
116214
116214
|
constructor({ disableColors } = {}) {
|
|
116215
|
-
this.transform = new
|
|
116215
|
+
this.transform = new Transform2({
|
|
116216
116216
|
transform(chunk, _enc, cb) {
|
|
116217
116217
|
cb(null, chunk);
|
|
116218
116218
|
}
|
|
@@ -128514,7 +128514,7 @@ var require_eventsource_stream = __commonJS({
|
|
|
128514
128514
|
"node_modules/undici/lib/web/eventsource/eventsource-stream.js"(exports, module) {
|
|
128515
128515
|
"use strict";
|
|
128516
128516
|
var buffer2 = __require("buffer");
|
|
128517
|
-
var { Transform } = __require("stream");
|
|
128517
|
+
var { Transform: Transform2 } = __require("stream");
|
|
128518
128518
|
var { isASCIINumber, isValidLastEventId } = require_util6();
|
|
128519
128519
|
var BOM = [239, 187, 191];
|
|
128520
128520
|
var LF = 10;
|
|
@@ -128564,7 +128564,7 @@ var require_eventsource_stream = __commonJS({
|
|
|
128564
128564
|
error62.aborted = false;
|
|
128565
128565
|
return error62;
|
|
128566
128566
|
}
|
|
128567
|
-
var EventSourceStream = class extends
|
|
128567
|
+
var EventSourceStream = class extends Transform2 {
|
|
128568
128568
|
/**
|
|
128569
128569
|
* @type {eventSourceSettings}
|
|
128570
128570
|
*/
|
|
@@ -275774,7 +275774,7 @@ function fingerprint(view) {
|
|
|
275774
275774
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
275775
275775
|
import { createHmac } from "crypto";
|
|
275776
275776
|
import { createServer } from "http";
|
|
275777
|
-
import { finished, Readable as Readable2 } from "stream";
|
|
275777
|
+
import { finished, Readable as Readable2, Transform } from "stream";
|
|
275778
275778
|
import { pipeline } from "stream/promises";
|
|
275779
275779
|
import { homedir as homedir13 } from "os";
|
|
275780
275780
|
import { join as join17 } from "path";
|
|
@@ -286533,7 +286533,7 @@ var ResponseCache = class {
|
|
|
286533
286533
|
*/
|
|
286534
286534
|
shouldCache(body, headers) {
|
|
286535
286535
|
if (!this.config.enabled) return false;
|
|
286536
|
-
if (headers?.["cache-control"]
|
|
286536
|
+
if (/\bno-(?:cache|store)\b/i.test(headers?.["cache-control"] ?? "")) {
|
|
286537
286537
|
return false;
|
|
286538
286538
|
}
|
|
286539
286539
|
try {
|
|
@@ -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,9 +291091,32 @@ function withZeroCapGuard(inner, isFree) {
|
|
|
291015
291091
|
return inner(input2, init2);
|
|
291016
291092
|
};
|
|
291017
291093
|
}
|
|
291018
|
-
|
|
291094
|
+
function isMessagesPath(url3) {
|
|
291095
|
+
return url3 === "/v1/messages" || (url3?.startsWith("/v1/messages?") ?? false);
|
|
291096
|
+
}
|
|
291097
|
+
async function relayWithIdleTimeout(source, destination, idleMs, signal) {
|
|
291098
|
+
let timer2;
|
|
291099
|
+
const arm = () => {
|
|
291100
|
+
clearTimeout(timer2);
|
|
291101
|
+
timer2 = setTimeout(() => watchdog.destroy(new Error("Body read timeout")), idleMs);
|
|
291102
|
+
};
|
|
291103
|
+
const watchdog = new Transform({
|
|
291104
|
+
transform(chunk, _encoding, done) {
|
|
291105
|
+
arm();
|
|
291106
|
+
done(null, chunk);
|
|
291107
|
+
}
|
|
291108
|
+
});
|
|
291109
|
+
arm();
|
|
291110
|
+
try {
|
|
291111
|
+
await pipeline(source, watchdog, destination, { signal });
|
|
291112
|
+
} finally {
|
|
291113
|
+
clearTimeout(timer2);
|
|
291114
|
+
}
|
|
291115
|
+
}
|
|
291116
|
+
async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPaymentUsd, accountPassthrough = false, authMode = "wallet", capRequest) {
|
|
291019
291117
|
const startTime = Date.now();
|
|
291020
291118
|
const upstreamUrl = `${apiBase}${req.url}`;
|
|
291119
|
+
const isMessages = isMessagesPath(req.url);
|
|
291021
291120
|
const isBlockrunExa = req.url?.startsWith("/v1/exa/") ?? false;
|
|
291022
291121
|
const isModalSandbox = req.url?.startsWith("/v1/modal/") ?? false;
|
|
291023
291122
|
const isPhone = (req.url?.startsWith("/v1/phone/") ?? false) || (req.url?.startsWith("/v1/voice/") ?? false);
|
|
@@ -291027,6 +291126,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291027
291126
|
bodyChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
291028
291127
|
}
|
|
291029
291128
|
const body = Buffer.concat(bodyChunks);
|
|
291129
|
+
const capped = capRequest?.(body);
|
|
291030
291130
|
const headers = {};
|
|
291031
291131
|
for (const [key3, value] of Object.entries(req.headers)) {
|
|
291032
291132
|
if (key3 === "host" || key3 === "connection" || key3 === "transfer-encoding" || key3 === "content-length")
|
|
@@ -291048,6 +291148,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291048
291148
|
body: body.length > 0 ? new Uint8Array(body) : void 0,
|
|
291049
291149
|
signal: clientAbort.signal
|
|
291050
291150
|
});
|
|
291151
|
+
if (upstream.ok) capped?.recordSuccess();
|
|
291051
291152
|
const responseHeaders = {};
|
|
291052
291153
|
upstream.headers.forEach((value, key3) => {
|
|
291053
291154
|
if (key3 === "transfer-encoding" || key3 === "connection" || key3 === "content-encoding" || key3 === "content-length")
|
|
@@ -291057,8 +291158,8 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291057
291158
|
if (accountPassthrough || authMode === "api-key") {
|
|
291058
291159
|
responseHeaders["cache-control"] = "no-store";
|
|
291059
291160
|
}
|
|
291060
|
-
res.writeHead(upstream.status, responseHeaders);
|
|
291061
291161
|
if (accountPassthrough) {
|
|
291162
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
291062
291163
|
if (upstream.body) {
|
|
291063
291164
|
await pipeline(
|
|
291064
291165
|
Readable2.fromWeb(upstream.body),
|
|
@@ -291068,12 +291169,23 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
|
|
|
291068
291169
|
} else {
|
|
291069
291170
|
res.end();
|
|
291070
291171
|
}
|
|
291071
|
-
} else {
|
|
291172
|
+
} else if (isMessages) {
|
|
291173
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
291072
291174
|
if (upstream.body) {
|
|
291073
|
-
|
|
291074
|
-
|
|
291075
|
-
|
|
291076
|
-
|
|
291175
|
+
await relayWithIdleTimeout(
|
|
291176
|
+
Readable2.fromWeb(upstream.body),
|
|
291177
|
+
res,
|
|
291178
|
+
MODEL_BODY_READ_TIMEOUT_MS,
|
|
291179
|
+
clientAbort.signal
|
|
291180
|
+
);
|
|
291181
|
+
} else {
|
|
291182
|
+
res.end();
|
|
291183
|
+
}
|
|
291184
|
+
} else {
|
|
291185
|
+
const chunks = upstream.body ? await readBodyWithTimeout(upstream.body, ERROR_BODY_READ_TIMEOUT_MS) : [];
|
|
291186
|
+
res.writeHead(upstream.status, responseHeaders);
|
|
291187
|
+
for (const chunk of chunks) {
|
|
291188
|
+
safeWrite(res, Buffer.from(chunk));
|
|
291077
291189
|
}
|
|
291078
291190
|
res.end();
|
|
291079
291191
|
}
|
|
@@ -291408,11 +291520,12 @@ async function startProxy(options) {
|
|
|
291408
291520
|
}
|
|
291409
291521
|
const requestOptions = solanaBatch ? { ...options, _solanaBatchActive: true } : options;
|
|
291410
291522
|
const keyFetch = apiKey ? createApiKeyFetch(apiKey, fetch, apiBase) : void 0;
|
|
291523
|
+
const isFreeForCap = (model) => {
|
|
291524
|
+
const { freeIds } = catalog.current();
|
|
291525
|
+
return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
|
|
291526
|
+
};
|
|
291411
291527
|
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,
|
|
291528
|
+
options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
|
|
291416
291529
|
options.spendControl ?? getSharedSpendControl(),
|
|
291417
291530
|
() => {
|
|
291418
291531
|
const store = paymentStore.getStore();
|
|
@@ -292393,7 +292506,8 @@ async function startProxy(options) {
|
|
|
292393
292506
|
}
|
|
292394
292507
|
return;
|
|
292395
292508
|
}
|
|
292396
|
-
const
|
|
292509
|
+
const isMessages = isMessagesPath(req.url);
|
|
292510
|
+
const isVerbatimGatewayPath = isMessages || req.url === "/v1/audio/speech" || (req.url?.startsWith("/v1/audio/speech?") ?? false);
|
|
292397
292511
|
if (isVerbatimGatewayPath || req.url?.match(PAID_API_PATH)) {
|
|
292398
292512
|
try {
|
|
292399
292513
|
await proxyPaidApiRequest(
|
|
@@ -292403,7 +292517,16 @@ async function startProxy(options) {
|
|
|
292403
292517
|
payFetch,
|
|
292404
292518
|
() => paymentStore.getStore()?.amountUsd ?? 0,
|
|
292405
292519
|
false,
|
|
292406
|
-
authMode
|
|
292520
|
+
authMode,
|
|
292521
|
+
// $0 is enforced below this, where calls are signed or fetched.
|
|
292522
|
+
isMessages && options.maxCostPerRunUsd !== void 0 && options.maxCostPerRunUsd !== 0 ? (body) => capMessagesRequest(body, req.headers, {
|
|
292523
|
+
usd: options.maxCostPerRunUsd,
|
|
292524
|
+
mode: options.maxCostPerRunMode ?? "graceful",
|
|
292525
|
+
authMode,
|
|
292526
|
+
sessions: sessionStore,
|
|
292527
|
+
models: catalog.current().models,
|
|
292528
|
+
isFree: isFreeForCap
|
|
292529
|
+
}) : void 0
|
|
292407
292530
|
);
|
|
292408
292531
|
} catch (err) {
|
|
292409
292532
|
if (refuseOverCostCap(res, err)) return;
|
|
@@ -292419,6 +292542,8 @@ async function startProxy(options) {
|
|
|
292419
292542
|
} else if (!res.writableEnded) {
|
|
292420
292543
|
res.end();
|
|
292421
292544
|
}
|
|
292545
|
+
} finally {
|
|
292546
|
+
paymentStore.getStore()?.sessionSpend?.release();
|
|
292422
292547
|
}
|
|
292423
292548
|
return;
|
|
292424
292549
|
}
|
|
@@ -294999,7 +295124,7 @@ data: [DONE]
|
|
|
294999
295124
|
body: responseBody,
|
|
295000
295125
|
completedAt: Date.now()
|
|
295001
295126
|
});
|
|
295002
|
-
if (upstream.status === 200 && responseCache2.shouldCache(body)) {
|
|
295127
|
+
if (upstream.status === 200 && responseCache2.shouldCache(body, reqHeaders)) {
|
|
295003
295128
|
responseCache2.set(cacheKey3, {
|
|
295004
295129
|
body: responseBody,
|
|
295005
295130
|
status: upstream.status,
|
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/features.md
CHANGED
|
@@ -46,8 +46,10 @@ The cache key is a SHA-256 hash of the request body (model + messages + params),
|
|
|
46
46
|
|
|
47
47
|
**Bypass cache:**
|
|
48
48
|
|
|
49
|
+
Either way, the request is neither answered from the cache nor stored in it. The separate 30-second dedup cache still applies, so an identical retry inside that window can replay the response.
|
|
50
|
+
|
|
49
51
|
```typescript
|
|
50
|
-
// Via header
|
|
52
|
+
// Via header ("no-store" works too)
|
|
51
53
|
fetch("/v1/chat/completions", {
|
|
52
54
|
headers: { "Cache-Control": "no-cache" }
|
|
53
55
|
})
|
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.310",
|
|
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
|
|