@blockrun/llm 4.3.0 → 4.3.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 +21 -5
- package/dist/index.cjs +17 -2
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +17 -2
- 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 -->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)
|
|
@@ -56,7 +56,7 @@ 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 -->
|
|
59
|
+
| **Models** | GPT only | 200+ | 100+ (BYO keys) | **<!-- br:models.chatVisible -->93<!-- /br:models.chatVisible -->, one credential** |
|
|
60
60
|
| **Free tier** | ✗ | Rate-limited | ✗ | **<!-- br:models.free -->9<!-- /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** |
|
|
@@ -1405,11 +1405,15 @@ const { answers, costUsd } = await client.decisions({
|
|
|
1405
1405
|
{ type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
1406
1406
|
{
|
|
1407
1407
|
type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
1408
|
-
choices: [
|
|
1408
|
+
choices: [
|
|
1409
|
+
{ value: 'billing', description: 'payments and refunds' },
|
|
1410
|
+
{ value: 'shipping', description: 'delivery' },
|
|
1411
|
+
{ value: 'none', description: 'fits no team' },
|
|
1412
|
+
],
|
|
1409
1413
|
},
|
|
1410
1414
|
{
|
|
1411
1415
|
type: 'score', name: 'anger', instructions: 'How upset is the writer?',
|
|
1412
|
-
levels: [{ label: 'calm' }, { label: 'annoyed' }, { label: 'furious' }], // lowest first
|
|
1416
|
+
levels: [{ label: 'calm', description: '' }, { label: 'annoyed', description: '' }, { label: 'furious', description: '' }], // lowest first
|
|
1413
1417
|
},
|
|
1414
1418
|
],
|
|
1415
1419
|
});
|
|
@@ -1418,6 +1422,12 @@ const { answers, costUsd } = await client.decisions({
|
|
|
1418
1422
|
// { type: 'score', name: 'anger', score: 1, probabilities: [...], confidence: 1 }]
|
|
1419
1423
|
```
|
|
1420
1424
|
|
|
1425
|
+
A `score` answer is the probability-weighted position on the rubric (0 = the
|
|
1426
|
+
first level), so it can be fractional: Gemini answered this example with 1.43
|
|
1427
|
+
(2% calm, 53% annoyed, 45% furious) where luna, all on "annoyed", gave 1. For a
|
|
1428
|
+
single level, take the entry in `probabilities` with the highest probability,
|
|
1429
|
+
or round.
|
|
1430
|
+
|
|
1421
1431
|
Only input tokens are billed. A wallet call pays the 402's quote: an
|
|
1422
1432
|
upper-bound estimate of the input tokens plus the $0.001 transaction fee. Under
|
|
1423
1433
|
Solana [batch settlement](#batch-settlement-optional-metered-billing) it pays
|
|
@@ -1432,6 +1442,12 @@ refuses an over-limit request with a 400 before any payment. A `choice` always
|
|
|
1432
1442
|
picks one of your values, so give it a `none` value for inputs that fit
|
|
1433
1443
|
nothing.
|
|
1434
1444
|
|
|
1445
|
+
Pass `model: 'gemini-decision-1'` to use Google's Gemini Decision 1 (same price,
|
|
1446
|
+
up to 1,000 questions). It needs a `description` string on every choice and every
|
|
1447
|
+
score level; an empty string is fine. The SDK throws before sending when one is
|
|
1448
|
+
missing. `gpt-6-luna` accepts descriptions too, so the example above works on
|
|
1449
|
+
both models.
|
|
1450
|
+
|
|
1435
1451
|
### Standalone Search
|
|
1436
1452
|
|
|
1437
1453
|
`SearchClient` wraps `POST /v1/search` — Grok Live Search over `web` and
|
|
@@ -1896,7 +1912,7 @@ to pick up security fixes.
|
|
|
1896
1912
|
## Frequently Asked Questions
|
|
1897
1913
|
|
|
1898
1914
|
### What is @blockrun/llm?
|
|
1899
|
-
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 -->
|
|
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 -->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.
|
|
1900
1916
|
|
|
1901
1917
|
### What is smart routing?
|
|
1902
1918
|
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).
|
package/dist/index.cjs
CHANGED
|
@@ -737,6 +737,10 @@ function withCost(body, response, bookedUsd, scheme) {
|
|
|
737
737
|
// src/decisions.ts
|
|
738
738
|
var DECISIONS_DEFAULT_MODEL = "gpt-6-luna";
|
|
739
739
|
var QUESTION_TYPES = /* @__PURE__ */ new Set(["predicate", "choice", "score"]);
|
|
740
|
+
var GEMINI_DECISIONS_MODEL = "gemini-decision-1";
|
|
741
|
+
function isGemini(model) {
|
|
742
|
+
return typeof model === "string" && model.trim().replace(/^google\//, "") === GEMINI_DECISIONS_MODEL;
|
|
743
|
+
}
|
|
740
744
|
function invalid(message) {
|
|
741
745
|
throw withDisposition(new Error(`decisions: ${message}`), "unpaid");
|
|
742
746
|
}
|
|
@@ -762,6 +766,15 @@ function buildDecisionsBody(request) {
|
|
|
762
766
|
if (q.type === "score" && (!Array.isArray(q.levels) || q.levels.length === 0)) {
|
|
763
767
|
invalid(`questions[${i}] (score) needs a non-empty levels array, lowest first`);
|
|
764
768
|
}
|
|
769
|
+
if (isGemini(request.model) && (q.type === "choice" || q.type === "score")) {
|
|
770
|
+
const key = q.type === "choice" ? "choices" : "levels";
|
|
771
|
+
const items = (q.type === "choice" ? q.choices : q.levels) ?? [];
|
|
772
|
+
items.forEach((item, j) => {
|
|
773
|
+
if (!item || typeof item !== "object" || typeof item.description !== "string") {
|
|
774
|
+
invalid(`questions[${i}].${key}[${j}].description must be a string for ${GEMINI_DECISIONS_MODEL} (it may be empty: "")`);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}
|
|
765
778
|
});
|
|
766
779
|
return { ...request, model: request.model ?? DECISIONS_DEFAULT_MODEL };
|
|
767
780
|
}
|
|
@@ -5352,7 +5365,7 @@ function getCostSummary() {
|
|
|
5352
5365
|
}
|
|
5353
5366
|
|
|
5354
5367
|
// src/version.ts
|
|
5355
|
-
var SDK_VERSION = "4.3.
|
|
5368
|
+
var SDK_VERSION = "4.3.1";
|
|
5356
5369
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
5357
5370
|
|
|
5358
5371
|
// src/client.ts
|
|
@@ -6591,7 +6604,9 @@ var LLMClient = class _LLMClient {
|
|
|
6591
6604
|
* questions: [
|
|
6592
6605
|
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
6593
6606
|
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
6594
|
-
* choices: [{ value: 'billing'
|
|
6607
|
+
* choices: [{ value: 'billing', description: 'payments and refunds' },
|
|
6608
|
+
* { value: 'shipping', description: 'delivery' },
|
|
6609
|
+
* { value: 'none', description: 'fits no team' }] },
|
|
6595
6610
|
* ],
|
|
6596
6611
|
* });
|
|
6597
6612
|
*/
|
package/dist/index.d.cts
CHANGED
|
@@ -1798,7 +1798,9 @@ declare class LLMClient {
|
|
|
1798
1798
|
* questions: [
|
|
1799
1799
|
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
1800
1800
|
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
1801
|
-
* choices: [{ value: 'billing'
|
|
1801
|
+
* choices: [{ value: 'billing', description: 'payments and refunds' },
|
|
1802
|
+
* { value: 'shipping', description: 'delivery' },
|
|
1803
|
+
* { value: 'none', description: 'fits no team' }] },
|
|
1802
1804
|
* ],
|
|
1803
1805
|
* });
|
|
1804
1806
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1798,7 +1798,9 @@ declare class LLMClient {
|
|
|
1798
1798
|
* questions: [
|
|
1799
1799
|
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
1800
1800
|
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
1801
|
-
* choices: [{ value: 'billing'
|
|
1801
|
+
* choices: [{ value: 'billing', description: 'payments and refunds' },
|
|
1802
|
+
* { value: 'shipping', description: 'delivery' },
|
|
1803
|
+
* { value: 'none', description: 'fits no team' }] },
|
|
1802
1804
|
* ],
|
|
1803
1805
|
* });
|
|
1804
1806
|
*/
|
package/dist/index.js
CHANGED
|
@@ -596,6 +596,10 @@ function withCost(body, response, bookedUsd, scheme) {
|
|
|
596
596
|
// src/decisions.ts
|
|
597
597
|
var DECISIONS_DEFAULT_MODEL = "gpt-6-luna";
|
|
598
598
|
var QUESTION_TYPES = /* @__PURE__ */ new Set(["predicate", "choice", "score"]);
|
|
599
|
+
var GEMINI_DECISIONS_MODEL = "gemini-decision-1";
|
|
600
|
+
function isGemini(model) {
|
|
601
|
+
return typeof model === "string" && model.trim().replace(/^google\//, "") === GEMINI_DECISIONS_MODEL;
|
|
602
|
+
}
|
|
599
603
|
function invalid(message) {
|
|
600
604
|
throw withDisposition(new Error(`decisions: ${message}`), "unpaid");
|
|
601
605
|
}
|
|
@@ -621,6 +625,15 @@ function buildDecisionsBody(request) {
|
|
|
621
625
|
if (q.type === "score" && (!Array.isArray(q.levels) || q.levels.length === 0)) {
|
|
622
626
|
invalid(`questions[${i}] (score) needs a non-empty levels array, lowest first`);
|
|
623
627
|
}
|
|
628
|
+
if (isGemini(request.model) && (q.type === "choice" || q.type === "score")) {
|
|
629
|
+
const key = q.type === "choice" ? "choices" : "levels";
|
|
630
|
+
const items = (q.type === "choice" ? q.choices : q.levels) ?? [];
|
|
631
|
+
items.forEach((item, j) => {
|
|
632
|
+
if (!item || typeof item !== "object" || typeof item.description !== "string") {
|
|
633
|
+
invalid(`questions[${i}].${key}[${j}].description must be a string for ${GEMINI_DECISIONS_MODEL} (it may be empty: "")`);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}
|
|
624
637
|
});
|
|
625
638
|
return { ...request, model: request.model ?? DECISIONS_DEFAULT_MODEL };
|
|
626
639
|
}
|
|
@@ -5211,7 +5224,7 @@ function getCostSummary() {
|
|
|
5211
5224
|
}
|
|
5212
5225
|
|
|
5213
5226
|
// src/version.ts
|
|
5214
|
-
var SDK_VERSION = "4.3.
|
|
5227
|
+
var SDK_VERSION = "4.3.1";
|
|
5215
5228
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
5216
5229
|
|
|
5217
5230
|
// src/client.ts
|
|
@@ -6450,7 +6463,9 @@ var LLMClient = class _LLMClient {
|
|
|
6450
6463
|
* questions: [
|
|
6451
6464
|
* { type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
6452
6465
|
* { type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
6453
|
-
* choices: [{ value: 'billing'
|
|
6466
|
+
* choices: [{ value: 'billing', description: 'payments and refunds' },
|
|
6467
|
+
* { value: 'shipping', description: 'delivery' },
|
|
6468
|
+
* { value: 'none', description: 'fits no team' }] },
|
|
6454
6469
|
* ],
|
|
6455
6470
|
* });
|
|
6456
6471
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockrun/llm",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript SDK for BlockRun - every frontier model behind one OpenAI-compatible client. Pay with a BlockRun API key or per-call in USDC. Smart routing picks the cheapest capable model. No rate limits.",
|
|
6
6
|
"main": "dist/index.cjs",
|