@blockrun/llm 3.20.0 → 3.21.0
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 +35 -10
- package/dist/index.cjs +366 -106
- package/dist/index.d.cts +75 -21
- package/dist/index.d.ts +75 -21
- package/dist/index.js +363 -103
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Cut your LLM bill by <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->%. One line of TypeScript.
|
|
6
6
|
|
|
7
|
-
The smart-routing SDK for <!-- br:models.chatVisible -->
|
|
7
|
+
The smart-routing SDK for <!-- br:models.chatVisible -->86<!-- /br:models.chatVisible --> models — every request goes to the cheapest model that can handle it,
|
|
8
8
|
paid with an API key or per-request USDC on Solana or Base. No vendor lock-in.
|
|
9
9
|
|
|
10
10
|
[](https://www.npmjs.com/package/@blockrun/llm)
|
|
@@ -44,7 +44,7 @@ console.log(r.response); // the proof
|
|
|
44
44
|
## Why This SDK
|
|
45
45
|
|
|
46
46
|
- 🧠 **Smart routing that pays for itself** — the bundled [Router Core V3](https://github.com/BlockRunAI/router-core) engine (shared with [ClawRouter](https://github.com/BlockRunAI/ClawRouter)) classifies every request locally in <1ms across <!-- br:clawrouter.dimensions -->15<!-- /br:clawrouter.dimensions --> dimensions and routes to the cheapest capable model. The main event.
|
|
47
|
-
- 🆓 **<!-- br:models.free -->
|
|
47
|
+
- 🆓 **<!-- br:models.free -->7<!-- /br:models.free --> genuinely free models** — $0 in and out, incl. two 1M-context Nemotrons, a multimodal one, and free coding models from Cohere and Poolside. No rate-limit gimmicks.
|
|
48
48
|
- 🔐 **Two ways to connect** — a **BlockRun API key** billed against account credit ([sign up at user.blockrun.ai](https://user.blockrun.ai), [create a key](https://user.blockrun.ai/dashboard/keys), [add credit](https://user.blockrun.ai/dashboard/credits)), or a wallet signature with x402 micropayments and no account at all. Same code either way.
|
|
49
49
|
- 💸 **Pay per request in USDC** — x402 micropayments on Solana or Base. $5 covers thousands of requests; agents can pay their own way.
|
|
50
50
|
- 🛡️ **Automatic failover** — transient errors (timeouts, 429, 5xx) before payment walk the router's ranked fallback chain instead of failing your request; a failure after a payment was sent never buys a second model.
|
|
@@ -56,8 +56,8 @@ console.log(r.response); // the proof
|
|
|
56
56
|
| | OpenAI SDK | OpenRouter | LiteLLM | **@blockrun/llm** |
|
|
57
57
|
| ------------------ | -------------- | ----------------- | ---------------- | ----------------------------------------------------------------------- |
|
|
58
58
|
| **Cost routing** | ✗ one vendor | Manual selection | Manual selection | **Automatic — <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% cheaper** |
|
|
59
|
-
| **Models** | GPT only | 200+ | 100+ (BYO keys) | **<!-- br:models.chatVisible -->
|
|
60
|
-
| **Free tier** | ✗ | Rate-limited | ✗ | **<!-- br:models.free -->
|
|
59
|
+
| **Models** | GPT only | 200+ | 100+ (BYO keys) | **<!-- br:models.chatVisible -->86<!-- /br:models.chatVisible -->, one credential** |
|
|
60
|
+
| **Free tier** | ✗ | Rate-limited | ✗ | **<!-- br:models.free -->7<!-- /br:models.free --> models, no signup** |
|
|
61
61
|
| **Auth** | API key | Account + API key | Your API keys | **API key *or* wallet signature** |
|
|
62
62
|
| **Payment** | Card + invoice | Credit card | BYO keys | **Account credit or USDC per-request** |
|
|
63
63
|
| **Agent-ready** | ✗ | ✗ | ✗ | **✓ — one key, or agents fund their own wallet** |
|
|
@@ -318,13 +318,19 @@ a retry disposition, which `retryDisposition(err)` returns:
|
|
|
318
318
|
|
|
319
319
|
- `'unpaid'`: nothing chargeable was sent — the unpaid first request and its
|
|
320
320
|
402 challenge, or signing the payment. A 429, 5xx, timeout or network error
|
|
321
|
-
here moves on to the next model.
|
|
321
|
+
here moves on to the next model. On Solana, a `503
|
|
322
|
+
PAYMENT_VERIFICATION_UNAVAILABLE` in answer to the payment is `'unpaid'`
|
|
323
|
+
too: the gateway sends it only when verification could not run, so nothing
|
|
324
|
+
was settled or broadcast (the batch path already treats it as a refusal).
|
|
325
|
+
This holds on every exact-paid Solana endpoint, not only chat.
|
|
322
326
|
- `'paid-or-in-doubt'`: the signed payment (exact or batch) was sent and may
|
|
323
327
|
have been charged — a timeout, abort or network error after sending it, any
|
|
324
328
|
error status in answer to it, or a 2xx whose body could not be read. The
|
|
325
329
|
error propagates; no other model is bought for the call. With an API key
|
|
326
|
-
the request itself is billed, so only the account API's explicit
|
|
327
|
-
|
|
330
|
+
the request itself is billed, so only the account API's explicit answers
|
|
331
|
+
are `'unpaid'`: a 4xx (such as a 429), or a 5xx carrying its JSON error
|
|
332
|
+
envelope (api.blockrun.ai debits only an accepted 2xx). An HTML or empty
|
|
333
|
+
5xx from a proxy, or a timeout, is not.
|
|
328
334
|
|
|
329
335
|
An error without a disposition counts as `'paid-or-in-doubt'`. Use the same
|
|
330
336
|
check in your own retry wrapper:
|
|
@@ -353,7 +359,7 @@ const reply = await client.chat('nvidia/nemotron-3.5-lightning', 'hello', {
|
|
|
353
359
|
|
|
354
360
|
| Profile | Strategy | Savings vs Opus 5 | Best For |
|
|
355
361
|
|---------|----------|-------------------|----------|
|
|
356
|
-
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->
|
|
362
|
+
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->7<!-- /br:models.free -->-model free tier first | **<!-- br:savings.ecoVsBaselinePct -->98<!-- /br:savings.ecoVsBaselinePct -->%** | Cost-sensitive production, zero-cost testing |
|
|
357
363
|
| `auto` | Best balance of cost/quality (default) | **<!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->%** | General use |
|
|
358
364
|
| `premium` | Top-tier models (OpenAI, Anthropic) | 0% | Quality-critical tasks |
|
|
359
365
|
|
|
@@ -484,6 +490,25 @@ const tweet = await client.chat('xai/grok-4.5', 'What is trending on X?', { sear
|
|
|
484
490
|
**Supported endpoint:** `https://sol.blockrun.ai/api`
|
|
485
491
|
**Payment:** Solana USDC (SPL, mainnet)
|
|
486
492
|
|
|
493
|
+
**Images, music and video on Solana:**
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
const image = await client.image('a lighthouse at dusk', { model: 'openai/gpt-image-2' });
|
|
497
|
+
const track = await client.music('chill lo-fi beats with piano');
|
|
498
|
+
const video = await client.video('a red apple slowly spinning', { duration_seconds: 5 });
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Slow jobs answer `202 { id, poll_url }` and the client polls for you. Each poll
|
|
502
|
+
proves the job is yours with a wallet signature (`x-poll-wallet`,
|
|
503
|
+
`x-poll-timestamp`, `x-poll-signature`: ed25519 over
|
|
504
|
+
`blockrun-poll:v1:<kind>:<job id>:<unix seconds>`), not a payment, so a
|
|
505
|
+
multi-minute job no longer signs a Solana transaction every few seconds. Image
|
|
506
|
+
and music are paid when submitted. A video is charged only once it is finished:
|
|
507
|
+
the client signs one payment for the completed job, and a failed job costs
|
|
508
|
+
nothing. If the gateway does not accept the poll signature for a job, the client
|
|
509
|
+
falls back to paying each poll the old way (logged to stderr). Base polling is
|
|
510
|
+
unchanged.
|
|
511
|
+
|
|
487
512
|
### Batch settlement (optional metered billing)
|
|
488
513
|
|
|
489
514
|
By default, every Solana call uses x402 `exact`: one SPL transfer per call,
|
|
@@ -1482,7 +1507,7 @@ const free = await client.chat('nvidia/nemotron-3.5-lightning', 'Hello!');
|
|
|
1482
1507
|
|
|
1483
1508
|
| Profile | Description | Best For |
|
|
1484
1509
|
|---------|-------------|----------|
|
|
1485
|
-
| `eco` | Budget-optimized — ranks the <!-- br:models.free -->
|
|
1510
|
+
| `eco` | Budget-optimized — ranks the <!-- br:models.free -->7<!-- /br:models.free -->-model free tier first | Cost-sensitive workloads, zero-cost testing |
|
|
1486
1511
|
| `auto` | Intelligent routing (default) | General use |
|
|
1487
1512
|
| `premium` | Best quality models | Critical tasks |
|
|
1488
1513
|
|
|
@@ -2081,7 +2106,7 @@ The `AnthropicClient` wraps the official `@anthropic-ai/sdk` with a custom fetch
|
|
|
2081
2106
|
## Frequently Asked Questions
|
|
2082
2107
|
|
|
2083
2108
|
### What is @blockrun/llm?
|
|
2084
|
-
@blockrun/llm is a TypeScript SDK that cuts LLM costs by up to <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% with built-in smart routing: every request is routed to the cheapest of <!-- br:models.chatVisible -->
|
|
2109
|
+
@blockrun/llm is a TypeScript SDK that cuts LLM costs by up to <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% with built-in smart routing: every request is routed to the cheapest of <!-- br:models.chatVisible -->86<!-- /br:models.chatVisible --> models (OpenAI, Anthropic, Google, xAI, DeepSeek, Moonshot, and more) that can handle it, then paid per-request in USDC via the x402 protocol — with API key account billing or x402 wallet payments on Solana or Base.
|
|
2085
2110
|
|
|
2086
2111
|
### How does payment work?
|
|
2087
2112
|
When you make an API call, the SDK automatically handles x402 payment. It signs a USDC transaction locally using your wallet private key (which never leaves your machine), and includes the payment proof in the request header. Settlement is non-custodial and instant on Base or Solana.
|