@blockrun/llm 4.4.0 → 4.5.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 +61 -40
- package/dist/index.cjs +486 -281
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +486 -281
- package/package.json +2 -2
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 -->93<!-- /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, Base or Arc. 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.
|
|
47
|
-
- 🆓 **<!-- br:models.free -->
|
|
47
|
+
- 🆓 **<!-- br:models.free -->8<!-- /br:models.free --> genuinely free models.** $0 in and out, including two 1M-context Nemotrons, two that accept images, a 1M-context MiniMax and a free Poolside coding model.
|
|
48
48
|
- 🔐 **Two ways to connect.** A **BlockRun API key** billed against account credit ([sign up](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, Base or Arc. Agents can fund and 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 -->93<!-- /br:models.chatVisible -->, one credential** |
|
|
60
|
+
| **Free tier** | ✗ | Rate-limited | ✗ | **<!-- br:models.free -->8<!-- /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** |
|
|
@@ -200,7 +200,7 @@ const result = await client.smartChat('Hello!');
|
|
|
200
200
|
console.log(result.model, result.response);
|
|
201
201
|
|
|
202
202
|
// Or pin a model yourself
|
|
203
|
-
const reply = await client.chat('openai/gpt-
|
|
203
|
+
const reply = await client.chat('openai/gpt-6.2-sol', 'Hello!');
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
That's it. The SDK handles the x402 payment, and `smartChat()` keeps the bill
|
|
@@ -269,7 +269,7 @@ const tools: Tool[] = [{
|
|
|
269
269
|
|
|
270
270
|
// 1. smartChat(): one-line routed chat
|
|
271
271
|
const result = await client.smartChat('What is the capital of France?');
|
|
272
|
-
console.log(result.model); // 'google/gemini-
|
|
272
|
+
console.log(result.model); // 'google/gemini-3.5-flash-lite'
|
|
273
273
|
console.log(`Saved ${(result.routing.savings * 100).toFixed(0)}%`); // 'Saved 90%': this request vs the baseline
|
|
274
274
|
|
|
275
275
|
// 2. smartChatCompletion(): full agent / tool conversations, routed
|
|
@@ -280,11 +280,11 @@ const reply = await client.chatCompletion('blockrun/auto', messages);
|
|
|
280
280
|
|
|
281
281
|
// Inspect a decision without paying for anything
|
|
282
282
|
const decision = await client.route('Prove the Riemann hypothesis step by step');
|
|
283
|
-
console.log(decision.model); // '
|
|
283
|
+
console.log(decision.model); // 'google/gemini-3.6-flash'
|
|
284
284
|
console.log(decision.method); // 'portfolio'
|
|
285
285
|
console.log(decision.taskType); // 'reasoning'
|
|
286
286
|
console.log(decision.candidates); // ranked, capability-eligible models
|
|
287
|
-
console.log(decision.fallbacks); // ['
|
|
287
|
+
console.log(decision.fallbacks); // ['deepseek/deepseek-v4-pro', 'deepseek/deepseek-reasoner', 'xai/grok-4.3', ...]
|
|
288
288
|
```
|
|
289
289
|
|
|
290
290
|
The aliases are resolved locally by `chat()` and `chatCompletion()` on both
|
|
@@ -353,7 +353,7 @@ const reply = await client.chat('nvidia/nemotron-3.5-lightning', 'hello', {
|
|
|
353
353
|
|
|
354
354
|
| Profile | Strategy | Savings vs Opus 5 | Best For |
|
|
355
355
|
|---------|----------|-------------------|----------|
|
|
356
|
-
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->
|
|
356
|
+
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->8<!-- /br:models.free -->-model free tier first | **<!-- br:savings.ecoVsBaselinePct -->98<!-- /br:savings.ecoVsBaselinePct -->%** | Cost-sensitive production, zero-cost testing |
|
|
357
357
|
| `auto` | Best balance of cost and quality (default) | **<!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->%** | General use |
|
|
358
358
|
| `premium` | Highest-quality model per tier | 0% | Quality-critical tasks |
|
|
359
359
|
|
|
@@ -406,9 +406,9 @@ anchors the portfolio's candidate pool):
|
|
|
406
406
|
|
|
407
407
|
| Tier | Example Tasks | ECO | AUTO | PREMIUM |
|
|
408
408
|
|------|---------------|-----|------|---------|
|
|
409
|
-
| SIMPLE | "What is the capital of France?", definitions | nemotron-3.5-lightning (**FREE**) | gemini-
|
|
410
|
-
| MEDIUM | Code snippets, explanations | glm-5.3-flash | gemini-3.
|
|
411
|
-
| COMPLEX | Architecture, long documents | glm-5.3-flash | gemini-3.1-pro | claude-
|
|
409
|
+
| SIMPLE | "What is the capital of France?", definitions | nemotron-3.5-lightning (**FREE**) | gemini-3.5-flash-lite | gemini-3.6-flash |
|
|
410
|
+
| MEDIUM | Code snippets, explanations | glm-5.3-flash | gemini-3.6-flash | gpt-5.3-codex |
|
|
411
|
+
| COMPLEX | Architecture, long documents | glm-5.3-flash | gemini-3.1-pro | claude-opus-5.5 |
|
|
412
412
|
| REASONING | Proofs, multi-step reasoning | deepseek-reasoner | deepseek-reasoner | claude-sonnet-5 |
|
|
413
413
|
|
|
414
414
|
This table mirrors the pinned router-core `DEFAULT_ROUTING_CONFIG`;
|
|
@@ -640,7 +640,7 @@ console.log(routed.model, routed.response);
|
|
|
640
640
|
const response = await client.chat('deepseek/deepseek-chat', 'gm Solana');
|
|
641
641
|
|
|
642
642
|
// Live Search with Grok
|
|
643
|
-
const trending = await client.chat('xai/grok-4.
|
|
643
|
+
const trending = await client.chat('xai/grok-4.7', 'What is trending on X?', { search: true });
|
|
644
644
|
|
|
645
645
|
// xAI x_search on chosen accounts, structured output, real cost per call
|
|
646
646
|
const res = await client.chatCompletion('xai/grok-4.3', [
|
|
@@ -736,7 +736,7 @@ const client = new SolanaLLMClient({
|
|
|
736
736
|
await client.smartChat('gm');
|
|
737
737
|
|
|
738
738
|
// Later calls are metered: you pay for the tokens the call actually used.
|
|
739
|
-
const reply = await client.chat('anthropic/claude-sonnet-
|
|
739
|
+
const reply = await client.chat('anthropic/claude-sonnet-5.5', 'Summarize x402 in one line', {
|
|
740
740
|
maxTokens: 2048, // a ceiling, not a price
|
|
741
741
|
});
|
|
742
742
|
|
|
@@ -769,7 +769,7 @@ import { LLMClient } from '@blockrun/llm';
|
|
|
769
769
|
const client = new LLMClient({ apiUrl: 'https://arc.blockrun.ai/api' });
|
|
770
770
|
|
|
771
771
|
const routed = await client.smartChat('gm Arc');
|
|
772
|
-
const response = await client.chat('openai/gpt-
|
|
772
|
+
const response = await client.chat('openai/gpt-6.1-sol', 'gm Arc');
|
|
773
773
|
```
|
|
774
774
|
|
|
775
775
|
The 402 from that host names `eip155:5042`, and the SDK signs the EIP-3009 authorization against Arc's USDC (`0x3600…0000`, EIP-712 domain `USDC` v2), never Base's. Circle's facilitator verifies and settles it on Arc; you pay no gas. Which networks the SDK can sign for is the exported `EVM_NETWORKS` table (Base, Arc, Base Sepolia); a 402 naming any other network, or a non-USDC asset, is refused before anything is signed.
|
|
@@ -861,7 +861,7 @@ const messages: ChatMessage[] = [
|
|
|
861
861
|
{ role: 'user', content: 'Explain quantum computing in simple terms' },
|
|
862
862
|
];
|
|
863
863
|
|
|
864
|
-
const response = await client.chatCompletionStream('google/gemini-
|
|
864
|
+
const response = await client.chatCompletionStream('google/gemini-3.5-flash-lite', messages);
|
|
865
865
|
|
|
866
866
|
const reader = response.body!.getReader();
|
|
867
867
|
const decoder = new TextDecoder();
|
|
@@ -960,19 +960,23 @@ gateway's health check holds it back; it stays on the free tier.
|
|
|
960
960
|
`nemotron-3.5-bolt` for free image input.
|
|
961
961
|
|
|
962
962
|
<details>
|
|
963
|
-
<summary><strong>Paid chat models</strong> — OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot, MiniMax, Z.ai, Qwen, Mistral, Tencent, Poolside, Xiaomi</summary>
|
|
963
|
+
<summary><strong>Paid chat models</strong> — OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot, MiniMax, Z.ai, Qwen, Mistral, Tencent, Poolside, Xiaomi, Meta, Reflection</summary>
|
|
964
964
|
|
|
965
965
|
### OpenAI
|
|
966
966
|
|
|
967
967
|
GPT-6: Astra is the flagship for long-horizon agentic work and computer use,
|
|
968
968
|
Sol the cost-efficient tier for complex coding, Luna the fast low-cost tier.
|
|
969
|
+
GPT-6.2 refreshes Astra and Sol at the same tiers.
|
|
969
970
|
GPT-5.6: three tiers on one base (Sol deepest reasoning, Terra balanced, Luna
|
|
970
971
|
cheap and fast), each with a `-pro` sibling that thinks longer at the same
|
|
971
972
|
token price.
|
|
972
973
|
|
|
973
974
|
| Model | Context | Notes |
|
|
974
975
|
|---|---|---|
|
|
976
|
+
| `openai/gpt-6.2-astra` | 1.05M | GPT-6.2 flagship for the hardest long-horizon work |
|
|
977
|
+
| `openai/gpt-6.2-sol` | 1.05M | Everyday GPT-6.2 for coding and agents at scale |
|
|
975
978
|
| `openai/gpt-6.1-sol` | 1.05M | |
|
|
979
|
+
| `openai/gpt-6.1-terra` | 1.05M | Cost-efficient GPT-6.1 for coding and agents, at half 6.1 Sol's rate |
|
|
976
980
|
| `openai/gpt-6-astra` | 1.05M | GPT-6 flagship |
|
|
977
981
|
| `openai/gpt-6-sol` | 1.05M | |
|
|
978
982
|
| `openai/gpt-6-luna` | 1.05M | |
|
|
@@ -993,15 +997,15 @@ token price.
|
|
|
993
997
|
| `openai/gpt-5.2` | 400K | |
|
|
994
998
|
| `openai/gpt-5.2-pro` | 400K | |
|
|
995
999
|
| `openai/gpt-5.1` | 400K | Configurable reasoning effort |
|
|
996
|
-
| `openai/gpt-5-mini` | 200K |
|
|
1000
|
+
| `openai/gpt-5-mini` | 200K | Retires 2026-12-11; the gateway will redirect it to `openai/gpt-5.6-luna` |
|
|
997
1001
|
| `openai/gpt-4.1` | 128K | |
|
|
998
1002
|
| `openai/gpt-4.1-mini` | 128K | |
|
|
999
1003
|
| `openai/gpt-4o` | 128K | |
|
|
1000
1004
|
| `openai/gpt-4o-mini` | 128K | |
|
|
1001
|
-
| `openai/
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
+
| `openai/o3` | 200K | Reasoning. Retires 2026-12-11; the gateway will redirect it to `openai/gpt-5.4-mini` |
|
|
1006
|
+
|
|
1007
|
+
`openai/o1`, `o1-mini`, `o3-mini` and `o4-mini` have left the catalog. They
|
|
1008
|
+
stay callable: the gateway redirects them to `openai/gpt-5.4-mini`.
|
|
1005
1009
|
|
|
1006
1010
|
### Anthropic Claude
|
|
1007
1011
|
|
|
@@ -1023,20 +1027,25 @@ token price.
|
|
|
1023
1027
|
|
|
1024
1028
|
### Google Gemini
|
|
1025
1029
|
|
|
1026
|
-
| Model | Context |
|
|
1027
|
-
|
|
1028
|
-
| `google/gemini-4-
|
|
1029
|
-
| `google/gemini-4-
|
|
1030
|
-
| `google/gemini-
|
|
1031
|
-
| `google/gemini-
|
|
1032
|
-
| `google/gemini-3.
|
|
1033
|
-
| `google/gemini-3.
|
|
1034
|
-
| `google/gemini-3-flash
|
|
1035
|
-
| `google/gemini-3
|
|
1036
|
-
| `google/gemini-3.
|
|
1037
|
-
| `google/gemini-
|
|
1038
|
-
| `google/gemini-2.5-
|
|
1039
|
-
| `google/gemini-2.5-flash
|
|
1030
|
+
| Model | Context | Notes |
|
|
1031
|
+
|---|---|---|
|
|
1032
|
+
| `google/gemini-4-neon` | 1M | Newest Gemini 4 — agentic coding and knowledge work |
|
|
1033
|
+
| `google/gemini-4-carbon` | 1M | |
|
|
1034
|
+
| `google/gemini-4-argon` | 1M | |
|
|
1035
|
+
| `google/gemini-4-hydrogen` | 1M | Fast, efficient Gemini 4 for everyday coding and agents |
|
|
1036
|
+
| `google/gemini-3.1-pro` | 1M | |
|
|
1037
|
+
| `google/gemini-3.8-flash` | 1M | |
|
|
1038
|
+
| `google/gemini-3.6-flash` | 1M | |
|
|
1039
|
+
| `google/gemini-3-flash-preview` | 1M | |
|
|
1040
|
+
| `google/gemini-3.5-flash-lite` | 1M | |
|
|
1041
|
+
| `google/gemini-3.1-flash-lite` | 1M | |
|
|
1042
|
+
| `google/gemini-2.5-pro` | 1M | Retires 2026-12-01; the gateway will redirect it to `google/gemini-3.8-flash` |
|
|
1043
|
+
| `google/gemini-2.5-flash` | 1M | Retires 2026-12-01; the gateway will redirect it to `google/gemini-3.5-flash-lite` |
|
|
1044
|
+
| `google/gemini-2.5-flash-lite` | 1M | |
|
|
1045
|
+
|
|
1046
|
+
`google/gemini-3.5-flash` has left the catalog. It stays callable: Google now
|
|
1047
|
+
serves Gemini 3.6 Flash under that name, so the gateway redirects it to
|
|
1048
|
+
`google/gemini-3.6-flash`.
|
|
1040
1049
|
|
|
1041
1050
|
### DeepSeek
|
|
1042
1051
|
|
|
@@ -1091,7 +1100,7 @@ callable — the gateway redirects them to a healthy model.
|
|
|
1091
1100
|
|---|---|---|
|
|
1092
1101
|
| `mistral/mistral-large-4` | 512K | Reasoning + vision, 256K output |
|
|
1093
1102
|
| `tencent/hy4-preview` | 1M | Preview |
|
|
1094
|
-
| `poolside/laguna-s-2.1` | 1M | Paid coding model (sibling of the free XS) |
|
|
1103
|
+
| `poolside/laguna-s-2.1` | 1M | Paid coding model (sibling of the free XS). Not for tool calls: the 2026-11-28 tool probe got a 500 after payment, so smart routing never sends it a tool-calling turn. Plain chat works |
|
|
1095
1104
|
|
|
1096
1105
|
### Xiaomi
|
|
1097
1106
|
|
|
@@ -1100,6 +1109,18 @@ callable — the gateway redirects them to a healthy model.
|
|
|
1100
1109
|
| `xiaomi/mimo-v2.5` | 1M |
|
|
1101
1110
|
| `xiaomi/mimo-v2.5-pro` | 1M |
|
|
1102
1111
|
|
|
1112
|
+
### Listed on Solana only
|
|
1113
|
+
|
|
1114
|
+
These are in the Solana catalog
|
|
1115
|
+
([sol.blockrun.ai](https://sol.blockrun.ai/api/v1/models)) but not the Base
|
|
1116
|
+
one; call them with `SolanaLLMClient`.
|
|
1117
|
+
|
|
1118
|
+
| Model | Context | Notes |
|
|
1119
|
+
|---|---|---|
|
|
1120
|
+
| `meta/muse-wonder-1.0` | 1M | Meta's frontier model (preview), image + text input, always reasons |
|
|
1121
|
+
| `meta/muse-spark-1.3` | 1M | Meta's current general model, image + text input, always reasons |
|
|
1122
|
+
| `reflection/beam-1.0-501b-a23b` | 1M | Open-weight 501B MoE reasoning model for coding and long-horizon agents |
|
|
1123
|
+
|
|
1103
1124
|
### Testnet Models (Base Sepolia)
|
|
1104
1125
|
|
|
1105
1126
|
| Model |
|
|
@@ -1659,7 +1680,7 @@ import { AnthropicClient } from '@blockrun/llm';
|
|
|
1659
1680
|
const client = new AnthropicClient();
|
|
1660
1681
|
|
|
1661
1682
|
const response = await client.messages.create({
|
|
1662
|
-
model: 'claude-sonnet-
|
|
1683
|
+
model: 'claude-sonnet-5-5',
|
|
1663
1684
|
max_tokens: 1024,
|
|
1664
1685
|
messages: [{ role: 'user', content: 'Hello!' }],
|
|
1665
1686
|
});
|
|
@@ -1667,7 +1688,7 @@ console.log(response.content[0]);
|
|
|
1667
1688
|
|
|
1668
1689
|
// Any model works in Anthropic format
|
|
1669
1690
|
const gptResponse = await client.messages.create({
|
|
1670
|
-
model: 'openai/gpt-
|
|
1691
|
+
model: 'openai/gpt-6.2-sol',
|
|
1671
1692
|
max_tokens: 1024,
|
|
1672
1693
|
messages: [{ role: 'user', content: 'Hello from GPT!' }],
|
|
1673
1694
|
});
|
|
@@ -1912,7 +1933,7 @@ to pick up security fixes.
|
|
|
1912
1933
|
## Frequently Asked Questions
|
|
1913
1934
|
|
|
1914
1935
|
### What is @blockrun/llm?
|
|
1915
|
-
A TypeScript SDK that cuts LLM costs by <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% on a realistic workload with built-in smart routing: every request goes to the cheapest of <!-- br:models.chatVisible -->
|
|
1936
|
+
A TypeScript SDK that cuts LLM costs by <!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->% on a realistic workload with built-in smart routing: every request goes to the cheapest of <!-- br:models.chatVisible -->93<!-- /br:models.chatVisible --> models (OpenAI, Anthropic, Google, xAI, DeepSeek, Moonshot, and more) that can handle it, paid with an account API key or per-request USDC via x402 on Solana, Base or Arc.
|
|
1916
1937
|
|
|
1917
1938
|
### What is smart routing?
|
|
1918
1939
|
Router Core V3, bundled into the SDK: the same deterministic engine that powers ClawRouter. It analyzes each request across <!-- br:clawrouter.dimensions -->15<!-- /br:clawrouter.dimensions --> dimensions locally, in under 1ms, and picks the cheapest capable model. Use `smartChat()`, `smartChatCompletion()`, or the `blockrun/auto` model alias. See [Smart Routing](#smart-routing-router-core-v3).
|