@blockrun/clawrouter 0.5.8 → 0.6.1
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 +42 -454
- package/dist/index.js +128 -72
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/scripts/reinstall.sh +177 -0
- package/scripts/uninstall.sh +135 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ One wallet, 30+ models, zero API keys.
|
|
|
10
10
|
[](https://typescriptlang.org)
|
|
11
11
|
[](https://nodejs.org)
|
|
12
12
|
|
|
13
|
-
[Docs](https://blockrun.ai/docs) · [Models](https://blockrun.ai/models) · [Configuration](docs/configuration.md) · [
|
|
13
|
+
[Docs](https://blockrun.ai/docs) · [Models](https://blockrun.ai/models) · [Configuration](docs/configuration.md) · [Features](docs/features.md) · [Troubleshooting](docs/troubleshooting.md) · [Telegram](https://t.me/blockrunAI) · [X](https://x.com/BlockRunAI)
|
|
14
14
|
|
|
15
15
|
</div>
|
|
16
16
|
|
|
@@ -56,7 +56,7 @@ Done! Smart routing (`blockrun/auto`) is now your default model.
|
|
|
56
56
|
### Tips
|
|
57
57
|
|
|
58
58
|
- **Use `/model blockrun/auto`** in any conversation to switch on the fly
|
|
59
|
-
- **Free tier?** Use `/model free` — routes to
|
|
59
|
+
- **Free tier?** Use `/model free` — routes to gpt-oss-120b at $0
|
|
60
60
|
- **Model aliases:** `/model sonnet`, `/model grok`, `/model deepseek`, `/model kimi`
|
|
61
61
|
- **Want a specific model?** Use `blockrun/openai/gpt-4o` or `blockrun/anthropic/claude-sonnet-4`
|
|
62
62
|
- **Already have a funded wallet?** `export BLOCKRUN_WALLET_KEY=0x...`
|
|
@@ -94,41 +94,7 @@ Request → Weighted Scorer (15 dimensions)
|
|
|
94
94
|
|
|
95
95
|
No external classifier calls. Ambiguous queries default to the MEDIUM tier (DeepSeek/GPT-4o-mini) — fast, cheap, and good enough for most tasks.
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
| Dimension | Weight | What It Detects |
|
|
100
|
-
| -------------------- | ------ | ---------------------------------------- |
|
|
101
|
-
| Reasoning markers | 0.18 | "prove", "theorem", "step by step" |
|
|
102
|
-
| Code presence | 0.15 | "function", "async", "import", "```" |
|
|
103
|
-
| Multi-step patterns | 0.12 | "first...then", "step 1", numbered lists |
|
|
104
|
-
| **Agentic task** | 0.10 | "run", "test", "fix", "deploy", "edit" |
|
|
105
|
-
| Technical terms | 0.10 | "algorithm", "kubernetes", "distributed" |
|
|
106
|
-
| Token count | 0.08 | short (<50) vs long (>500) prompts |
|
|
107
|
-
| Creative markers | 0.05 | "story", "poem", "brainstorm" |
|
|
108
|
-
| Question complexity | 0.05 | Multiple question marks |
|
|
109
|
-
| Constraint count | 0.04 | "at most", "O(n)", "maximum" |
|
|
110
|
-
| Imperative verbs | 0.03 | "build", "create", "implement" |
|
|
111
|
-
| Output format | 0.03 | "json", "yaml", "schema" |
|
|
112
|
-
| Simple indicators | 0.02 | "what is", "define", "translate" |
|
|
113
|
-
| Domain specificity | 0.02 | "quantum", "fpga", "genomics" |
|
|
114
|
-
| Reference complexity | 0.02 | "the docs", "the api", "above" |
|
|
115
|
-
| Negation complexity | 0.01 | "don't", "avoid", "without" |
|
|
116
|
-
|
|
117
|
-
Weighted sum → sigmoid confidence calibration → tier selection.
|
|
118
|
-
|
|
119
|
-
### Supported Languages
|
|
120
|
-
|
|
121
|
-
ClawRouter's keyword-based routing works with prompts in:
|
|
122
|
-
|
|
123
|
-
| Language | Script | Examples |
|
|
124
|
-
| --------------------- | ------------ | ------------------------------ |
|
|
125
|
-
| **English** | Latin | Full support (default) |
|
|
126
|
-
| **Chinese (中文)** | Han/CJK | 证明, 定理, 你好, 什么是 |
|
|
127
|
-
| **Japanese (日本語)** | Kanji + Kana | 証明, こんにちは, アルゴリズム |
|
|
128
|
-
| **Russian (Русский)** | Cyrillic | доказать, привет, алгоритм |
|
|
129
|
-
| **German (Deutsch)** | Latin | beweisen, hallo, algorithmus |
|
|
130
|
-
|
|
131
|
-
Mixed-language prompts are supported — keywords from all languages are checked simultaneously.
|
|
97
|
+
**Deep dive:** [15-dimension scoring weights](docs/configuration.md#scoring-weights) | [Architecture](docs/architecture.md)
|
|
132
98
|
|
|
133
99
|
### Tier → Model Mapping
|
|
134
100
|
|
|
@@ -141,122 +107,20 @@ Mixed-language prompts are supported — keywords from all languages are checked
|
|
|
141
107
|
|
|
142
108
|
Special rule: 2+ reasoning markers → REASONING at 0.97 confidence.
|
|
143
109
|
|
|
144
|
-
###
|
|
110
|
+
### Advanced Features
|
|
145
111
|
|
|
146
|
-
ClawRouter
|
|
112
|
+
ClawRouter v0.5+ includes intelligent features that work automatically:
|
|
147
113
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
**How it works:**
|
|
155
|
-
|
|
156
|
-
- Detects agentic keywords: file ops ("read", "edit"), execution ("run", "test", "deploy"), iteration ("fix", "debug", "verify")
|
|
157
|
-
- Threshold: 2+ signals triggers auto-switch to agentic tiers
|
|
158
|
-
- No config needed — works automatically
|
|
159
|
-
|
|
160
|
-
**Agentic tier models** (optimized for multi-step autonomy):
|
|
161
|
-
|
|
162
|
-
| Tier | Agentic Model | Why |
|
|
163
|
-
| --------- | ---------------- | ------------------------------ |
|
|
164
|
-
| SIMPLE | claude-haiku-4.5 | Fast + reliable tool use |
|
|
165
|
-
| MEDIUM | kimi-k2.5 | 200+ tool chains, 76% cheaper |
|
|
166
|
-
| COMPLEX | claude-sonnet-4 | Best balance for complex tasks |
|
|
167
|
-
| REASONING | kimi-k2.5 | Extended reasoning + execution |
|
|
168
|
-
|
|
169
|
-
You can also force agentic mode via config:
|
|
170
|
-
|
|
171
|
-
```yaml
|
|
172
|
-
# openclaw.yaml
|
|
173
|
-
plugins:
|
|
174
|
-
- id: "@blockrun/clawrouter"
|
|
175
|
-
config:
|
|
176
|
-
routing:
|
|
177
|
-
overrides:
|
|
178
|
-
agenticMode: true # Always use agentic tiers
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Tool Detection (v0.5)
|
|
182
|
-
|
|
183
|
-
When your request includes a `tools` array (function calling), ClawRouter automatically switches to agentic tiers:
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
// Request with tools → auto-agentic mode
|
|
187
|
-
{
|
|
188
|
-
model: "blockrun/auto",
|
|
189
|
-
messages: [{ role: "user", content: "Check the weather" }],
|
|
190
|
-
tools: [{ type: "function", function: { name: "get_weather", ... } }]
|
|
191
|
-
}
|
|
192
|
-
// → Routes to claude-haiku-4.5 (excellent tool use)
|
|
193
|
-
// → Instead of gemini-flash (may produce malformed tool calls)
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
**Why this matters:** Some models (like `deepseek-reasoner`) are optimized for chain-of-thought reasoning but can generate malformed tool calls. Tool detection ensures requests with functions go to models proven to handle tool use correctly.
|
|
197
|
-
|
|
198
|
-
### Context-Length-Aware Routing (v0.5)
|
|
199
|
-
|
|
200
|
-
ClawRouter automatically filters out models that can't handle your context size:
|
|
201
|
-
|
|
202
|
-
```
|
|
203
|
-
150K token request:
|
|
204
|
-
Full chain: [grok-4-fast (131K), deepseek (128K), kimi (262K), gemini (1M)]
|
|
205
|
-
Filtered: [kimi (262K), gemini (1M)]
|
|
206
|
-
→ Skips models that would fail with "context too long" errors
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
This prevents wasted API calls and faster fallback to capable models.
|
|
210
|
-
|
|
211
|
-
### Model Aliases (v0.5)
|
|
212
|
-
|
|
213
|
-
Use short aliases instead of full model paths:
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
/model free # nvidia/gpt-oss-120b (FREE!)
|
|
217
|
-
/model sonnet # anthropic/claude-sonnet-4
|
|
218
|
-
/model opus # anthropic/claude-opus-4
|
|
219
|
-
/model haiku # anthropic/claude-haiku-4.5
|
|
220
|
-
/model gpt # openai/gpt-4o
|
|
221
|
-
/model gpt5 # openai/gpt-5.2
|
|
222
|
-
/model deepseek # deepseek/deepseek-chat
|
|
223
|
-
/model reasoner # deepseek/deepseek-reasoner
|
|
224
|
-
/model kimi # moonshot/kimi-k2.5
|
|
225
|
-
/model gemini # google/gemini-2.5-pro
|
|
226
|
-
/model flash # google/gemini-2.5-flash
|
|
227
|
-
/model grok # xai/grok-3
|
|
228
|
-
/model grok-fast # xai/grok-4-fast-reasoning
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
All aliases work with `/model blockrun/xxx` or just `/model xxx`.
|
|
232
|
-
|
|
233
|
-
### Free Tier Fallback (v0.5)
|
|
234
|
-
|
|
235
|
-
When your wallet balance hits $0, ClawRouter automatically falls back to the free model (`nvidia/gpt-oss-120b`):
|
|
236
|
-
|
|
237
|
-
```
|
|
238
|
-
Wallet: $0.00
|
|
239
|
-
Request: "Help me write a function"
|
|
240
|
-
→ Routes to nvidia/gpt-oss-120b (FREE)
|
|
241
|
-
→ No "insufficient funds" error
|
|
242
|
-
→ Keep building while you top up
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
You'll never get blocked by an empty wallet — the free tier keeps you running.
|
|
246
|
-
|
|
247
|
-
### Session Persistence (v0.5)
|
|
248
|
-
|
|
249
|
-
For multi-turn conversations, ClawRouter pins the model to prevent mid-task switching:
|
|
250
|
-
|
|
251
|
-
```
|
|
252
|
-
Turn 1: "Build a React component" → claude-sonnet-4
|
|
253
|
-
Turn 2: "Add dark mode support" → claude-sonnet-4 (pinned)
|
|
254
|
-
Turn 3: "Now add tests" → claude-sonnet-4 (pinned)
|
|
255
|
-
```
|
|
114
|
+
- **Agentic auto-detect** — routes multi-step tasks to Kimi K2.5
|
|
115
|
+
- **Tool detection** — auto-switches when `tools` array present
|
|
116
|
+
- **Context-aware** — filters models that can't handle your context size
|
|
117
|
+
- **Model aliases** — `/model free`, `/model sonnet`, `/model grok`
|
|
118
|
+
- **Session persistence** — pins model for multi-turn conversations
|
|
119
|
+
- **Free tier fallback** — keeps working when wallet is empty
|
|
256
120
|
|
|
257
|
-
|
|
121
|
+
**Full details:** [docs/features.md](docs/features.md)
|
|
258
122
|
|
|
259
|
-
### Cost Savings
|
|
123
|
+
### Cost Savings
|
|
260
124
|
|
|
261
125
|
| Tier | % of Traffic | Cost/M |
|
|
262
126
|
| ------------------- | ------------ | ----------- |
|
|
@@ -280,6 +144,7 @@ Compared to **$75/M** for Claude Opus = **96% savings** on a typical workload.
|
|
|
280
144
|
| gpt-5.2 | $1.75 | $14.00 | 400K | \* |
|
|
281
145
|
| gpt-4o | $2.50 | $10.00 | 128K | |
|
|
282
146
|
| gpt-4o-mini | $0.15 | $0.60 | 128K | |
|
|
147
|
+
| gpt-oss-120b | **$0** | **$0** | 128K | |
|
|
283
148
|
| o3 | $2.00 | $8.00 | 200K | \* |
|
|
284
149
|
| o3-mini | $1.10 | $4.40 | 128K | \* |
|
|
285
150
|
| **Anthropic** | | | | |
|
|
@@ -300,10 +165,8 @@ Compared to **$75/M** for Claude Opus = **96% savings** on a typical workload.
|
|
|
300
165
|
| grok-code-fast-1 | $0.20 | $1.50 | 131K | |
|
|
301
166
|
| **Moonshot** | | | | |
|
|
302
167
|
| kimi-k2.5 | $0.50 | $2.40 | 262K | \* |
|
|
303
|
-
| **NVIDIA (Free)** | | | | |
|
|
304
|
-
| gpt-oss-120b | **$0** | **$0** | 128K | |
|
|
305
168
|
|
|
306
|
-
> **Free tier:** `
|
|
169
|
+
> **Free tier:** `gpt-oss-120b` costs nothing and serves as automatic fallback when wallet is empty.
|
|
307
170
|
|
|
308
171
|
Full list: [`src/models.ts`](src/models.ts)
|
|
309
172
|
|
|
@@ -340,99 +203,17 @@ USDC stays in your wallet until spent — non-custodial. Price is visible in the
|
|
|
340
203
|
|
|
341
204
|
## Wallet Configuration
|
|
342
205
|
|
|
343
|
-
ClawRouter
|
|
344
|
-
|
|
345
|
-
### Resolution Order
|
|
346
|
-
|
|
347
|
-
| Priority | Source | Behavior |
|
|
348
|
-
| -------- | ---------------------------------------------- | --------------------------------- |
|
|
349
|
-
| 1st | Saved file (`~/.openclaw/blockrun/wallet.key`) | Used if exists |
|
|
350
|
-
| 2nd | `BLOCKRUN_WALLET_KEY` env var | Used if no saved file |
|
|
351
|
-
| 3rd | Auto-generate | Creates new wallet, saves to file |
|
|
352
|
-
|
|
353
|
-
**Important:** The saved file takes priority over the environment variable. If you have both, the env var is ignored.
|
|
354
|
-
|
|
355
|
-
### Common Scenarios
|
|
206
|
+
ClawRouter auto-generates and saves a wallet at `~/.openclaw/blockrun/wallet.key`.
|
|
356
207
|
|
|
357
208
|
```bash
|
|
358
|
-
# Check
|
|
359
|
-
ls -la ~/.openclaw/blockrun/wallet.key
|
|
360
|
-
|
|
361
|
-
# Use your own wallet (only works if no saved file exists)
|
|
362
|
-
export BLOCKRUN_WALLET_KEY=0x...
|
|
363
|
-
|
|
364
|
-
# Force use of a different wallet
|
|
365
|
-
rm ~/.openclaw/blockrun/wallet.key
|
|
366
|
-
export BLOCKRUN_WALLET_KEY=0x...
|
|
367
|
-
openclaw restart
|
|
368
|
-
|
|
369
|
-
# See which wallet is active
|
|
370
|
-
curl http://localhost:8402/health | jq .wallet
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
### Why This Order?
|
|
374
|
-
|
|
375
|
-
The saved file is checked first to ensure wallet persistence across sessions. Once a wallet is generated and funded, you don't want an accidentally-set env var to switch wallets and leave your funds inaccessible.
|
|
376
|
-
|
|
377
|
-
If you explicitly want to use a different wallet:
|
|
378
|
-
|
|
379
|
-
1. Delete `~/.openclaw/blockrun/wallet.key`
|
|
380
|
-
2. Set `BLOCKRUN_WALLET_KEY=0x...`
|
|
381
|
-
3. Restart OpenClaw
|
|
382
|
-
|
|
383
|
-
### Wallet Backup & Recovery
|
|
384
|
-
|
|
385
|
-
Your wallet private key is stored at `~/.openclaw/blockrun/wallet.key`. **Back up this file before terminating any VPS or machine!**
|
|
386
|
-
|
|
387
|
-
#### Using the `/wallet` Command
|
|
388
|
-
|
|
389
|
-
ClawRouter provides a built-in command for wallet management:
|
|
390
|
-
|
|
391
|
-
```bash
|
|
392
|
-
# Check wallet status (address, balance, file location)
|
|
209
|
+
# Check wallet status
|
|
393
210
|
/wallet
|
|
394
211
|
|
|
395
|
-
#
|
|
396
|
-
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
The `/wallet export` command displays your private key so you can copy it before terminating a machine.
|
|
400
|
-
|
|
401
|
-
#### Manual Backup
|
|
402
|
-
|
|
403
|
-
```bash
|
|
404
|
-
# Option 1: Copy the key file
|
|
405
|
-
cp ~/.openclaw/blockrun/wallet.key ~/backup-wallet.key
|
|
406
|
-
|
|
407
|
-
# Option 2: View and copy the key
|
|
408
|
-
cat ~/.openclaw/blockrun/wallet.key
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
#### Restore on a New Machine
|
|
412
|
-
|
|
413
|
-
```bash
|
|
414
|
-
# Option 1: Set environment variable (before installing ClawRouter)
|
|
415
|
-
export BLOCKRUN_WALLET_KEY=0x...your_key_here...
|
|
416
|
-
openclaw plugins install @blockrun/clawrouter
|
|
417
|
-
|
|
418
|
-
# Option 2: Create the key file directly
|
|
419
|
-
mkdir -p ~/.openclaw/blockrun
|
|
420
|
-
echo "0x...your_key_here..." > ~/.openclaw/blockrun/wallet.key
|
|
421
|
-
chmod 600 ~/.openclaw/blockrun/wallet.key
|
|
422
|
-
openclaw plugins install @blockrun/clawrouter
|
|
212
|
+
# Use your own wallet
|
|
213
|
+
export BLOCKRUN_WALLET_KEY=0x...
|
|
423
214
|
```
|
|
424
215
|
|
|
425
|
-
**
|
|
426
|
-
|
|
427
|
-
#### Lost Key Recovery
|
|
428
|
-
|
|
429
|
-
If you lose your wallet key, **there is no way to recover it**. The wallet is self-custodial, meaning only you have the private key. We do not store keys or have any way to restore access.
|
|
430
|
-
|
|
431
|
-
**Prevention tips:**
|
|
432
|
-
|
|
433
|
-
- Run `/wallet export` before terminating any VPS
|
|
434
|
-
- Keep a secure backup of `~/.openclaw/blockrun/wallet.key`
|
|
435
|
-
- For production use, consider using a hardware wallet or key management system
|
|
216
|
+
**Full reference:** [Wallet configuration](docs/configuration.md#wallet-configuration) | [Backup & recovery](docs/configuration.md#wallet-backup--recovery)
|
|
436
217
|
|
|
437
218
|
---
|
|
438
219
|
|
|
@@ -467,40 +248,13 @@ Routing is **client-side** — open source and inspectable.
|
|
|
467
248
|
|
|
468
249
|
## Configuration
|
|
469
250
|
|
|
470
|
-
For basic usage, no configuration
|
|
471
|
-
|
|
472
|
-
| Setting | Default | Description |
|
|
473
|
-
| --------------------- | -------- | ------------------------------------ |
|
|
474
|
-
| `CLAWROUTER_DISABLED` | `false` | Disable plugin (use default routing) |
|
|
475
|
-
| `BLOCKRUN_PROXY_PORT` | `8402` | Proxy port (env var) |
|
|
476
|
-
| `BLOCKRUN_WALLET_KEY` | auto | Wallet private key (env var) |
|
|
477
|
-
| `routing.tiers` | see docs | Override tier→model mappings |
|
|
478
|
-
| `routing.scoring` | see docs | Custom keyword weights |
|
|
479
|
-
|
|
480
|
-
**Quick examples:**
|
|
481
|
-
|
|
482
|
-
```bash
|
|
483
|
-
# Temporarily disable ClawRouter (use OpenClaw's default routing)
|
|
484
|
-
CLAWROUTER_DISABLED=true openclaw gateway restart
|
|
485
|
-
|
|
486
|
-
# Re-enable ClawRouter
|
|
487
|
-
openclaw gateway restart
|
|
251
|
+
For basic usage, no configuration needed. For advanced options:
|
|
488
252
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
```yaml
|
|
495
|
-
# openclaw.yaml — override models
|
|
496
|
-
plugins:
|
|
497
|
-
- id: "@blockrun/clawrouter"
|
|
498
|
-
config:
|
|
499
|
-
routing:
|
|
500
|
-
tiers:
|
|
501
|
-
COMPLEX:
|
|
502
|
-
primary: "openai/gpt-4o"
|
|
503
|
-
```
|
|
253
|
+
| Setting | Default | Description |
|
|
254
|
+
| --------------------- | ------- | --------------------- |
|
|
255
|
+
| `CLAWROUTER_DISABLED` | `false` | Disable smart routing |
|
|
256
|
+
| `BLOCKRUN_PROXY_PORT` | `8402` | Proxy port |
|
|
257
|
+
| `BLOCKRUN_WALLET_KEY` | auto | Wallet private key |
|
|
504
258
|
|
|
505
259
|
**Full reference:** [docs/configuration.md](docs/configuration.md)
|
|
506
260
|
|
|
@@ -508,57 +262,20 @@ plugins:
|
|
|
508
262
|
|
|
509
263
|
## Programmatic Usage
|
|
510
264
|
|
|
511
|
-
Use
|
|
265
|
+
Use ClawRouter directly in your code:
|
|
512
266
|
|
|
513
267
|
```typescript
|
|
514
|
-
import { startProxy } from "@blockrun/clawrouter";
|
|
515
|
-
|
|
516
|
-
const proxy = await startProxy({
|
|
517
|
-
walletKey: process.env.BLOCKRUN_WALLET_KEY!,
|
|
518
|
-
onReady: (port) => console.log(`Proxy on port ${port}`),
|
|
519
|
-
onRouted: (d) => console.log(`${d.model} saved ${(d.savings * 100).toFixed(0)}%`),
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
// Any OpenAI-compatible client works
|
|
523
|
-
const res = await fetch(`${proxy.baseUrl}/v1/chat/completions`, {
|
|
524
|
-
method: "POST",
|
|
525
|
-
headers: { "Content-Type": "application/json" },
|
|
526
|
-
body: JSON.stringify({
|
|
527
|
-
model: "blockrun/auto",
|
|
528
|
-
messages: [{ role: "user", content: "What is 2+2?" }],
|
|
529
|
-
}),
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
await proxy.close();
|
|
533
|
-
```
|
|
268
|
+
import { startProxy, route } from "@blockrun/clawrouter";
|
|
534
269
|
|
|
535
|
-
|
|
270
|
+
// Start proxy server
|
|
271
|
+
const proxy = await startProxy({ walletKey: "0x..." });
|
|
536
272
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
// Build pricing map
|
|
541
|
-
const modelPricing = new Map();
|
|
542
|
-
for (const m of BLOCKRUN_MODELS) {
|
|
543
|
-
modelPricing.set(m.id, { inputPrice: m.inputPrice, outputPrice: m.outputPrice });
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const decision = route("Prove sqrt(2) is irrational", undefined, 4096, {
|
|
547
|
-
config: DEFAULT_ROUTING_CONFIG,
|
|
548
|
-
modelPricing,
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
console.log(decision);
|
|
552
|
-
// {
|
|
553
|
-
// model: "deepseek/deepseek-reasoner",
|
|
554
|
-
// tier: "REASONING",
|
|
555
|
-
// confidence: 0.97,
|
|
556
|
-
// method: "rules",
|
|
557
|
-
// savings: 0.994,
|
|
558
|
-
// costEstimate: 0.002,
|
|
559
|
-
// }
|
|
273
|
+
// Or use router directly (no proxy)
|
|
274
|
+
const decision = route("Prove sqrt(2) is irrational", ...);
|
|
560
275
|
```
|
|
561
276
|
|
|
277
|
+
**Full examples:** [docs/configuration.md#programmatic-usage](docs/configuration.md#programmatic-usage)
|
|
278
|
+
|
|
562
279
|
---
|
|
563
280
|
|
|
564
281
|
## Performance Optimizations (v0.3)
|
|
@@ -569,36 +286,11 @@ console.log(decision);
|
|
|
569
286
|
|
|
570
287
|
---
|
|
571
288
|
|
|
572
|
-
## Cost Tracking
|
|
289
|
+
## Cost Tracking
|
|
573
290
|
|
|
574
|
-
Track your savings in
|
|
291
|
+
Track your savings with `/stats` in any OpenClaw conversation.
|
|
575
292
|
|
|
576
|
-
|
|
577
|
-
# In any OpenClaw conversation
|
|
578
|
-
/stats
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
Output:
|
|
582
|
-
|
|
583
|
-
```
|
|
584
|
-
╔════════════════════════════════════════════════════════════╗
|
|
585
|
-
║ ClawRouter Usage Statistics ║
|
|
586
|
-
╠════════════════════════════════════════════════════════════╣
|
|
587
|
-
║ Period: last 7 days ║
|
|
588
|
-
║ Total Requests: 442 ║
|
|
589
|
-
║ Total Cost: $1.73 ║
|
|
590
|
-
║ Baseline Cost (Opus): $20.13 ║
|
|
591
|
-
║ 💰 Total Saved: $18.40 (91.4%) ║
|
|
592
|
-
╠════════════════════════════════════════════════════════════╣
|
|
593
|
-
║ Routing by Tier: ║
|
|
594
|
-
║ SIMPLE ███████████ 55.0% (243) ║
|
|
595
|
-
║ MEDIUM ██████ 30.8% (136) ║
|
|
596
|
-
║ COMPLEX █ 7.2% (32) ║
|
|
597
|
-
║ REASONING █ 7.0% (31) ║
|
|
598
|
-
╚════════════════════════════════════════════════════════════╝
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
Stats are stored locally at `~/.openclaw/blockrun/logs/` and aggregated on demand.
|
|
293
|
+
**Full details:** [docs/features.md#cost-tracking-with-stats](docs/features.md#cost-tracking-with-stats)
|
|
602
294
|
|
|
603
295
|
---
|
|
604
296
|
|
|
@@ -619,121 +311,17 @@ Agents shouldn't need a human to paste API keys. They should generate a wallet,
|
|
|
619
311
|
|
|
620
312
|
## Troubleshooting
|
|
621
313
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
### Quick Checklist
|
|
314
|
+
Quick checklist:
|
|
625
315
|
|
|
626
316
|
```bash
|
|
627
|
-
#
|
|
317
|
+
# Check version (should be 0.5.7+)
|
|
628
318
|
cat ~/.openclaw/extensions/clawrouter/package.json | grep version
|
|
629
319
|
|
|
630
|
-
#
|
|
320
|
+
# Check proxy running
|
|
631
321
|
curl http://localhost:8402/health
|
|
632
|
-
|
|
633
|
-
# 3. Watch routing in action
|
|
634
|
-
openclaw logs --follow
|
|
635
|
-
# Should see: gemini-2.5-flash $0.0012 (saved 99%)
|
|
636
|
-
|
|
637
|
-
# 4. View cost savings
|
|
638
|
-
/stats
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
### "Unknown model: blockrun/auto" or "Unknown model: auto"
|
|
642
|
-
|
|
643
|
-
Plugin isn't loaded or outdated. **Don't change the model name** — `blockrun/auto` is correct.
|
|
644
|
-
|
|
645
|
-
**Fix:** Update to v0.3.21+ which handles both `blockrun/auto` and `auto` (OpenClaw strips provider prefix). See [How to Update ClawRouter](#how-to-update-clawrouter).
|
|
646
|
-
|
|
647
|
-
### "No API key found for provider blockrun"
|
|
648
|
-
|
|
649
|
-
Auth profile is missing or wasn't created properly.
|
|
650
|
-
|
|
651
|
-
**Fix:** See [How to Update ClawRouter](#how-to-update-clawrouter) — the reinstall script automatically injects the auth profile.
|
|
652
|
-
|
|
653
|
-
### "Config validation failed: plugin not found: clawrouter"
|
|
654
|
-
|
|
655
|
-
Plugin directory was removed but config still references it. This blocks all OpenClaw commands until fixed.
|
|
656
|
-
|
|
657
|
-
**Fix:** See [How to Update ClawRouter](#how-to-update-clawrouter) for complete cleanup steps.
|
|
658
|
-
|
|
659
|
-
### "No USDC balance" / "Insufficient funds"
|
|
660
|
-
|
|
661
|
-
Wallet needs funding.
|
|
662
|
-
|
|
663
|
-
**Fix:**
|
|
664
|
-
|
|
665
|
-
1. Find your wallet address (printed during install)
|
|
666
|
-
2. Send USDC on **Base network** to that address
|
|
667
|
-
3. $1-5 is enough for hundreds of requests
|
|
668
|
-
4. Restart OpenClaw
|
|
669
|
-
|
|
670
|
-
### "WARNING: dangerous code patterns — possible credential harvesting"
|
|
671
|
-
|
|
672
|
-
This is a **false positive**. ClawRouter legitimately:
|
|
673
|
-
|
|
674
|
-
1. Reads `BLOCKRUN_WALLET_KEY` from environment (for authentication)
|
|
675
|
-
2. Sends authenticated requests to BlockRun API (for x402 micropayments)
|
|
676
|
-
|
|
677
|
-
This pattern triggers OpenClaw's security scanner, but it's the intended behavior — the wallet key is required to sign payment transactions. The code is fully open source and auditable.
|
|
678
|
-
|
|
679
|
-
### Security Scanner Warning: "env-harvesting"
|
|
680
|
-
|
|
681
|
-
OpenClaw's security scanner may flag ClawRouter with:
|
|
682
|
-
|
|
683
|
-
```
|
|
684
|
-
[env-harvesting] Environment variable access combined with network send
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
**This is a false positive.** ClawRouter reads `BLOCKRUN_WALLET_KEY` to sign x402 payment transactions — this is required and intentional:
|
|
688
|
-
|
|
689
|
-
- The wallet key is used **locally** for cryptographic signing (EIP-712)
|
|
690
|
-
- The **signature** is transmitted, not the private key itself
|
|
691
|
-
- This is standard x402 payment protocol behavior
|
|
692
|
-
- Source code is [MIT licensed and fully auditable](https://github.com/BlockRunAI/ClawRouter)
|
|
693
|
-
|
|
694
|
-
See [`openclaw.security.json`](openclaw.security.json) for detailed security documentation.
|
|
695
|
-
|
|
696
|
-
### Port 8402 already in use
|
|
697
|
-
|
|
698
|
-
As of v0.4.1, ClawRouter automatically detects and reuses an existing proxy on the configured port instead of failing with `EADDRINUSE`. You should no longer see this error.
|
|
699
|
-
|
|
700
|
-
If you need to use a different port:
|
|
701
|
-
|
|
702
|
-
```bash
|
|
703
|
-
# Set custom port via environment variable
|
|
704
|
-
export BLOCKRUN_PROXY_PORT=8403
|
|
705
|
-
openclaw gateway restart
|
|
706
322
|
```
|
|
707
323
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
```bash
|
|
711
|
-
lsof -i :8402
|
|
712
|
-
# Kill the process or restart OpenClaw
|
|
713
|
-
```
|
|
714
|
-
|
|
715
|
-
### How to Update ClawRouter
|
|
716
|
-
|
|
717
|
-
```bash
|
|
718
|
-
curl -fsSL https://raw.githubusercontent.com/BlockRunAI/ClawRouter/main/scripts/reinstall.sh | bash
|
|
719
|
-
openclaw gateway restart
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
This removes the old version, installs the latest, and restarts the gateway.
|
|
723
|
-
|
|
724
|
-
### Verify Routing is Working
|
|
725
|
-
|
|
726
|
-
```bash
|
|
727
|
-
openclaw logs --follow
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
You should see model selection for each request:
|
|
731
|
-
|
|
732
|
-
```
|
|
733
|
-
[plugins] [SIMPLE] google/gemini-2.5-flash $0.0012 (saved 99%)
|
|
734
|
-
[plugins] [MEDIUM] deepseek/deepseek-chat $0.0003 (saved 99%)
|
|
735
|
-
[plugins] [REASONING] deepseek/deepseek-reasoner $0.0005 (saved 99%)
|
|
736
|
-
```
|
|
324
|
+
**Full guide:** [docs/troubleshooting.md](docs/troubleshooting.md)
|
|
737
325
|
|
|
738
326
|
---
|
|
739
327
|
|
|
@@ -765,7 +353,7 @@ BLOCKRUN_WALLET_KEY=0x... npx tsx test-e2e.ts
|
|
|
765
353
|
- [x] Session persistence — pin model for multi-turn conversations
|
|
766
354
|
- [x] Cost tracking — /stats command with savings dashboard
|
|
767
355
|
- [x] Model aliases — `/model free`, `/model sonnet`, `/model grok`, etc.
|
|
768
|
-
- [x] Free tier —
|
|
356
|
+
- [x] Free tier — gpt-oss-120b for $0 when wallet is empty
|
|
769
357
|
- [ ] Cascade routing — try cheap model first, escalate on low quality
|
|
770
358
|
- [ ] Spend controls — daily/monthly budgets
|
|
771
359
|
- [ ] Remote analytics — cost tracking at blockrun.ai
|