@blockrun/llm 3.20.1 → 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 +26 -7
- package/dist/index.cjs +350 -101
- package/dist/index.d.cts +75 -21
- package/dist/index.d.ts +75 -21
- package/dist/index.js +347 -98
- 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** |
|
|
@@ -359,7 +359,7 @@ const reply = await client.chat('nvidia/nemotron-3.5-lightning', 'hello', {
|
|
|
359
359
|
|
|
360
360
|
| Profile | Strategy | Savings vs Opus 5 | Best For |
|
|
361
361
|
|---------|----------|-------------------|----------|
|
|
362
|
-
| `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 |
|
|
363
363
|
| `auto` | Best balance of cost/quality (default) | **<!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->%** | General use |
|
|
364
364
|
| `premium` | Top-tier models (OpenAI, Anthropic) | 0% | Quality-critical tasks |
|
|
365
365
|
|
|
@@ -490,6 +490,25 @@ const tweet = await client.chat('xai/grok-4.5', 'What is trending on X?', { sear
|
|
|
490
490
|
**Supported endpoint:** `https://sol.blockrun.ai/api`
|
|
491
491
|
**Payment:** Solana USDC (SPL, mainnet)
|
|
492
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
|
+
|
|
493
512
|
### Batch settlement (optional metered billing)
|
|
494
513
|
|
|
495
514
|
By default, every Solana call uses x402 `exact`: one SPL transfer per call,
|
|
@@ -1488,7 +1507,7 @@ const free = await client.chat('nvidia/nemotron-3.5-lightning', 'Hello!');
|
|
|
1488
1507
|
|
|
1489
1508
|
| Profile | Description | Best For |
|
|
1490
1509
|
|---------|-------------|----------|
|
|
1491
|
-
| `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 |
|
|
1492
1511
|
| `auto` | Intelligent routing (default) | General use |
|
|
1493
1512
|
| `premium` | Best quality models | Critical tasks |
|
|
1494
1513
|
|
|
@@ -2087,7 +2106,7 @@ The `AnthropicClient` wraps the official `@anthropic-ai/sdk` with a custom fetch
|
|
|
2087
2106
|
## Frequently Asked Questions
|
|
2088
2107
|
|
|
2089
2108
|
### What is @blockrun/llm?
|
|
2090
|
-
@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.
|
|
2091
2110
|
|
|
2092
2111
|
### How does payment work?
|
|
2093
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.
|