@blockrun/llm 4.2.0 → 4.3.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 +119 -52
- package/dist/index.cjs +173 -10
- package/dist/index.d.cts +220 -2
- package/dist/index.d.ts +220 -2
- package/dist/index.js +170 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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 -->9<!-- /br:models.free --> genuinely free models.** $0 in and out, including two 1M-context Nemotrons, two that accept images,
|
|
47
|
+
- 🆓 **<!-- br:models.free -->9<!-- /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.
|
|
@@ -111,9 +111,11 @@ The Anthropic SDK is a runtime dependency because the public compatibility wrapp
|
|
|
111
111
|
| Try it for $0 | [Try It Free](#try-it-free-no-usdc-required) and [Free Tier](#free-tier) |
|
|
112
112
|
| Understand wallet payments and settlement | [How Payment Works](#how-payment-works) |
|
|
113
113
|
| Pay from a Solana wallet | [Solana Support](#solana-support) |
|
|
114
|
+
| Pay with USDC on Circle's Arc | [Arc Support](#arc-support) |
|
|
114
115
|
| Enable metered batch settlement | [Batch settlement](#batch-settlement-optional-metered-billing) and the [full reference](https://github.com/BlockRunAI/blockrun-llm-ts/blob/main/docs/solana-batch.md) |
|
|
115
116
|
| Stream tokens, use tools | [Chat, Tools and Streaming](#chat-tools-and-streaming) |
|
|
116
117
|
| Generate media or query data services | [Models and Service APIs](#models-and-service-apis) |
|
|
118
|
+
| Get typed yes/no, choice or score answers | [Decisions](#decisions-typed-judgments) |
|
|
117
119
|
| Use the OpenAI or Anthropic SDK surface | [OpenAI and Anthropic Compatibility](#openai-and-anthropic-compatibility) |
|
|
118
120
|
| Create, find or import a wallet | [Wallets](#wallets) |
|
|
119
121
|
| Configure production credentials safely | [Configuration and Environment Variables](#configuration-and-environment-variables) and [Security](#security) |
|
|
@@ -227,7 +229,7 @@ console.log(result.response); // 'The capital of France is Paris.'
|
|
|
227
229
|
console.log(result.routing.savings); // 1 (100%)
|
|
228
230
|
```
|
|
229
231
|
|
|
230
|
-
The
|
|
232
|
+
The free models to pin are listed under [Free Tier](#free-tier). `eco` lands on
|
|
231
233
|
a free model when one can handle the request and moves to the cheapest paid
|
|
232
234
|
model when none can; pin a free id when the call must cost $0.
|
|
233
235
|
|
|
@@ -404,7 +406,7 @@ anchors the portfolio's candidate pool):
|
|
|
404
406
|
|
|
405
407
|
| Tier | Example Tasks | ECO | AUTO | PREMIUM |
|
|
406
408
|
|------|---------------|-----|------|---------|
|
|
407
|
-
| SIMPLE | "What is the capital of France?", definitions | nemotron-3.5-lightning (**FREE**) | gemini-2.5-flash | gemini-
|
|
409
|
+
| SIMPLE | "What is the capital of France?", definitions | nemotron-3.5-lightning (**FREE**) | gemini-2.5-flash | gemini-3.5-flash |
|
|
408
410
|
| MEDIUM | Code snippets, explanations | glm-5.3-flash | gemini-3.5-flash | gpt-5.3-codex |
|
|
409
411
|
| COMPLEX | Architecture, long documents | glm-5.3-flash | gemini-3.1-pro | claude-fable-5 |
|
|
410
412
|
| REASONING | Proofs, multi-step reasoning | deepseek-reasoner | deepseek-reasoner | claude-sonnet-5 |
|
|
@@ -437,7 +439,7 @@ picked:
|
|
|
437
439
|
| `costEstimate` / `baselineCost` | Estimated cost of the pick vs that baseline, in USD |
|
|
438
440
|
| `confidence` | Sigmoid-calibrated classifier confidence, 0–1 |
|
|
439
441
|
| `routerVersion` | `'v3-portfolio'` or `'v2-rules'` |
|
|
440
|
-
| `profile` |
|
|
442
|
+
| `profile` | Tier set the decision used: `'auto'`, `'eco'`, `'premium'`, or `'agentic'` (the router's own set for agentic requests; not a `routingProfile` you can pass) |
|
|
441
443
|
| `reasoning` | Human-readable explanation of the decision |
|
|
442
444
|
| `tierConfigs` | The tier → primary/fallback map the decision was made against |
|
|
443
445
|
|
|
@@ -580,7 +582,27 @@ console.log(`Lifetime: $${summary.totalUsd.toFixed(2)} over ${summary.calls} cal
|
|
|
580
582
|
console.log('By model:', summary.byModel);
|
|
581
583
|
```
|
|
582
584
|
|
|
583
|
-
|
|
585
|
+
#### Per-call cost and timeouts
|
|
586
|
+
|
|
587
|
+
Each paid chat response on `LLMClient` and `SolanaLLMClient` carries what it
|
|
588
|
+
cost. `costUsd` is what the call added to `getSpending()`: the signed price
|
|
589
|
+
under `exact`, the metered `extra.chargedAmount` under Solana batch settlement,
|
|
590
|
+
`0` for a free model; it is undefined in API-key mode (billed to the account).
|
|
591
|
+
`settlement` holds the scheme, the quote and the transaction. When the gateway
|
|
592
|
+
answers a paid request from a free fallback model it skips settlement:
|
|
593
|
+
`costUsd` is `0`, `settlement.skipped` is `"free-fallback"`, and nothing is
|
|
594
|
+
added to `getSpending()`.
|
|
595
|
+
|
|
596
|
+
Both clients default to a 600 s request timeout (`BLOCKRUN_CHAT_TIMEOUT`, in
|
|
597
|
+
seconds, overrides it; the per-call `timeout` option, in ms, overrides both).
|
|
598
|
+
A call aborted after its payment was sent may already have been charged, so it
|
|
599
|
+
is never paid again automatically; under Solana batch settlement it raises
|
|
600
|
+
`BatchPaymentUnresolvedError` (see
|
|
601
|
+
[Batch settlement](#batch-settlement-optional-metered-billing)).
|
|
602
|
+
|
|
603
|
+
#### Cost log and on-chain records
|
|
604
|
+
|
|
605
|
+
Only `LLMClient` wallet settlements (Base / Arc) are appended to
|
|
584
606
|
`~/.blockrun/cost_log.jsonl` automatically. Other clients count their payments
|
|
585
607
|
in their own `getSpending()`. Account usage lives on the
|
|
586
608
|
[Activity](https://user.blockrun.ai/dashboard/activity) page, not in-process.
|
|
@@ -639,22 +661,15 @@ own default applies, and some default to their highest effort (Reflection Beam
|
|
|
639
661
|
defaults to `"max"`); reasoning tokens bill as output:
|
|
640
662
|
|
|
641
663
|
```typescript
|
|
664
|
+
const messages = [{ role: 'user' as const, content: 'Summarize x402 in one line' }];
|
|
642
665
|
const quick = await client.chatCompletion('reflection/beam-1.0-501b-a23b', messages, {
|
|
643
666
|
reasoningEffort: 'low', // none | minimal | low | medium | high | xhigh | max, per model
|
|
644
667
|
maxTokens: 8192, // reasoning counts toward max_tokens
|
|
645
668
|
});
|
|
646
669
|
```
|
|
647
670
|
|
|
648
|
-
`costUsd`, `settlement` and the
|
|
649
|
-
|
|
650
|
-
(`BLOCKRUN_CHAT_TIMEOUT`, in seconds, overrides it; the `timeout` option, in
|
|
651
|
-
ms, overrides both): a call aborted after its payment was sent may already be
|
|
652
|
-
charged, so a batch payment ends unresolved rather than paid again. `costUsd` is what the call added to `getSpending()`: the signed
|
|
653
|
-
price under `exact`, the metered `extra.chargedAmount` under batch settlement,
|
|
654
|
-
`0` for a free model; it is undefined in API-key mode (billed to the account).
|
|
655
|
-
When the gateway answers a paid request from a free fallback model it skips
|
|
656
|
-
settlement: `costUsd` is `0`, `settlement.skipped` is `"free-fallback"`, and
|
|
657
|
-
nothing is added to `getSpending()`.
|
|
671
|
+
`costUsd`, `settlement` and the request timeout work as on `LLMClient`: see
|
|
672
|
+
[Per-call cost and timeouts](#per-call-cost-and-timeouts).
|
|
658
673
|
|
|
659
674
|
**Setup:**
|
|
660
675
|
1. Export your Solana wallet key: `export SOLANA_WALLET_KEY="your-bs58-key"`
|
|
@@ -732,8 +747,9 @@ await client.closeBatchChannel();
|
|
|
732
747
|
- **Explicit trust.** `operators` has no default, and the SDK never learns a trusted key from a 402.
|
|
733
748
|
- **Bounded exposure.** `maxDeposit` caps the escrow deposited and not yet settled on-chain; it is the most the operator could claim without another authorization from you.
|
|
734
749
|
- **Never pays twice.** Anything that goes wrong before a batch payment is sent falls back to `exact`. Once one is sent, a call whose payment may have been charged throws `BatchPaymentUnresolvedError` and is never paid again (no new payment, no `exact`, no fallback model).
|
|
735
|
-
- **Chat, buffered and streamed.** `chat`, `chatCompletion`, `smartChat`, `smartChatCompletion` and `
|
|
750
|
+
- **Chat, buffered and streamed, and Decisions.** `chat`, `chatCompletion`, `smartChat`, `smartChatCompletion`, `stream()` and `decisions()` use batch; media jobs pay `exact`. A stream's receipt arrives as a final SSE event the SDK reads and removes before your loop sees it (it never reaches your chunks), or, for a stream that is cut, from `POST /v1/batch/receipt` afterwards. Its charge is booked in `getSpending()` once that receipt is in, which can be a few seconds after your loop ends: the model may keep generating after a disconnect, and that is charged too.
|
|
736
751
|
- **One channel per wallet.** All clients for a wallet share one channel, saved to `~/.blockrun/solana-batch/<wallet>.json` (mode `0600`) so a restart reuses it.
|
|
752
|
+
- **One call at a time per wallet.** A channel carries one pending authorization, and each voucher builds on the previous call's metered charge, which is known only once that call's answer is in. So the wallet stays busy from payment until the answer is reconciled: the whole generation, and for `stream()` the whole stream (including a stream your loop stopped reading: the SDK keeps reading it to its receipt, because everything generated is charged). A concurrent batch call on the same wallet (`chat`, `chatCompletion`, `smartChat`, `smartChatCompletion`, `stream()`, `decisions()`) falls back to `exact` meanwhile, reported as `channel_busy`. `batch.onBusy: "wait"` makes it wait up to `batch.busyWaitMs` (default 60 s) and pay with batch instead, trading latency for price; `"throw"` raises `BatchChannelBusyError` (unpaid, nothing signed). The gateway allows one live channel per payer, so for parallel batch calls give each worker its own wallet.
|
|
737
753
|
- **One process per wallet.** The process that opens the channel holds its store's lock until it exits. Other processes on that wallet (worker pools, PM2/cluster workers, parallel runs) pay `exact`, reported as `channel_store_locked`. Give each worker its own wallet, or route calls through one process. `batch.onLocked: "wait"` waits up to `batch.lockWaitMs` (default 60 s) for the lock, and `"throw"` raises `BatchChannelLockedError` (unpaid, nothing signed) instead of paying `exact`.
|
|
738
754
|
- **Observable.** Every fallback, backoff, recovery and re-read writes one stderr line; `batch.onEvent` and `client.getBatchStats()` expose the same events and counters.
|
|
739
755
|
|
|
@@ -760,7 +776,7 @@ The 402 from that host names `eip155:5042`, and the SDK signs the EIP-3009 autho
|
|
|
760
776
|
|
|
761
777
|
**Setup:**
|
|
762
778
|
1. Same wallet key as Base: `export BASE_CHAIN_WALLET_KEY="0x..."`
|
|
763
|
-
2. Fund it with USDC on Arc (Arc's native token
|
|
779
|
+
2. Fund it with USDC on Arc (Arc's native gas token; the SDK pays through its ERC-20 interface at `0x3600…0000`)
|
|
764
780
|
3. `apiUrl: 'https://arc.blockrun.ai/api'` — payments are automatic via x402
|
|
765
781
|
|
|
766
782
|
**Endpoint:** `https://arc.blockrun.ai/api` · **Payment:** USDC on Arc (chain 5042), settled by Circle
|
|
@@ -808,9 +824,10 @@ console.log(result.choices[0].message.content);
|
|
|
808
824
|
### Streaming
|
|
809
825
|
|
|
810
826
|
Every client streams with automatic payment. On `LLMClient` in Base / Arc
|
|
811
|
-
wallet mode, `chatCompletionStream()` also keeps a **pre-auth cache**:
|
|
812
|
-
first call
|
|
813
|
-
(about
|
|
827
|
+
wallet mode, `chatCompletionStream()` also keeps a **pre-auth cache**: once a
|
|
828
|
+
first call has learned a model's price, later calls to that model sign the
|
|
829
|
+
payment before sending and skip the 402 round-trip (about 200 ms saved per
|
|
830
|
+
request).
|
|
814
831
|
|
|
815
832
|
#### OpenAI-compatible (recommended)
|
|
816
833
|
|
|
@@ -871,8 +888,10 @@ while (true) {
|
|
|
871
888
|
yields each `data:` frame already parsed as JSON and stops at `[DONE]`. The
|
|
872
889
|
x402 handshake happens before the first frame — 402, sign an SPL
|
|
873
890
|
TransferChecked authorization locally, replay with `PAYMENT-SIGNATURE` —
|
|
874
|
-
including the fresh-blockhash re-sign on a verification-phase rejection.
|
|
875
|
-
|
|
891
|
+
including the fresh-blockhash re-sign on a verification-phase rejection. When
|
|
892
|
+
the client is constructed with `batch`, the stream is paid with a channel
|
|
893
|
+
voucher instead and charged the metered cost (see [Batch settlement](#batch-settlement-optional-metered-billing)).
|
|
894
|
+
A free model, or an account key, is answered `200` with no handshake at all and
|
|
876
895
|
settles nothing. Pass a concrete model id: `stream()` does not resolve the
|
|
877
896
|
`blockrun/*` aliases.
|
|
878
897
|
|
|
@@ -928,16 +947,17 @@ prefix, or let `routingProfile: 'eco'` rank them first.
|
|
|
928
947
|
| `nvidia/nemotron-3.5-lightning` | 1M | Thinking-mode reasoning at 1M context |
|
|
929
948
|
| `nvidia/nemotron-3-ultra-550b` | 1M | Largest free model — 550B, 1M context |
|
|
930
949
|
| `nvidia/nemotron-3-nano-omni-30b-a3b-reasoning` | 256K | Multimodal reasoning — text + images |
|
|
950
|
+
| `nvidia/minimax-m3.1-flash` | 1M | MiniMax M3.1 Flash — reasons, calls tools |
|
|
931
951
|
| `nvidia/nemotron-3.5-bolt` | 128K | Free vision — verified on real image probes on Base and Solana |
|
|
932
952
|
| `poolside/laguna-xs-2.1` | 128K | Coding model |
|
|
933
953
|
|
|
934
954
|
A free model can be briefly marked unavailable in the live catalog while the
|
|
935
955
|
gateway's health check holds it back; it stays on the free tier.
|
|
936
956
|
|
|
937
|
-
`nvidia/llama-3.2-11b-vision`, `
|
|
938
|
-
still answer, but
|
|
939
|
-
|
|
940
|
-
|
|
957
|
+
`nvidia/llama-3.2-11b-vision`, `nvidia/nemotron-3-super-120b`,
|
|
958
|
+
`cohere/north-mini-code` and `nvidia/muse-glimmer-30b` still answer, but since
|
|
959
|
+
2026-11 the gateway serves them with a different model. Don't pin them; use
|
|
960
|
+
`nemotron-3.5-bolt` for free image input.
|
|
941
961
|
|
|
942
962
|
<details>
|
|
943
963
|
<summary><strong>Paid chat models</strong> — OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot, MiniMax, Z.ai, Qwen, Mistral, Tencent, Poolside, Xiaomi</summary>
|
|
@@ -976,7 +996,6 @@ token price.
|
|
|
976
996
|
| `openai/gpt-5-mini` | 200K | |
|
|
977
997
|
| `openai/gpt-4.1` | 128K | |
|
|
978
998
|
| `openai/gpt-4.1-mini` | 128K | |
|
|
979
|
-
| `openai/gpt-4.1-nano` | 128K | |
|
|
980
999
|
| `openai/gpt-4o` | 128K | |
|
|
981
1000
|
| `openai/gpt-4o-mini` | 128K | |
|
|
982
1001
|
| `openai/o1` | 200K | Reasoning |
|
|
@@ -988,7 +1007,8 @@ token price.
|
|
|
988
1007
|
|
|
989
1008
|
| Model | Context | Notes |
|
|
990
1009
|
|---|---|---|
|
|
991
|
-
| `anthropic/claude-fable-5.
|
|
1010
|
+
| `anthropic/claude-fable-5.2` | 1M | Most capable — successor to Fable 5.1 at a lower price, 128K output |
|
|
1011
|
+
| `anthropic/claude-fable-5.1` | 1M | Successor to Fable 5 at the same tier and price |
|
|
992
1012
|
| `anthropic/claude-fable-5` | 1M | Mythos-class flagship above Opus — always-on thinking, 128K output |
|
|
993
1013
|
| `anthropic/claude-opus-5.5` | 1M | Newest Opus — Opus-class reasoning at a lower price than Opus 5 |
|
|
994
1014
|
| `anthropic/claude-opus-5` | 1M | Flagship — the baseline the routing savings claim is measured against |
|
|
@@ -1005,6 +1025,7 @@ token price.
|
|
|
1005
1025
|
|
|
1006
1026
|
| Model | Context |
|
|
1007
1027
|
|---|---|
|
|
1028
|
+
| `google/gemini-4-carbon` | 1M |
|
|
1008
1029
|
| `google/gemini-4-argon` | 1M |
|
|
1009
1030
|
| `google/gemini-3.1-pro` | 1M |
|
|
1010
1031
|
| `google/gemini-3.8-flash` | 1M |
|
|
@@ -1026,6 +1047,7 @@ paid SKU; the vision SKU is an experimental preview.
|
|
|
1026
1047
|
| Model | Context | Notes |
|
|
1027
1048
|
|---|---|---|
|
|
1028
1049
|
| `deepseek/deepseek-v4-pro` | 1M | V4 flagship — strongest open-weight reasoner |
|
|
1050
|
+
| `deepseek/deepseek-v4.1-flash` | 1M | V4.1 Flash non-thinking |
|
|
1029
1051
|
| `deepseek/deepseek-v4-flash-vision-exp` | 1M | Experimental vision preview |
|
|
1030
1052
|
| `deepseek/deepseek-chat` | 1M | V4 Flash non-thinking |
|
|
1031
1053
|
| `deepseek/deepseek-reasoner` | 1M | V4 Flash thinking (same upstream, thinking on by default) |
|
|
@@ -1048,7 +1070,7 @@ callable — the gateway redirects them to a healthy model.
|
|
|
1048
1070
|
|
|
1049
1071
|
| Model | Context | Notes |
|
|
1050
1072
|
|---|---|---|
|
|
1051
|
-
| `moonshot/kimi-k3` | 1M |
|
|
1073
|
+
| `moonshot/kimi-k3.1-pro` | 1M | Flagship, image + text input; `kimi-k3` stays callable but is unlisted |
|
|
1052
1074
|
| `minimax/minimax-m3` | 1M | |
|
|
1053
1075
|
| `minimax/minimax-m2.7` | 200K | |
|
|
1054
1076
|
| `zai/glm-5.3` | 1M | |
|
|
@@ -1196,7 +1218,8 @@ console.log(fused.data[0].url);
|
|
|
1196
1218
|
| `bytedance/seedance-2.0-mini` | 5s | 15s | 480p/720p, lowest-cost Seedance 2.0. RealFace supported |
|
|
1197
1219
|
| `bytedance/seedance-2.0` | 5s | 15s | Premium, up to 4K, synced audio. RealFace supported |
|
|
1198
1220
|
| `bytedance/seedance-2.5` | 5s | 30s | Long-form — up to 30s, 480p/720p, multilingual, up to 30 reference images |
|
|
1199
|
-
|
|
1221
|
+
|
|
1222
|
+
Sora 2 (`azure/sora-2`, `openai/sora-2`) was retired by its providers on 2026-11-02 and is no longer served.
|
|
1200
1223
|
|
|
1201
1224
|
```typescript
|
|
1202
1225
|
import { VideoClient } from '@blockrun/llm';
|
|
@@ -1362,6 +1385,53 @@ const info = await phone.lookup('+14155552671');
|
|
|
1362
1385
|
const { phone_number } = await phone.buyNumber({ country: 'US', areaCode: '415' });
|
|
1363
1386
|
```
|
|
1364
1387
|
|
|
1388
|
+
### Decisions (typed judgments)
|
|
1389
|
+
|
|
1390
|
+
`decisions()` asks `gpt-6-luna` questions with a fixed answer space and gets one
|
|
1391
|
+
typed answer per question back instead of text: a `predicate` (probability that
|
|
1392
|
+
it holds), a `choice` (one of your values, with per-value probabilities) or a
|
|
1393
|
+
`score` (position on an ordered rubric). Request and response match OpenAI's
|
|
1394
|
+
Decisions API. It is on `LLMClient`, `SolanaLLMClient` and the OpenAI wrapper
|
|
1395
|
+
(`client.decisions.create()`), with an API key or a wallet.
|
|
1396
|
+
|
|
1397
|
+
```typescript
|
|
1398
|
+
import { LLMClient } from '@blockrun/llm';
|
|
1399
|
+
|
|
1400
|
+
const client = new LLMClient();
|
|
1401
|
+
|
|
1402
|
+
const { answers, costUsd } = await client.decisions({
|
|
1403
|
+
input: 'My card was charged twice for one order and nobody answers my emails.',
|
|
1404
|
+
questions: [
|
|
1405
|
+
{ type: 'predicate', name: 'urgent', instructions: 'Does this need a reply today?' },
|
|
1406
|
+
{
|
|
1407
|
+
type: 'choice', name: 'team', instructions: 'Which team owns this?',
|
|
1408
|
+
choices: [{ value: 'billing' }, { value: 'shipping' }, { value: 'none', description: 'fits no team' }],
|
|
1409
|
+
},
|
|
1410
|
+
{
|
|
1411
|
+
type: 'score', name: 'anger', instructions: 'How upset is the writer?',
|
|
1412
|
+
levels: [{ label: 'calm' }, { label: 'annoyed' }, { label: 'furious' }], // lowest first
|
|
1413
|
+
},
|
|
1414
|
+
],
|
|
1415
|
+
});
|
|
1416
|
+
// [{ type: 'predicate', name: 'urgent', probability: 0.85 },
|
|
1417
|
+
// { type: 'choice', name: 'team', choice: 'billing', probabilities: [...], confidence: 1 },
|
|
1418
|
+
// { type: 'score', name: 'anger', score: 1, probabilities: [...], confidence: 1 }]
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1421
|
+
Only input tokens are billed. A wallet call pays the 402's quote: an
|
|
1422
|
+
upper-bound estimate of the input tokens plus the $0.001 transaction fee. Under
|
|
1423
|
+
Solana [batch settlement](#batch-settlement-optional-metered-billing) it pays
|
|
1424
|
+
the input tokens the provider reports and no per-call fee instead, so a short
|
|
1425
|
+
question costs a few thousandths of a cent. With an API key the account is
|
|
1426
|
+
billed on reported tokens.
|
|
1427
|
+
|
|
1428
|
+
`input` is a string or messages with text and inline `data:image/*` images
|
|
1429
|
+
(hosted image URLs are refused). The gateway caps a call at 64 questions,
|
|
1430
|
+
255 choices or levels each, 120,000 characters of text and 8 images, and
|
|
1431
|
+
refuses an over-limit request with a 400 before any payment. A `choice` always
|
|
1432
|
+
picks one of your values, so give it a `none` value for inputs that fit
|
|
1433
|
+
nothing.
|
|
1434
|
+
|
|
1365
1435
|
### Standalone Search
|
|
1366
1436
|
|
|
1367
1437
|
`SearchClient` wraps `POST /v1/search` — Grok Live Search over `web` and
|
|
@@ -1384,40 +1454,36 @@ for (const c of result.citations ?? []) console.log(c.url);
|
|
|
1384
1454
|
The same endpoint is available as `search()` on `LLMClient` and
|
|
1385
1455
|
`SolanaLLMClient`.
|
|
1386
1456
|
|
|
1387
|
-
### Market Data
|
|
1457
|
+
### Market Data
|
|
1388
1458
|
|
|
1389
|
-
`PriceClient` wraps the
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1459
|
+
`PriceClient` wraps the market-data endpoints: crypto, FX and commodity prices,
|
|
1460
|
+
history and symbol lists, **free and without a wallet**. They are daily closes,
|
|
1461
|
+
not realtime (every response carries `realtime: false`), sourced from Chainlink
|
|
1462
|
+
feeds and Backpack.
|
|
1393
1463
|
|
|
1394
1464
|
```typescript
|
|
1395
1465
|
import { PriceClient } from '@blockrun/llm';
|
|
1396
1466
|
|
|
1397
1467
|
const p = new PriceClient({ requireWallet: false });
|
|
1398
|
-
const btc = await p.price('crypto', 'BTC-USD');
|
|
1468
|
+
const btc = await p.price('crypto', 'BTC-USD'); // btc.price, btc.source, btc.realtime === false
|
|
1399
1469
|
const eur = await p.price('fx', 'EUR-USD');
|
|
1470
|
+
const gold = await p.price('commodity', 'XAU-USD');
|
|
1471
|
+
const bars = await p.history('crypto', 'ETH-USD', { resolution: 'D', from: 1760000000, to: 1762000000 });
|
|
1400
1472
|
const symbols = await p.listSymbols('crypto', { query: 'sol', limit: 20 });
|
|
1401
|
-
|
|
1402
|
-
// Paid: requires an API key or a wallet
|
|
1403
|
-
const p2 = new PriceClient();
|
|
1404
|
-
const aapl = await p2.price('stocks', 'AAPL', { market: 'us' });
|
|
1405
|
-
const bars = await p2.history('stocks', 'AAPL', {
|
|
1406
|
-
market: 'us',
|
|
1407
|
-
resolution: 'D',
|
|
1408
|
-
from: 1700000000,
|
|
1409
|
-
to: 1710000000,
|
|
1410
|
-
});
|
|
1411
1473
|
```
|
|
1412
1474
|
|
|
1413
|
-
|
|
1475
|
+
**Equities are catalog-only for now.** `listSymbols('stocks', { market })` still
|
|
1476
|
+
lists the 12 markets' tickers (`us, hk, jp, kr, gb, de, fr, nl, ie, lu, cn, ca`),
|
|
1477
|
+
but stock `price()` and `history()` answer `501` (an `APIError` with
|
|
1478
|
+
`statusCode` 501): BlockRun does not currently serve equity prices. Nothing is
|
|
1479
|
+
charged for them.
|
|
1414
1480
|
|
|
1415
1481
|
### Prediction Markets (Powered by Predexon)
|
|
1416
1482
|
|
|
1417
1483
|
Prediction-market data from Polymarket, Kalshi, Limitless, Opinion,
|
|
1418
1484
|
Predict.Fun, Binance Futures, UMA oracle resolutions and sports markets via
|
|
1419
1485
|
[Predexon](https://predexon.com). Every endpoint costs the same flat price per
|
|
1420
|
-
call
|
|
1486
|
+
call. Use an account API key or x402 wallet
|
|
1421
1487
|
payments; no separate Predexon key is needed. `pm()` works on both `LLMClient`
|
|
1422
1488
|
and `SolanaLLMClient`; query parameters are strings.
|
|
1423
1489
|
|
|
@@ -1593,8 +1659,9 @@ const gptResponse = await client.messages.create({
|
|
|
1593
1659
|
|
|
1594
1660
|
This wrapper proxies straight to the gateway's `/v1/messages` and does not
|
|
1595
1661
|
resolve `blockrun/*` aliases; pass a concrete model id. Anthropic's own dashed
|
|
1596
|
-
ids resolve, including the Mythos-class `claude-fable-5
|
|
1597
|
-
`claude-fable-5-1` / `claude-fable-5.1`
|
|
1662
|
+
ids resolve, including the Mythos-class `claude-fable-5`,
|
|
1663
|
+
`claude-fable-5-1` / `claude-fable-5.1` and `claude-fable-5-2` /
|
|
1664
|
+
`claude-fable-5.2` (1M context, always-on thinking).
|
|
1598
1665
|
|
|
1599
1666
|
## Wallets
|
|
1600
1667
|
|
|
@@ -1835,10 +1902,10 @@ A TypeScript SDK that cuts LLM costs by <!-- br:savings.autoVsBaselinePct -->84<
|
|
|
1835
1902
|
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).
|
|
1836
1903
|
|
|
1837
1904
|
### Does it support streaming?
|
|
1838
|
-
Yes: `LLMClient.chatCompletionStream()`, `stream: true` in the OpenAI-compatible client, and `
|
|
1905
|
+
Yes: `LLMClient.chatCompletionStream()`, `stream: true` in the OpenAI-compatible client, `SolanaLLMClient.stream()`, and `BlockrunClient.stream()`. The payment is signed before the first token (under Solana batch settlement the metered charge is booked once the stream's receipt arrives), and with an API key the stream is billed to your account.
|
|
1839
1906
|
|
|
1840
1907
|
### How much does it cost?
|
|
1841
|
-
Pay only for what you use: no minimums, subscriptions, or monthly fees, and
|
|
1908
|
+
Pay only for what you use: no minimums, subscriptions, or monthly fees, and the [free tier](#free-tier) costs $0. Live per-model rates are at [blockrun.ai/models](https://blockrun.ai/models).
|
|
1842
1909
|
|
|
1843
1910
|
### Do I need a crypto wallet?
|
|
1844
1911
|
No. An account API key from [user.blockrun.ai](https://user.blockrun.ai) works without any wallet or chain. Wallets are for x402 pay-per-request on Solana (`SolanaLLMClient`, recommended), Base or Arc (`LLMClient`).
|