@kognai/clawrouter-x402 0.1.2 → 0.1.3
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/dist/clawrouter-v2.js +16 -3
- package/package.json +1 -1
package/dist/clawrouter-v2.js
CHANGED
|
@@ -288,11 +288,24 @@ async function callAnthropicDirect(model, messages, maxTokens = 4096) {
|
|
|
288
288
|
throw new Error(`Anthropic direct API returned ${res.status}: ${res.data.slice(0, 300)}`);
|
|
289
289
|
}
|
|
290
290
|
const json = JSON.parse(res.data);
|
|
291
|
+
const inTok = json.usage?.input_tokens || 0;
|
|
292
|
+
const outTok = json.usage?.output_tokens || 0;
|
|
293
|
+
// TICKET-350 cost visibility: the direct path used to hardcode cost_usd=0, so
|
|
294
|
+
// the honest-routing haiku calls logged $0 and the ledger under-counted real
|
|
295
|
+
// spend. Compute the actual cost from token usage × per-million USD rates.
|
|
296
|
+
const DIRECT_RATES = {
|
|
297
|
+
'claude-haiku-4-5': { in: 0.80, out: 4.00 },
|
|
298
|
+
'claude-sonnet-4': { in: 3.00, out: 15.00 },
|
|
299
|
+
'claude-opus-4': { in: 15.00, out: 75.00 },
|
|
300
|
+
};
|
|
301
|
+
const rateKey = Object.keys(DIRECT_RATES).find(k => model.includes(k));
|
|
302
|
+
const rate = rateKey ? DIRECT_RATES[rateKey] : { in: 0.80, out: 4.00 }; // default ≈ haiku
|
|
303
|
+
const cost_usd = (inTok * rate.in + outTok * rate.out) / 1_000_000;
|
|
291
304
|
return {
|
|
292
305
|
content: json.content?.[0]?.text || '',
|
|
293
|
-
input_tokens:
|
|
294
|
-
output_tokens:
|
|
295
|
-
cost_usd
|
|
306
|
+
input_tokens: inTok,
|
|
307
|
+
output_tokens: outTok,
|
|
308
|
+
cost_usd,
|
|
296
309
|
};
|
|
297
310
|
}
|
|
298
311
|
// ── x402 Payment Signing (EIP-3009 TransferWithAuthorization) ─────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kognai/clawrouter-x402",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ClawRouter v2 — Kognai's viem-backed x402 ModelRouter implementation. Injected into @kognai/orchestrator-core's router seam at startup, so core never depends on viem; products that don't route on-chain simply don't install this package.",
|
|
6
6
|
"main": "dist/index.js",
|