@blockrun/llm 3.15.0 → 3.16.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 +32 -7
- package/dist/index.cjs +66 -12
- package/dist/index.d.cts +41 -4
- package/dist/index.d.ts +41 -4
- package/dist/index.js +62 -12
- 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 -->78<!-- /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
|
[](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. The main event.
|
|
47
|
-
- 🆓 **<!-- br:models.free -->
|
|
47
|
+
- 🆓 **<!-- br:models.free -->6<!-- /br:models.free --> genuinely free models** — $0 in and out, incl. two 1M-context Nemotrons, a multimodal one, and free coding models from Cohere and Poolside. No rate-limit gimmicks.
|
|
48
48
|
- 🔐 **Two ways to connect** — a **BlockRun API key** billed against account credit ([sign up at user.blockrun.ai](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 or Base. $5 covers thousands of requests; agents can pay their own way.
|
|
50
50
|
- 🛡️ **Automatic failover** — transient errors (timeouts, 429, 5xx) walk the router's ranked fallback chain instead of failing your request.
|
|
@@ -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 -->78<!-- /br:models.chatVisible -->, one credential** |
|
|
60
|
+
| **Free tier** | ✗ | Rate-limited | ✗ | **<!-- br:models.free -->6<!-- /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** |
|
|
@@ -313,7 +313,7 @@ const reply = await client.chat('nvidia/nemotron-3.5-lightning', 'hello', {
|
|
|
313
313
|
|
|
314
314
|
| Profile | Strategy | Savings vs Opus 5 | Best For |
|
|
315
315
|
|---------|----------|-------------------|----------|
|
|
316
|
-
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->
|
|
316
|
+
| `eco` | Cheapest capable model — ranks the <!-- br:models.free -->6<!-- /br:models.free -->-model free tier first | **<!-- br:savings.ecoVsBaselinePct -->98<!-- /br:savings.ecoVsBaselinePct -->%** | Cost-sensitive production, zero-cost testing |
|
|
317
317
|
| `auto` | Best balance of cost/quality (default) | **<!-- br:savings.autoVsBaselinePct -->84<!-- /br:savings.autoVsBaselinePct -->%** | General use |
|
|
318
318
|
| `premium` | Top-tier models (OpenAI, Anthropic) | 0% | Quality-critical tasks |
|
|
319
319
|
|
|
@@ -444,6 +444,31 @@ const tweet = await client.chat('xai/grok-4.5', 'What is trending on X?', { sear
|
|
|
444
444
|
**Supported endpoint:** `https://sol.blockrun.ai/api`
|
|
445
445
|
**Payment:** Solana USDC (SPL, mainnet)
|
|
446
446
|
|
|
447
|
+
## Arc Support
|
|
448
|
+
|
|
449
|
+
The same `LLMClient` pays on [Circle's Arc](https://www.arc.network) via [arc.blockrun.ai](https://arc.blockrun.ai) — point `apiUrl` at it and hold USDC on Arc in the same EVM wallet:
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
import { LLMClient } from '@blockrun/llm';
|
|
453
|
+
|
|
454
|
+
const client = new LLMClient({
|
|
455
|
+
privateKey: process.env.BLOCKRUN_WALLET_KEY,
|
|
456
|
+
apiUrl: 'https://arc.blockrun.ai/api',
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const response = await client.chat('openai/gpt-4o', 'gm Arc');
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
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.
|
|
463
|
+
|
|
464
|
+
**Setup:**
|
|
465
|
+
1. Same wallet key as Base: `export BLOCKRUN_WALLET_KEY="0x..."`
|
|
466
|
+
2. Fund it with USDC on Arc (Arc's native token, shown as the ERC-20 at `0x3600…0000`)
|
|
467
|
+
3. `apiUrl: 'https://arc.blockrun.ai/api'` — payments are automatic via x402
|
|
468
|
+
|
|
469
|
+
**Supported endpoint:** `https://arc.blockrun.ai/api`
|
|
470
|
+
**Payment:** USDC on Arc (chain 5042), settled by Circle
|
|
471
|
+
|
|
447
472
|
## How Payment Works
|
|
448
473
|
|
|
449
474
|
In wallet mode, no API key is required. You hold USDC in your own wallet, and **every request pays for itself** with an on-chain micropayment. Two phases:
|
|
@@ -1158,7 +1183,7 @@ const free = await client.chat('nvidia/nemotron-3.5-lightning', 'Hello!');
|
|
|
1158
1183
|
|
|
1159
1184
|
| Profile | Description | Best For |
|
|
1160
1185
|
|---------|-------------|----------|
|
|
1161
|
-
| `eco` | Budget-optimized — ranks the <!-- br:models.free -->
|
|
1186
|
+
| `eco` | Budget-optimized — ranks the <!-- br:models.free -->6<!-- /br:models.free -->-model free tier first | Cost-sensitive workloads, zero-cost testing |
|
|
1162
1187
|
| `auto` | Intelligent routing (default) | General use |
|
|
1163
1188
|
| `premium` | Best quality models | Critical tasks |
|
|
1164
1189
|
|
|
@@ -1749,7 +1774,7 @@ The `AnthropicClient` wraps the official `@anthropic-ai/sdk` with a custom fetch
|
|
|
1749
1774
|
## Frequently Asked Questions
|
|
1750
1775
|
|
|
1751
1776
|
### What is @blockrun/llm?
|
|
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 -->
|
|
1777
|
+
@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 -->78<!-- /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.
|
|
1753
1778
|
|
|
1754
1779
|
### How does payment work?
|
|
1755
1780
|
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.
|
package/dist/index.cjs
CHANGED
|
@@ -32,10 +32,12 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
APIError: () => APIError,
|
|
34
34
|
API_KEY_URL: () => API_KEY_URL,
|
|
35
|
+
ARC_CHAIN_ID: () => ARC_CHAIN_ID,
|
|
35
36
|
AnthropicClient: () => AnthropicClient,
|
|
36
37
|
BASE_CHAIN_ID: () => BASE_CHAIN_ID,
|
|
37
38
|
BlockrunClient: () => BlockrunClient,
|
|
38
39
|
BlockrunError: () => BlockrunError,
|
|
40
|
+
EVM_NETWORKS: () => EVM_NETWORKS,
|
|
39
41
|
ImageClient: () => ImageClient,
|
|
40
42
|
KNOWN_PROVIDERS: () => KNOWN_PROVIDERS,
|
|
41
43
|
LLMClient: () => LLMClient,
|
|
@@ -59,6 +61,7 @@ __export(index_exports, {
|
|
|
59
61
|
SolanaLLMClient: () => SolanaLLMClient,
|
|
60
62
|
SpeechClient: () => SpeechClient,
|
|
61
63
|
SurfClient: () => SurfClient,
|
|
64
|
+
USDC_ARC: () => USDC_ARC,
|
|
62
65
|
USDC_BASE: () => USDC_BASE,
|
|
63
66
|
USDC_BASE_CONTRACT: () => USDC_BASE_CONTRACT,
|
|
64
67
|
USDC_SOLANA: () => USDC_SOLANA,
|
|
@@ -72,6 +75,7 @@ __export(index_exports, {
|
|
|
72
75
|
createSolanaWallet: () => createSolanaWallet,
|
|
73
76
|
createWallet: () => createWallet,
|
|
74
77
|
default: () => client_default,
|
|
78
|
+
evmNetwork: () => evmNetwork,
|
|
75
79
|
extractPaymentDetails: () => extractPaymentDetails,
|
|
76
80
|
formatFundingMessageCompact: () => formatFundingMessageCompact,
|
|
77
81
|
formatNeedsFundingMessage: () => formatNeedsFundingMessage,
|
|
@@ -243,9 +247,12 @@ function sanitizeErrorResponse(errorBody) {
|
|
|
243
247
|
return { message: "API request failed" };
|
|
244
248
|
}
|
|
245
249
|
const body = errorBody;
|
|
250
|
+
const detail = typeof body.message === "string" && body.message !== body.error ? body.message : void 0;
|
|
246
251
|
return {
|
|
247
252
|
message: typeof body.error === "string" ? body.error : "API request failed",
|
|
248
|
-
code: typeof body.code === "string" ? body.code : void 0
|
|
253
|
+
code: typeof body.code === "string" ? body.code : void 0,
|
|
254
|
+
...detail ? { detail } : {},
|
|
255
|
+
...typeof body.hint === "string" ? { hint: body.hint } : {}
|
|
249
256
|
};
|
|
250
257
|
}
|
|
251
258
|
function validateResourceUrl(url, baseUrl) {
|
|
@@ -4309,6 +4316,42 @@ async function loadSplToken(what) {
|
|
|
4309
4316
|
// src/x402.ts
|
|
4310
4317
|
var BASE_CHAIN_ID = 8453;
|
|
4311
4318
|
var USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
4319
|
+
var ARC_CHAIN_ID = 5042;
|
|
4320
|
+
var USDC_ARC = "0x3600000000000000000000000000000000000000";
|
|
4321
|
+
var EVM_NETWORKS = {
|
|
4322
|
+
"eip155:8453": {
|
|
4323
|
+
name: "Base",
|
|
4324
|
+
chainId: BASE_CHAIN_ID,
|
|
4325
|
+
usdc: USDC_BASE,
|
|
4326
|
+
domain: { name: "USD Coin", version: "2", chainId: BASE_CHAIN_ID, verifyingContract: USDC_BASE }
|
|
4327
|
+
},
|
|
4328
|
+
"eip155:5042": {
|
|
4329
|
+
name: "Arc",
|
|
4330
|
+
chainId: ARC_CHAIN_ID,
|
|
4331
|
+
usdc: USDC_ARC,
|
|
4332
|
+
domain: { name: "USDC", version: "2", chainId: ARC_CHAIN_ID, verifyingContract: USDC_ARC }
|
|
4333
|
+
},
|
|
4334
|
+
"eip155:84532": {
|
|
4335
|
+
name: "Base Sepolia",
|
|
4336
|
+
chainId: 84532,
|
|
4337
|
+
usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
4338
|
+
domain: {
|
|
4339
|
+
name: "USDC",
|
|
4340
|
+
version: "2",
|
|
4341
|
+
chainId: 84532,
|
|
4342
|
+
verifyingContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
};
|
|
4346
|
+
function evmNetwork(network) {
|
|
4347
|
+
const net = EVM_NETWORKS[network];
|
|
4348
|
+
if (!net) {
|
|
4349
|
+
throw new Error(
|
|
4350
|
+
`Unsupported x402 network "${network}": this SDK signs USDC payments on ${Object.keys(EVM_NETWORKS).join(", ")}`
|
|
4351
|
+
);
|
|
4352
|
+
}
|
|
4353
|
+
return net;
|
|
4354
|
+
}
|
|
4312
4355
|
var SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
4313
4356
|
var USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
4314
4357
|
var SOLANA_USDC_DECIMALS = 6;
|
|
@@ -4352,12 +4395,6 @@ async function getBlockhashEntry(connection, rpcUrl, forceRefresh) {
|
|
|
4352
4395
|
trimOldest(blockhashCache, MAX_TRACKED_ENDPOINTS);
|
|
4353
4396
|
return entry;
|
|
4354
4397
|
}
|
|
4355
|
-
var USDC_DOMAIN = {
|
|
4356
|
-
name: "USD Coin",
|
|
4357
|
-
version: "2",
|
|
4358
|
-
chainId: BASE_CHAIN_ID,
|
|
4359
|
-
verifyingContract: USDC_BASE
|
|
4360
|
-
};
|
|
4361
4398
|
var TRANSFER_TYPES = {
|
|
4362
4399
|
TransferWithAuthorization: [
|
|
4363
4400
|
{ name: "from", type: "address" },
|
|
@@ -4388,7 +4425,13 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
4388
4425
|
const validAfter = now - 600;
|
|
4389
4426
|
const validBefore = now + (options.maxTimeoutSeconds || 300);
|
|
4390
4427
|
const nonce = createNonce();
|
|
4391
|
-
const
|
|
4428
|
+
const net = evmNetwork(network);
|
|
4429
|
+
if (options.asset && options.asset.toLowerCase() !== net.usdc.toLowerCase()) {
|
|
4430
|
+
throw new Error(
|
|
4431
|
+
`x402 asset mismatch: the 402 asks for ${options.asset} on ${network}, but this SDK only pays USDC there (${net.usdc})`
|
|
4432
|
+
);
|
|
4433
|
+
}
|
|
4434
|
+
const domain = net.domain;
|
|
4392
4435
|
const signature = await (0, import_accounts.signTypedData)({
|
|
4393
4436
|
privateKey,
|
|
4394
4437
|
domain,
|
|
@@ -4414,10 +4457,10 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
4414
4457
|
scheme: "exact",
|
|
4415
4458
|
network,
|
|
4416
4459
|
amount,
|
|
4417
|
-
asset:
|
|
4460
|
+
asset: net.usdc,
|
|
4418
4461
|
payTo: recipient,
|
|
4419
4462
|
maxTimeoutSeconds: options.maxTimeoutSeconds || 300,
|
|
4420
|
-
extra: { name:
|
|
4463
|
+
extra: { name: net.domain.name, version: net.domain.version }
|
|
4421
4464
|
},
|
|
4422
4465
|
payload: {
|
|
4423
4466
|
signature,
|
|
@@ -4617,7 +4660,7 @@ function getCostSummary() {
|
|
|
4617
4660
|
}
|
|
4618
4661
|
|
|
4619
4662
|
// src/version.ts
|
|
4620
|
-
var SDK_VERSION = "3.
|
|
4663
|
+
var SDK_VERSION = "3.16.0";
|
|
4621
4664
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
4622
4665
|
|
|
4623
4666
|
// src/client.ts
|
|
@@ -5077,6 +5120,7 @@ var LLMClient = class _LLMClient {
|
|
|
5077
5120
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5078
5121
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5079
5122
|
extra: details.extra,
|
|
5123
|
+
asset: details.asset,
|
|
5080
5124
|
extensions
|
|
5081
5125
|
}
|
|
5082
5126
|
);
|
|
@@ -5162,6 +5206,7 @@ var LLMClient = class _LLMClient {
|
|
|
5162
5206
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5163
5207
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5164
5208
|
extra: details.extra,
|
|
5209
|
+
asset: details.asset,
|
|
5165
5210
|
extensions
|
|
5166
5211
|
}
|
|
5167
5212
|
);
|
|
@@ -5373,6 +5418,7 @@ var LLMClient = class _LLMClient {
|
|
|
5373
5418
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5374
5419
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5375
5420
|
extra: details.extra,
|
|
5421
|
+
asset: details.asset,
|
|
5376
5422
|
extensions
|
|
5377
5423
|
}
|
|
5378
5424
|
);
|
|
@@ -5520,6 +5566,7 @@ var LLMClient = class _LLMClient {
|
|
|
5520
5566
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5521
5567
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5522
5568
|
extra: details.extra,
|
|
5569
|
+
asset: details.asset,
|
|
5523
5570
|
extensions
|
|
5524
5571
|
}
|
|
5525
5572
|
);
|
|
@@ -6313,6 +6360,7 @@ var ImageClient = class {
|
|
|
6313
6360
|
resourceDescription: details.resource?.description || "BlockRun Image Generation",
|
|
6314
6361
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
6315
6362
|
extra: details.extra,
|
|
6363
|
+
asset: details.asset,
|
|
6316
6364
|
extensions
|
|
6317
6365
|
}
|
|
6318
6366
|
);
|
|
@@ -8920,7 +8968,8 @@ var BlockrunClient = class {
|
|
|
8920
8968
|
details.maxTimeoutSeconds || 0,
|
|
8921
8969
|
opts.maxTimeoutSeconds || 300
|
|
8922
8970
|
),
|
|
8923
|
-
extra: details.extra
|
|
8971
|
+
extra: details.extra,
|
|
8972
|
+
asset: details.asset
|
|
8924
8973
|
}
|
|
8925
8974
|
);
|
|
8926
8975
|
}
|
|
@@ -10851,6 +10900,7 @@ var AnthropicClient = class {
|
|
|
10851
10900
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
10852
10901
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
10853
10902
|
extra: details.extra,
|
|
10903
|
+
asset: details.asset,
|
|
10854
10904
|
extensions
|
|
10855
10905
|
}
|
|
10856
10906
|
);
|
|
@@ -10893,10 +10943,12 @@ var AnthropicClient = class {
|
|
|
10893
10943
|
0 && (module.exports = {
|
|
10894
10944
|
APIError,
|
|
10895
10945
|
API_KEY_URL,
|
|
10946
|
+
ARC_CHAIN_ID,
|
|
10896
10947
|
AnthropicClient,
|
|
10897
10948
|
BASE_CHAIN_ID,
|
|
10898
10949
|
BlockrunClient,
|
|
10899
10950
|
BlockrunError,
|
|
10951
|
+
EVM_NETWORKS,
|
|
10900
10952
|
ImageClient,
|
|
10901
10953
|
KNOWN_PROVIDERS,
|
|
10902
10954
|
LLMClient,
|
|
@@ -10920,6 +10972,7 @@ var AnthropicClient = class {
|
|
|
10920
10972
|
SolanaLLMClient,
|
|
10921
10973
|
SpeechClient,
|
|
10922
10974
|
SurfClient,
|
|
10975
|
+
USDC_ARC,
|
|
10923
10976
|
USDC_BASE,
|
|
10924
10977
|
USDC_BASE_CONTRACT,
|
|
10925
10978
|
USDC_SOLANA,
|
|
@@ -10932,6 +10985,7 @@ var AnthropicClient = class {
|
|
|
10932
10985
|
createSolanaPaymentPayload,
|
|
10933
10986
|
createSolanaWallet,
|
|
10934
10987
|
createWallet,
|
|
10988
|
+
evmNetwork,
|
|
10935
10989
|
extractPaymentDetails,
|
|
10936
10990
|
formatFundingMessageCompact,
|
|
10937
10991
|
formatNeedsFundingMessage,
|
package/dist/index.d.cts
CHANGED
|
@@ -1164,7 +1164,9 @@ declare class APIError extends BlockrunError {
|
|
|
1164
1164
|
* BlockRun LLM Gateway Client.
|
|
1165
1165
|
*
|
|
1166
1166
|
* Provides access to multiple LLM providers (OpenAI, Anthropic, Google, etc.)
|
|
1167
|
-
* with automatic x402 micropayments on Base chain
|
|
1167
|
+
* with automatic x402 micropayments in USDC on Base (chain 8453) or, with
|
|
1168
|
+
* `apiUrl` pointed at arc.blockrun.ai, on Circle's Arc (chain 5042) — the
|
|
1169
|
+
* 402's `network` selects the chain (see EVM_NETWORKS in x402.ts).
|
|
1168
1170
|
* API base: https://blockrun.ai/api
|
|
1169
1171
|
*/
|
|
1170
1172
|
declare class LLMClient {
|
|
@@ -2312,16 +2314,51 @@ declare class BlockrunClient {
|
|
|
2312
2314
|
|
|
2313
2315
|
declare const BASE_CHAIN_ID = 8453;
|
|
2314
2316
|
declare const USDC_BASE: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2317
|
+
declare const ARC_CHAIN_ID = 5042;
|
|
2318
|
+
declare const USDC_ARC: "0x3600000000000000000000000000000000000000";
|
|
2319
|
+
/**
|
|
2320
|
+
* The EVM networks a BlockRun gateway settles on, keyed by the CAIP-2
|
|
2321
|
+
* `network` a 402 carries, each with the SDK's OWN values for that network's
|
|
2322
|
+
* USDC and its EIP-712 domain.
|
|
2323
|
+
*
|
|
2324
|
+
* Until 3.16.0 there was one domain — Base's — signed whatever the 402 said,
|
|
2325
|
+
* so against arc.blockrun.ai (eip155:5042) or testnet.blockrun.ai every
|
|
2326
|
+
* payment was a signature over the wrong domain: the facilitator recovered a
|
|
2327
|
+
* different signer and answered 401 after the SDK had reported a payment.
|
|
2328
|
+
*
|
|
2329
|
+
* The 402 SELECTS a network from this table; it never supplies the domain.
|
|
2330
|
+
* That keeps the rule the single constant enforced — a hostile 402's `extra`
|
|
2331
|
+
* cannot steer a signature onto another contract — while letting the same
|
|
2332
|
+
* SDK pay on every host. Arc's USDC is the chain's native token exposed as an
|
|
2333
|
+
* ERC-20 at 0x3600…0000, and its domain name is "USDC", not Base's "USD Coin".
|
|
2334
|
+
*/
|
|
2335
|
+
interface EvmNetwork {
|
|
2336
|
+
name: string;
|
|
2337
|
+
chainId: number;
|
|
2338
|
+
usdc: `0x${string}`;
|
|
2339
|
+
domain: {
|
|
2340
|
+
name: string;
|
|
2341
|
+
version: string;
|
|
2342
|
+
chainId: number;
|
|
2343
|
+
verifyingContract: `0x${string}`;
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
declare const EVM_NETWORKS: Readonly<Record<string, EvmNetwork>>;
|
|
2347
|
+
/** The network table entry for a 402's `network`, or a refusal that names what IS supported. */
|
|
2348
|
+
declare function evmNetwork(network: string): EvmNetwork;
|
|
2315
2349
|
declare const SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
2316
2350
|
declare const USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
2317
2351
|
interface CreatePaymentOptions {
|
|
2318
2352
|
resourceUrl?: string;
|
|
2319
2353
|
resourceDescription?: string;
|
|
2320
2354
|
maxTimeoutSeconds?: number;
|
|
2355
|
+
/** The 402's `extra`. Echoed nowhere: the domain comes from EVM_NETWORKS. */
|
|
2321
2356
|
extra?: {
|
|
2322
2357
|
name?: string;
|
|
2323
2358
|
version?: string;
|
|
2324
2359
|
};
|
|
2360
|
+
/** The 402's `asset`. Checked against the network's USDC; a mismatch is refused. */
|
|
2361
|
+
asset?: string;
|
|
2325
2362
|
extensions?: Record<string, unknown>;
|
|
2326
2363
|
}
|
|
2327
2364
|
/**
|
|
@@ -2331,7 +2368,7 @@ interface CreatePaymentOptions {
|
|
|
2331
2368
|
* @param fromAddress - Sender wallet address
|
|
2332
2369
|
* @param recipient - Payment recipient address
|
|
2333
2370
|
* @param amount - Amount in micro USDC (6 decimals)
|
|
2334
|
-
* @param network -
|
|
2371
|
+
* @param network - CAIP-2 network from the 402 (default: eip155:8453); must be in EVM_NETWORKS
|
|
2335
2372
|
* @param options - Additional options for resource info
|
|
2336
2373
|
* @returns Base64-encoded signed payment payload
|
|
2337
2374
|
*/
|
|
@@ -3014,7 +3051,7 @@ interface CostEntry {
|
|
|
3014
3051
|
model?: string;
|
|
3015
3052
|
/** Payer wallet address (EVM 0x... or Solana base58). */
|
|
3016
3053
|
wallet?: string;
|
|
3017
|
-
/** Network identifier — "eip155:8453" for Base
|
|
3054
|
+
/** Network identifier — "eip155:8453" for Base, "eip155:5042" for Arc, "solana-mainnet", etc. */
|
|
3018
3055
|
network?: string;
|
|
3019
3056
|
/** Caller kind for analytics — "LLMClient", "ImageClient", "AgentClient", ... */
|
|
3020
3057
|
client_kind?: string;
|
|
@@ -3243,4 +3280,4 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3243
3280
|
*/
|
|
3244
3281
|
declare function validateTopP(topP?: number): void;
|
|
3245
3282
|
|
|
3246
|
-
export { APIError, API_KEY_URL, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
3283
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
package/dist/index.d.ts
CHANGED
|
@@ -1164,7 +1164,9 @@ declare class APIError extends BlockrunError {
|
|
|
1164
1164
|
* BlockRun LLM Gateway Client.
|
|
1165
1165
|
*
|
|
1166
1166
|
* Provides access to multiple LLM providers (OpenAI, Anthropic, Google, etc.)
|
|
1167
|
-
* with automatic x402 micropayments on Base chain
|
|
1167
|
+
* with automatic x402 micropayments in USDC on Base (chain 8453) or, with
|
|
1168
|
+
* `apiUrl` pointed at arc.blockrun.ai, on Circle's Arc (chain 5042) — the
|
|
1169
|
+
* 402's `network` selects the chain (see EVM_NETWORKS in x402.ts).
|
|
1168
1170
|
* API base: https://blockrun.ai/api
|
|
1169
1171
|
*/
|
|
1170
1172
|
declare class LLMClient {
|
|
@@ -2312,16 +2314,51 @@ declare class BlockrunClient {
|
|
|
2312
2314
|
|
|
2313
2315
|
declare const BASE_CHAIN_ID = 8453;
|
|
2314
2316
|
declare const USDC_BASE: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2317
|
+
declare const ARC_CHAIN_ID = 5042;
|
|
2318
|
+
declare const USDC_ARC: "0x3600000000000000000000000000000000000000";
|
|
2319
|
+
/**
|
|
2320
|
+
* The EVM networks a BlockRun gateway settles on, keyed by the CAIP-2
|
|
2321
|
+
* `network` a 402 carries, each with the SDK's OWN values for that network's
|
|
2322
|
+
* USDC and its EIP-712 domain.
|
|
2323
|
+
*
|
|
2324
|
+
* Until 3.16.0 there was one domain — Base's — signed whatever the 402 said,
|
|
2325
|
+
* so against arc.blockrun.ai (eip155:5042) or testnet.blockrun.ai every
|
|
2326
|
+
* payment was a signature over the wrong domain: the facilitator recovered a
|
|
2327
|
+
* different signer and answered 401 after the SDK had reported a payment.
|
|
2328
|
+
*
|
|
2329
|
+
* The 402 SELECTS a network from this table; it never supplies the domain.
|
|
2330
|
+
* That keeps the rule the single constant enforced — a hostile 402's `extra`
|
|
2331
|
+
* cannot steer a signature onto another contract — while letting the same
|
|
2332
|
+
* SDK pay on every host. Arc's USDC is the chain's native token exposed as an
|
|
2333
|
+
* ERC-20 at 0x3600…0000, and its domain name is "USDC", not Base's "USD Coin".
|
|
2334
|
+
*/
|
|
2335
|
+
interface EvmNetwork {
|
|
2336
|
+
name: string;
|
|
2337
|
+
chainId: number;
|
|
2338
|
+
usdc: `0x${string}`;
|
|
2339
|
+
domain: {
|
|
2340
|
+
name: string;
|
|
2341
|
+
version: string;
|
|
2342
|
+
chainId: number;
|
|
2343
|
+
verifyingContract: `0x${string}`;
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
declare const EVM_NETWORKS: Readonly<Record<string, EvmNetwork>>;
|
|
2347
|
+
/** The network table entry for a 402's `network`, or a refusal that names what IS supported. */
|
|
2348
|
+
declare function evmNetwork(network: string): EvmNetwork;
|
|
2315
2349
|
declare const SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
2316
2350
|
declare const USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
2317
2351
|
interface CreatePaymentOptions {
|
|
2318
2352
|
resourceUrl?: string;
|
|
2319
2353
|
resourceDescription?: string;
|
|
2320
2354
|
maxTimeoutSeconds?: number;
|
|
2355
|
+
/** The 402's `extra`. Echoed nowhere: the domain comes from EVM_NETWORKS. */
|
|
2321
2356
|
extra?: {
|
|
2322
2357
|
name?: string;
|
|
2323
2358
|
version?: string;
|
|
2324
2359
|
};
|
|
2360
|
+
/** The 402's `asset`. Checked against the network's USDC; a mismatch is refused. */
|
|
2361
|
+
asset?: string;
|
|
2325
2362
|
extensions?: Record<string, unknown>;
|
|
2326
2363
|
}
|
|
2327
2364
|
/**
|
|
@@ -2331,7 +2368,7 @@ interface CreatePaymentOptions {
|
|
|
2331
2368
|
* @param fromAddress - Sender wallet address
|
|
2332
2369
|
* @param recipient - Payment recipient address
|
|
2333
2370
|
* @param amount - Amount in micro USDC (6 decimals)
|
|
2334
|
-
* @param network -
|
|
2371
|
+
* @param network - CAIP-2 network from the 402 (default: eip155:8453); must be in EVM_NETWORKS
|
|
2335
2372
|
* @param options - Additional options for resource info
|
|
2336
2373
|
* @returns Base64-encoded signed payment payload
|
|
2337
2374
|
*/
|
|
@@ -3014,7 +3051,7 @@ interface CostEntry {
|
|
|
3014
3051
|
model?: string;
|
|
3015
3052
|
/** Payer wallet address (EVM 0x... or Solana base58). */
|
|
3016
3053
|
wallet?: string;
|
|
3017
|
-
/** Network identifier — "eip155:8453" for Base
|
|
3054
|
+
/** Network identifier — "eip155:8453" for Base, "eip155:5042" for Arc, "solana-mainnet", etc. */
|
|
3018
3055
|
network?: string;
|
|
3019
3056
|
/** Caller kind for analytics — "LLMClient", "ImageClient", "AgentClient", ... */
|
|
3020
3057
|
client_kind?: string;
|
|
@@ -3243,4 +3280,4 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3243
3280
|
*/
|
|
3244
3281
|
declare function validateTopP(topP?: number): void;
|
|
3245
3282
|
|
|
3246
|
-
export { APIError, API_KEY_URL, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
|
3283
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, type BarResolution, type BlockRunAnthropicOptions, BlockrunClient, type BlockrunClientOptions, BlockrunError, type CallInitiatedResponse, type CallModel, type CallOptions, type CallStatusResponse, type ChatChoice, type ChatCompletionOptions, type ChatMessage, type ChatOptions, type ChatResponse, type ChatResponseWithCost, type ChatUsage, type CostEntry, type CostEstimate, type CreatePaymentOptions, EVM_NETWORKS, type EvmNetwork, type FunctionCall, type FunctionDefinition, type HistoryOptions, ImageClient, type ImageClientOptions, type ImageData, type ImageEditOptions, type ImageGenerateOptions, type ImageModel, type ImageResponse, KNOWN_PROVIDERS, LLMClient, type LLMClientOptions, type ListOptions, type MarketSession, type Model, MusicClient, type MusicClientOptions, type MusicGenerateOptions, type MusicResponse, NETWORK_ALIASES, type NewsSearchSource, OpenAI, type OpenAIChatCompletionChoice, type OpenAIChatCompletionChunk, type OpenAIChatCompletionParams, type OpenAIChatCompletionResponse, type OpenAIClientOptions, PHONE_PRICES, PORTAL_URL, PORTRAIT_ENROLLMENT_PRICE_USD, PaymentError, type PaymentLinks, type PhoneBuyOptions, type PhoneBuyResponse, PhoneClient, type PhoneClientOptions, type PhoneListResponse, type PhoneLookupResponse, type PhoneNumberRecord, type PhoneReleaseResponse, type PhoneRenewResponse, type PollOptions, PortraitClient, type PortraitClientOptions, type PortraitEnrollOptions, type PortraitEnrollResponse, type PriceBar, type PriceCategory, PriceClient, type PriceClientOptions, type PriceHistoryResponse, type PriceOptions, type PricePoint, RPC_PRICE_USD, type ResponseFormat, RetiredEndpointError, type RoutingDecision, type RoutingProfile, type RoutingTaskType, type RoutingTier, type RoutingTierConfig, type RpcBatchRequest, RpcClient, type RpcClientOptions, type RpcError, type RpcNetwork, type RpcResponse, type RssSearchSource, SOLANA_NETWORK, SOLANA_WALLET_FILE as SOLANA_WALLET_FILE_PATH, SUPPORTED_NETWORKS, SearchClient, type SearchClientOptions, type SearchOptions, type SearchParameters, type SearchResult, type SearchSource, type SearchUsage, type SmartChatCompletionOptions, type SmartChatCompletionResponse, type SmartChatOptions, type SmartChatResponse, SolanaLLMClient, type SolanaLLMClientOptions, type SolanaWalletInfo, type SoundEffectOptions, type SpeechAudio, SpeechClient, type SpeechClientOptions, type SpeechGenerateOptions, type SpeechModel, type SpeechResponse, type SpeechVoice, type Spending, type SpendingReport, type StockMarket, SurfClient, type SurfClientOptions, type SymbolListResponse, type Tool, type ToolCall, type ToolChoice, USDC_ARC, USDC_BASE, USDC_BASE_CONTRACT, USDC_SOLANA, VideoClient, type VideoClientOptions, type VideoClip, type VideoGenerateOptions, type VideoModel, type VideoResponse, VoiceClient, type VoiceClientOptions, type VoiceInfo, type VoicePreset, WALLET_DIR_PATH, WALLET_FILE_PATH, type WalletInfo, type WebSearchSource, type XSearchSource, clearCache, createPaymentPayload, createSolanaPaymentPayload, createSolanaWallet, createWallet, LLMClient as default, evmNetwork, extractPaymentDetails, formatFundingMessageCompact, formatNeedsFundingMessage, formatSolanaWalletMigrationNotice, formatWalletCreatedMessage, formatWalletMigrationNotice, getCached, getCachedByRequest, getCostLogSummary, getCostSummary, getEip681Uri, getOrCreateSolanaWallet, getOrCreateWallet, getPaymentLinks, getWalletAddress, importSolanaWallet, importWallet, listDiscoveredSolanaWallets, listDiscoveredWallets, loadSolanaWallet, loadWallet, logCost, parsePaymentRequired, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|
package/dist/index.js
CHANGED
|
@@ -126,9 +126,12 @@ function sanitizeErrorResponse(errorBody) {
|
|
|
126
126
|
return { message: "API request failed" };
|
|
127
127
|
}
|
|
128
128
|
const body = errorBody;
|
|
129
|
+
const detail = typeof body.message === "string" && body.message !== body.error ? body.message : void 0;
|
|
129
130
|
return {
|
|
130
131
|
message: typeof body.error === "string" ? body.error : "API request failed",
|
|
131
|
-
code: typeof body.code === "string" ? body.code : void 0
|
|
132
|
+
code: typeof body.code === "string" ? body.code : void 0,
|
|
133
|
+
...detail ? { detail } : {},
|
|
134
|
+
...typeof body.hint === "string" ? { hint: body.hint } : {}
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
137
|
function validateResourceUrl(url, baseUrl) {
|
|
@@ -4192,6 +4195,42 @@ async function loadSplToken(what) {
|
|
|
4192
4195
|
// src/x402.ts
|
|
4193
4196
|
var BASE_CHAIN_ID = 8453;
|
|
4194
4197
|
var USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
4198
|
+
var ARC_CHAIN_ID = 5042;
|
|
4199
|
+
var USDC_ARC = "0x3600000000000000000000000000000000000000";
|
|
4200
|
+
var EVM_NETWORKS = {
|
|
4201
|
+
"eip155:8453": {
|
|
4202
|
+
name: "Base",
|
|
4203
|
+
chainId: BASE_CHAIN_ID,
|
|
4204
|
+
usdc: USDC_BASE,
|
|
4205
|
+
domain: { name: "USD Coin", version: "2", chainId: BASE_CHAIN_ID, verifyingContract: USDC_BASE }
|
|
4206
|
+
},
|
|
4207
|
+
"eip155:5042": {
|
|
4208
|
+
name: "Arc",
|
|
4209
|
+
chainId: ARC_CHAIN_ID,
|
|
4210
|
+
usdc: USDC_ARC,
|
|
4211
|
+
domain: { name: "USDC", version: "2", chainId: ARC_CHAIN_ID, verifyingContract: USDC_ARC }
|
|
4212
|
+
},
|
|
4213
|
+
"eip155:84532": {
|
|
4214
|
+
name: "Base Sepolia",
|
|
4215
|
+
chainId: 84532,
|
|
4216
|
+
usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
4217
|
+
domain: {
|
|
4218
|
+
name: "USDC",
|
|
4219
|
+
version: "2",
|
|
4220
|
+
chainId: 84532,
|
|
4221
|
+
verifyingContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
};
|
|
4225
|
+
function evmNetwork(network) {
|
|
4226
|
+
const net = EVM_NETWORKS[network];
|
|
4227
|
+
if (!net) {
|
|
4228
|
+
throw new Error(
|
|
4229
|
+
`Unsupported x402 network "${network}": this SDK signs USDC payments on ${Object.keys(EVM_NETWORKS).join(", ")}`
|
|
4230
|
+
);
|
|
4231
|
+
}
|
|
4232
|
+
return net;
|
|
4233
|
+
}
|
|
4195
4234
|
var SOLANA_NETWORK = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
4196
4235
|
var USDC_SOLANA = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
4197
4236
|
var SOLANA_USDC_DECIMALS = 6;
|
|
@@ -4235,12 +4274,6 @@ async function getBlockhashEntry(connection, rpcUrl, forceRefresh) {
|
|
|
4235
4274
|
trimOldest(blockhashCache, MAX_TRACKED_ENDPOINTS);
|
|
4236
4275
|
return entry;
|
|
4237
4276
|
}
|
|
4238
|
-
var USDC_DOMAIN = {
|
|
4239
|
-
name: "USD Coin",
|
|
4240
|
-
version: "2",
|
|
4241
|
-
chainId: BASE_CHAIN_ID,
|
|
4242
|
-
verifyingContract: USDC_BASE
|
|
4243
|
-
};
|
|
4244
4277
|
var TRANSFER_TYPES = {
|
|
4245
4278
|
TransferWithAuthorization: [
|
|
4246
4279
|
{ name: "from", type: "address" },
|
|
@@ -4271,7 +4304,13 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
4271
4304
|
const validAfter = now - 600;
|
|
4272
4305
|
const validBefore = now + (options.maxTimeoutSeconds || 300);
|
|
4273
4306
|
const nonce = createNonce();
|
|
4274
|
-
const
|
|
4307
|
+
const net = evmNetwork(network);
|
|
4308
|
+
if (options.asset && options.asset.toLowerCase() !== net.usdc.toLowerCase()) {
|
|
4309
|
+
throw new Error(
|
|
4310
|
+
`x402 asset mismatch: the 402 asks for ${options.asset} on ${network}, but this SDK only pays USDC there (${net.usdc})`
|
|
4311
|
+
);
|
|
4312
|
+
}
|
|
4313
|
+
const domain = net.domain;
|
|
4275
4314
|
const signature = await signTypedData({
|
|
4276
4315
|
privateKey,
|
|
4277
4316
|
domain,
|
|
@@ -4297,10 +4336,10 @@ async function createPaymentPayload(privateKey, fromAddress, recipient, amount,
|
|
|
4297
4336
|
scheme: "exact",
|
|
4298
4337
|
network,
|
|
4299
4338
|
amount,
|
|
4300
|
-
asset:
|
|
4339
|
+
asset: net.usdc,
|
|
4301
4340
|
payTo: recipient,
|
|
4302
4341
|
maxTimeoutSeconds: options.maxTimeoutSeconds || 300,
|
|
4303
|
-
extra: { name:
|
|
4342
|
+
extra: { name: net.domain.name, version: net.domain.version }
|
|
4304
4343
|
},
|
|
4305
4344
|
payload: {
|
|
4306
4345
|
signature,
|
|
@@ -4500,7 +4539,7 @@ function getCostSummary() {
|
|
|
4500
4539
|
}
|
|
4501
4540
|
|
|
4502
4541
|
// src/version.ts
|
|
4503
|
-
var SDK_VERSION = "3.
|
|
4542
|
+
var SDK_VERSION = "3.16.0";
|
|
4504
4543
|
var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
|
|
4505
4544
|
|
|
4506
4545
|
// src/client.ts
|
|
@@ -4960,6 +4999,7 @@ var LLMClient = class _LLMClient {
|
|
|
4960
4999
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
4961
5000
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
4962
5001
|
extra: details.extra,
|
|
5002
|
+
asset: details.asset,
|
|
4963
5003
|
extensions
|
|
4964
5004
|
}
|
|
4965
5005
|
);
|
|
@@ -5045,6 +5085,7 @@ var LLMClient = class _LLMClient {
|
|
|
5045
5085
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5046
5086
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5047
5087
|
extra: details.extra,
|
|
5088
|
+
asset: details.asset,
|
|
5048
5089
|
extensions
|
|
5049
5090
|
}
|
|
5050
5091
|
);
|
|
@@ -5256,6 +5297,7 @@ var LLMClient = class _LLMClient {
|
|
|
5256
5297
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5257
5298
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5258
5299
|
extra: details.extra,
|
|
5300
|
+
asset: details.asset,
|
|
5259
5301
|
extensions
|
|
5260
5302
|
}
|
|
5261
5303
|
);
|
|
@@ -5403,6 +5445,7 @@ var LLMClient = class _LLMClient {
|
|
|
5403
5445
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
5404
5446
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
5405
5447
|
extra: details.extra,
|
|
5448
|
+
asset: details.asset,
|
|
5406
5449
|
extensions
|
|
5407
5450
|
}
|
|
5408
5451
|
);
|
|
@@ -6196,6 +6239,7 @@ var ImageClient = class {
|
|
|
6196
6239
|
resourceDescription: details.resource?.description || "BlockRun Image Generation",
|
|
6197
6240
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
6198
6241
|
extra: details.extra,
|
|
6242
|
+
asset: details.asset,
|
|
6199
6243
|
extensions
|
|
6200
6244
|
}
|
|
6201
6245
|
);
|
|
@@ -8803,7 +8847,8 @@ var BlockrunClient = class {
|
|
|
8803
8847
|
details.maxTimeoutSeconds || 0,
|
|
8804
8848
|
opts.maxTimeoutSeconds || 300
|
|
8805
8849
|
),
|
|
8806
|
-
extra: details.extra
|
|
8850
|
+
extra: details.extra,
|
|
8851
|
+
asset: details.asset
|
|
8807
8852
|
}
|
|
8808
8853
|
);
|
|
8809
8854
|
}
|
|
@@ -10734,6 +10779,7 @@ var AnthropicClient = class {
|
|
|
10734
10779
|
resourceDescription: details.resource?.description || "BlockRun AI API call",
|
|
10735
10780
|
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
10736
10781
|
extra: details.extra,
|
|
10782
|
+
asset: details.asset,
|
|
10737
10783
|
extensions
|
|
10738
10784
|
}
|
|
10739
10785
|
);
|
|
@@ -10775,10 +10821,12 @@ var AnthropicClient = class {
|
|
|
10775
10821
|
export {
|
|
10776
10822
|
APIError,
|
|
10777
10823
|
API_KEY_URL,
|
|
10824
|
+
ARC_CHAIN_ID,
|
|
10778
10825
|
AnthropicClient,
|
|
10779
10826
|
BASE_CHAIN_ID,
|
|
10780
10827
|
BlockrunClient,
|
|
10781
10828
|
BlockrunError,
|
|
10829
|
+
EVM_NETWORKS,
|
|
10782
10830
|
ImageClient,
|
|
10783
10831
|
KNOWN_PROVIDERS,
|
|
10784
10832
|
LLMClient,
|
|
@@ -10802,6 +10850,7 @@ export {
|
|
|
10802
10850
|
SolanaLLMClient,
|
|
10803
10851
|
SpeechClient,
|
|
10804
10852
|
SurfClient,
|
|
10853
|
+
USDC_ARC,
|
|
10805
10854
|
USDC_BASE,
|
|
10806
10855
|
USDC_BASE_CONTRACT,
|
|
10807
10856
|
USDC_SOLANA,
|
|
@@ -10815,6 +10864,7 @@ export {
|
|
|
10815
10864
|
createSolanaWallet,
|
|
10816
10865
|
createWallet,
|
|
10817
10866
|
client_default as default,
|
|
10867
|
+
evmNetwork,
|
|
10818
10868
|
extractPaymentDetails,
|
|
10819
10869
|
formatFundingMessageCompact,
|
|
10820
10870
|
formatNeedsFundingMessage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockrun/llm",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
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",
|