@blockrun/llm 3.14.2 → 3.15.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 CHANGED
@@ -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
 
@@ -1292,35 +1327,35 @@ const markets = await client.pm("polymarket/markets");
1292
1327
  const filtered = await client.pm("polymarket/markets", { status: "active", limit: 10 });
1293
1328
  const searched = await client.pm("polymarket/markets", { search: "bitcoin" });
1294
1329
 
1295
- // List events ($0.001/request)
1330
+ // List events
1296
1331
  const events = await client.pm("polymarket/events");
1297
1332
 
1298
- // Historical trades ($0.001/request)
1333
+ // Historical trades
1299
1334
  const trades = await client.pm("polymarket/trades");
1300
1335
 
1301
- // OHLCV candlestick data for a specific condition ($0.001/request)
1336
+ // OHLCV candlestick data for a specific condition
1302
1337
  const candles = await client.pm("polymarket/candlesticks/0x1234abcd...");
1303
1338
 
1304
- // Wallet profile ($0.005/request — tier 2)
1339
+ // Wallet profile (tier 2)
1305
1340
  const profile = await client.pm("polymarket/wallet/0xABC123...");
1306
1341
 
1307
- // Wallet P&L ($0.005/request — tier 2)
1342
+ // Wallet P&L (tier 2)
1308
1343
  const pnl = await client.pm("polymarket/wallet/pnl/0xABC123...");
1309
1344
 
1310
- // Global leaderboard ($0.001/request)
1345
+ // Global leaderboard
1311
1346
  const leaderboard = await client.pm("polymarket/leaderboard");
1312
1347
  ```
1313
1348
 
1314
1349
  ### Kalshi & Binance
1315
1350
 
1316
1351
  ```typescript
1317
- // Kalshi markets ($0.001/request)
1352
+ // Kalshi markets
1318
1353
  const kalshiMarkets = await client.pm("kalshi/markets");
1319
1354
 
1320
- // Kalshi trades ($0.001/request)
1355
+ // Kalshi trades
1321
1356
  const kalshiTrades = await client.pm("kalshi/trades");
1322
1357
 
1323
- // Binance candles for supported pairs ($0.001/request)
1358
+ // Binance candles for supported pairs
1324
1359
  const btcCandles = await client.pm("binance/candles/BTCUSDT");
1325
1360
  const ethCandles = await client.pm("binance/candles/ETHUSDT");
1326
1361
  // Also: SOLUSDT, XRPUSDT
@@ -1329,7 +1364,7 @@ const ethCandles = await client.pm("binance/candles/ETHUSDT");
1329
1364
  ### Cross-Platform
1330
1365
 
1331
1366
  ```typescript
1332
- // Cross-platform matching pairs ($0.001/request)
1367
+ // Cross-platform matching pairs
1333
1368
  const pairs = await client.pm("matching-markets/pairs");
1334
1369
  ```
1335
1370
 
@@ -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
  |---|---|
@@ -1354,17 +1389,17 @@ import { LLMClient } from '@blockrun/llm';
1354
1389
 
1355
1390
  const client = new LLMClient();
1356
1391
 
1357
- // Neural web search ($0.01/request)
1392
+ // Neural web search
1358
1393
  const results = await client.exaSearch("latest AI safety research", { numResults: 5 });
1359
1394
  const news = await client.exaSearch("bitcoin ETF news", { category: "news", numResults: 10 });
1360
1395
 
1361
- // Find similar pages ($0.01/request)
1396
+ // Find similar pages
1362
1397
  const similar = await client.exaFindSimilar("https://openai.com/research/gpt-4", { numResults: 5 });
1363
1398
 
1364
- // Extract content from URLs ($0.002/URL)
1399
+ // Extract content from URLs
1365
1400
  const content = await client.exaContents(["https://arxiv.org/abs/2303.08774"]);
1366
1401
 
1367
- // AI-generated answer from live web ($0.01/request)
1402
+ // AI-generated answer from live web
1368
1403
  const answer = await client.exaAnswer("What is the current state of AI safety research?");
1369
1404
 
1370
1405
  // Generic proxy for any Exa endpoint
@@ -1436,7 +1471,7 @@ npm test -- --coverage # Run with coverage report
1436
1471
  Integration tests call the production API and require:
1437
1472
  - A funded Base wallet with USDC ($1+ recommended)
1438
1473
  - `BASE_CHAIN_WALLET_KEY` environment variable set
1439
- - Estimated cost: ~$0.05 per test run
1474
+ - Integration tests make real paid calls; cost depends on the models exercised
1440
1475
 
1441
1476
  ```bash
1442
1477
  export BASE_CHAIN_WALLET_KEY=0x...
@@ -1726,7 +1761,7 @@ Router Core V3 is bundled into the SDK — the same deterministic routing engine
1726
1761
  Yes — as of v1.6.1. Use `client.chatCompletionStream()` for native streaming or `stream: true` in the OpenAI-compatible client. Payment is handled automatically: the SDK signs USDC payment before streaming begins, and caches payment requirements per model so subsequent calls skip the 402 round-trip (~200ms faster).
1727
1762
 
1728
1763
  ### How much does it cost?
1729
- Pay only for what you use. Prices start at $0.0002 per request (GPT-5 Nano). There are no minimums, subscriptions, or monthly fees. $5 in USDC gets you thousands of requests.
1764
+ Pay only for what you use. There are no minimums, subscriptions, or monthly fees, and $5 in USDC gets you thousands of requests. Live per-model rates are at [blockrun.ai/models](https://blockrun.ai/models).
1730
1765
 
1731
1766
  ### Does it support both Solana and Base?
1732
1767
  Yes. Use `SolanaLLMClient` for Solana payments (recommended) and `LLMClient` for Base payments. Use `apiKey` for account billing without selecting a chain.