@blockrun/llm 3.14.3 → 3.15.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 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 -->74<!-- /br:models.chatVisible --> models — every request goes to the cheapest model that can handle it,
7
+ The smart-routing SDK for <!-- br:models.chatVisible -->76<!-- /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
  [![npm](https://img.shields.io/npm/v/@blockrun/llm.svg?style=flat-square)](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 -->74<!-- /br:models.chatVisible -->, one credential** |
59
+ | **Models** | GPT only | 200+ | 100+ (BYO keys) | **<!-- br:models.chatVisible -->76<!-- /br:models.chatVisible -->, one credential** |
60
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** |
@@ -65,7 +65,7 @@ console.log(r.response); // the proof
65
65
  ## Installation
66
66
 
67
67
  ```bash
68
- npm install @blockrun/llm # Base / EVM payments — smart routing included, nothing else needed
68
+ npm install @blockrun/llm # Account API keys or Base wallets; smart routing included
69
69
  ```
70
70
 
71
71
  <details>
@@ -98,6 +98,8 @@ without them throws an error naming the exact install command.
98
98
 
99
99
  </details>
100
100
 
101
+ The Anthropic SDK is a runtime dependency because the public compatibility wrapper exposes its types. Solana signing dependencies remain optional and are unnecessary for account billing.
102
+
101
103
  ## Quick Start: API Key
102
104
 
103
105
  1. [Sign up or sign in](https://user.blockrun.ai).
@@ -130,9 +132,14 @@ wallet mode even when `BLOCKRUN_API_KEY` is set; passing both explicit credentia
130
132
  is an error. With no explicit credential, `BLOCKRUN_API_KEY` beats the wallet key
131
133
  env vars — a process holding both runs in account mode. Invalid or exhausted API keys never fall back to wallet payments.
132
134
  Errors preserve `statusCode`, account error `response.code`, and `retryAfter`.
133
- Account credentials are restricted to the configured origin, including polling.
135
+ Account credentials are restricted to the configured origin, including polling. Account POSTs are not automatically replayed, including through the Anthropic wrapper. GET/HEAD requests can retry temporary gateway errors; accepted jobs keep polling the same job within the original timeout. A 429 returns `retryAfter` to the caller.
136
+
137
+ Check [Activity](https://user.blockrun.ai/dashboard/activity) for account usage and charges. Chat uses token usage; media and data can use duration, image, or per-request units. When adding credit, the checkout shows the credit amount and total card charge, including any processing fee. Keep API keys in server or local environment variables, never in browser code or logs.
138
+
139
+ For asynchronous jobs, retain the complete returned `poll_url`, including its query parameters. If polling times out, check the original job and Activity before submitting again.
140
+
141
+ To switch back to a wallet, unset `BLOCKRUN_API_KEY` and create a new wallet client, or pass an explicit `privateKey` to the appropriate client. Existing clients retain their original credentials; changing a wallet chain does not change account billing.
134
142
 
135
- Use the [account dashboard](https://user.blockrun.ai/dashboard) for account usage.
136
143
  `getSpending()` reports x402 settlements only and throws in account mode; wallet
137
144
  address/balance helpers require a wallet. Account credit does not sign trades or
138
145
  transfer wallet funds. Service availability depends on the account gateway and model.
@@ -1017,8 +1024,7 @@ Generic escape hatches: `client.defi(path, params)`, `client.dex(path, params, b
1017
1024
  `RpcClient` wraps `POST /v1/rpc/{network}` — standard JSON-RPC 2.0 access to
1018
1025
  <!-- br:chains.rpc -->40<!-- /br:chains.rpc --> chains through one endpoint (Ethereum, Base, Solana, Polygon, BSC,
1019
1026
  Arbitrum, Optimism, Avalanche, Bitcoin, Sui, and more; powered by Tatum's RPC
1020
- gateway). No API key, no per-chain endpoints: one flat per-call rate in
1021
- USDC; a JSON-RPC batch charges per element.
1027
+ gateway). Use account credits or the selected x402 wallet; no separate Tatum key is needed. A JSON-RPC batch is priced per element.
1022
1028
 
1023
1029
  ```ts
1024
1030
  import { RpcClient } from '@blockrun/llm';
@@ -1233,6 +1239,35 @@ while (true) {
1233
1239
  }
1234
1240
  ```
1235
1241
 
1242
+ #### Solana
1243
+
1244
+ `SolanaLLMClient.stream()` is the Solana counterpart, with the same shape as
1245
+ `BlockrunClient.stream()`: it yields each `data:` frame already parsed as JSON
1246
+ and stops at `[DONE]`. The x402 handshake happens before the first frame — 402,
1247
+ sign an SPL TransferChecked authorization locally, replay with
1248
+ `PAYMENT-SIGNATURE` — including the fresh-blockhash re-sign on a
1249
+ verification-phase rejection. A free model, or an account key, is answered `200`
1250
+ with no handshake at all and settles nothing.
1251
+
1252
+ ```typescript
1253
+ import { SolanaLLMClient } from '@blockrun/llm';
1254
+
1255
+ const client = new SolanaLLMClient(); // SOLANA_WALLET_KEY, or { apiKey: 'brk_live_…' }
1256
+
1257
+ for await (const chunk of client.stream('/v1/chat/completions', {
1258
+ model: 'deepseek/deepseek-chat',
1259
+ messages: [{ role: 'user', content: 'Hi' }],
1260
+ max_tokens: 64,
1261
+ stream: true,
1262
+ })) {
1263
+ process.stdout.write(chunk?.choices?.[0]?.delta?.content ?? '');
1264
+ }
1265
+ ```
1266
+
1267
+ Set `stream: true` yourself — the method does not inject it, because the gateway
1268
+ prices a streaming and a non-streaming request the same and rewriting a caller's
1269
+ body silently is how you end up debugging a request you did not send.
1270
+
1236
1271
  #### Payment + streaming flow
1237
1272
 
1238
1273
  ```
@@ -1278,7 +1313,7 @@ const [gpt, claude, gemini] = await Promise.all([
1278
1313
 
1279
1314
  ## Prediction Markets (Powered by Predexon)
1280
1315
 
1281
- Access real-time prediction market data from Polymarket, Kalshi, and Binance Futures via [Predexon](https://predexon.com). No API keys needed — pay-per-request via x402.
1316
+ Access real-time prediction market data from Polymarket, Kalshi, and Binance Futures via [Predexon](https://predexon.com). Use a BlockRun account API key or x402 wallet payments; no separate Predexon key is needed.
1282
1317
 
1283
1318
  ### Polymarket
1284
1319
 
@@ -1339,7 +1374,7 @@ Works on both `LLMClient` (Base) and `SolanaLLMClient`.
1339
1374
 
1340
1375
  ## Exa Web Search (Powered by Exa)
1341
1376
 
1342
- Access [Exa](https://exa.ai)'s neural web search via x402. No API keys needed — pay-per-request. Available on **`LLMClient` (Base USDC)** and `SolanaLLMClient` (Solana USDC). Use Base as the primary path; the Solana gateway is awaiting `EXA_API_KEY` provisioning.
1377
+ Access [Exa](https://exa.ai)'s neural web search using account credits or x402 wallet payments; no separate Exa key is needed. Use `SolanaLLMClient` for a Solana wallet or `LLMClient` for a Base wallet. Availability depends on the selected gateway.
1343
1378
 
1344
1379
  | Method | Description |
1345
1380
  |---|---|
@@ -1714,7 +1749,7 @@ The `AnthropicClient` wraps the official `@anthropic-ai/sdk` with a custom fetch
1714
1749
  ## Frequently Asked Questions
1715
1750
 
1716
1751
  ### What is @blockrun/llm?
1717
- @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 -->74<!-- /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.
1752
+ @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 -->76<!-- /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.
1718
1753
 
1719
1754
  ### How does payment work?
1720
1755
  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.