@blockrun/llm 3.19.1 → 3.20.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 +260 -66
- package/dist/index.cjs +2207 -203
- package/dist/index.d.cts +319 -21
- package/dist/index.d.ts +319 -21
- package/dist/index.js +2203 -203
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import * as _anthropic_ai_sdk from '@anthropic-ai/sdk';
|
|
2
2
|
|
|
3
|
-
/** Account billing is independent of the wallet payment chain. */
|
|
4
|
-
interface ApiKeyOptions {
|
|
5
|
-
/** BlockRun account key. Defaults to BLOCKRUN_API_KEY unless a privateKey is explicit. */
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
}
|
|
8
|
-
declare const API_KEY_URL = "https://api.blockrun.ai";
|
|
9
|
-
declare const PORTAL_URL = "https://user.blockrun.ai";
|
|
10
|
-
|
|
11
3
|
/**
|
|
12
4
|
* Smart Router Types
|
|
13
5
|
*
|
|
@@ -1180,6 +1172,33 @@ interface PollOptions {
|
|
|
1180
1172
|
/** Sleep between poll attempts (default 5000 = 5 s). */
|
|
1181
1173
|
intervalMs?: number;
|
|
1182
1174
|
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Whether a failed request may be retried, or sent to another model, without
|
|
1177
|
+
* risking a second charge. The request layer that knows whether a payment was
|
|
1178
|
+
* sent attaches it to the error it throws; read it with
|
|
1179
|
+
* {@link retryDisposition}.
|
|
1180
|
+
*
|
|
1181
|
+
* - `"unpaid"`: nothing that could be charged was sent for this request: the
|
|
1182
|
+
* unpaid first request of an x402 exchange (and its 402 challenge), the
|
|
1183
|
+
* signing step, or, with an API key, the account API's explicit 4xx
|
|
1184
|
+
* refusal. A retry or a fallback model pays at most once.
|
|
1185
|
+
* - `"paid-or-in-doubt"`: a payment was sent (with an API key, the billed
|
|
1186
|
+
* request itself) and may have been charged: a timeout, an abort or a
|
|
1187
|
+
* network error after it was sent, any non-2xx answer to it, or a 2xx whose
|
|
1188
|
+
* body could not be read. A retry or a fallback model could pay twice, so
|
|
1189
|
+
* the SDK does neither.
|
|
1190
|
+
*
|
|
1191
|
+
* An error that carries no disposition is treated as `"paid-or-in-doubt"`.
|
|
1192
|
+
*/
|
|
1193
|
+
type RetryDisposition = "unpaid" | "paid-or-in-doubt";
|
|
1194
|
+
/**
|
|
1195
|
+
* The {@link RetryDisposition} the SDK attached to an error, or undefined
|
|
1196
|
+
* when it attached none (then treat the error as `"paid-or-in-doubt"`).
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* if (retryDisposition(err) === "unpaid") await retryLater();
|
|
1200
|
+
*/
|
|
1201
|
+
declare function retryDisposition(err: unknown): RetryDisposition | undefined;
|
|
1183
1202
|
declare class BlockrunError extends Error {
|
|
1184
1203
|
constructor(message: string);
|
|
1185
1204
|
}
|
|
@@ -1204,6 +1223,14 @@ declare class APIError extends BlockrunError {
|
|
|
1204
1223
|
constructor(message: string, statusCode: number, response?: unknown);
|
|
1205
1224
|
}
|
|
1206
1225
|
|
|
1226
|
+
/** Account billing is independent of the wallet payment chain. */
|
|
1227
|
+
interface ApiKeyOptions {
|
|
1228
|
+
/** BlockRun account key. Defaults to BLOCKRUN_API_KEY unless a privateKey is explicit. */
|
|
1229
|
+
apiKey?: string;
|
|
1230
|
+
}
|
|
1231
|
+
declare const API_KEY_URL = "https://api.blockrun.ai";
|
|
1232
|
+
declare const PORTAL_URL = "https://user.blockrun.ai";
|
|
1233
|
+
|
|
1207
1234
|
/**
|
|
1208
1235
|
* BlockRun LLM Gateway Client.
|
|
1209
1236
|
*
|
|
@@ -1300,10 +1327,13 @@ declare class LLMClient {
|
|
|
1300
1327
|
* Full chat completion interface (OpenAI-compatible).
|
|
1301
1328
|
*
|
|
1302
1329
|
* When `fallbackModels` is set, transient failures (timeouts, network
|
|
1303
|
-
* errors, 5xx) on the primary model trigger a retry against the next
|
|
1304
|
-
* model in the list before raising
|
|
1305
|
-
*
|
|
1306
|
-
*
|
|
1330
|
+
* errors, 429, 5xx) on the primary model trigger a retry against the next
|
|
1331
|
+
* model in the list before raising, but only while no payment has been
|
|
1332
|
+
* sent for it (the error's {@link RetryDisposition} is `"unpaid"`). Once a
|
|
1333
|
+
* payment was sent, any failure propagates: the next model would be a
|
|
1334
|
+
* second charge. 4xx errors and PaymentError also propagate immediately —
|
|
1335
|
+
* those aren't "swap upstream and retry" situations. Each fallback hop
|
|
1336
|
+
* logs one stderr line.
|
|
1307
1337
|
*
|
|
1308
1338
|
* @param model - Primary model ID
|
|
1309
1339
|
* @param messages - Array of messages with role and content
|
|
@@ -1331,12 +1361,37 @@ declare class LLMClient {
|
|
|
1331
1361
|
private parseChatResponse;
|
|
1332
1362
|
/**
|
|
1333
1363
|
* Make a request with automatic x402 payment handling.
|
|
1364
|
+
*
|
|
1365
|
+
* Every error it throws carries a {@link RetryDisposition}, which is what
|
|
1366
|
+
* {@link LLMClient.chatCompletion}'s fallback walk honours: errors of the
|
|
1367
|
+
* unpaid first request (and its one 502/503 retry), of the 402 challenge
|
|
1368
|
+
* and of signing are `"unpaid"`; anything after the signed payment was sent
|
|
1369
|
+
* is `"paid-or-in-doubt"`. With an API key the request itself is billed, so
|
|
1370
|
+
* only the account API's explicit 4xx refusal is `"unpaid"`.
|
|
1334
1371
|
*/
|
|
1335
1372
|
private requestWithPayment;
|
|
1373
|
+
/**
|
|
1374
|
+
* Send a request that carries no payment, marking what it throws with its
|
|
1375
|
+
* {@link RetryDisposition}: `"unpaid"` with a wallet; with an API key, see
|
|
1376
|
+
* {@link accountErrorDisposition} (the request itself is billed).
|
|
1377
|
+
*/
|
|
1378
|
+
private sendUnpaid;
|
|
1379
|
+
/**
|
|
1380
|
+
* Parse a response to a request that carried no payment: the free tier,
|
|
1381
|
+
* or, with an API key, the billed request itself.
|
|
1382
|
+
*/
|
|
1383
|
+
private parseUnpaidChatResponse;
|
|
1336
1384
|
/**
|
|
1337
1385
|
* Handle 402 response: parse requirements, sign payment, retry.
|
|
1386
|
+
*
|
|
1387
|
+
* Anything thrown before the signed payment is sent is `"unpaid"`; anything
|
|
1388
|
+
* after it, `"paid-or-in-doubt"` (see {@link RetryDisposition}).
|
|
1338
1389
|
*/
|
|
1339
1390
|
private handlePaymentAndRetry;
|
|
1391
|
+
/** Read a 402's requirements and sign the exact payment for them. Sends nothing. */
|
|
1392
|
+
private signFrom402;
|
|
1393
|
+
/** Send the signed payment and read the answer. The payment may settle from here on. */
|
|
1394
|
+
private sendPaid;
|
|
1340
1395
|
/**
|
|
1341
1396
|
* Sign a payment header and return the PAYMENT-SIGNATURE value.
|
|
1342
1397
|
* Extracted to share logic between streaming and non-streaming flows.
|
|
@@ -2727,10 +2782,13 @@ interface SolanaBatchOptions {
|
|
|
2727
2782
|
*/
|
|
2728
2783
|
operators: string[];
|
|
2729
2784
|
/**
|
|
2730
|
-
*
|
|
2731
|
-
* deposit
|
|
2732
|
-
*
|
|
2733
|
-
*
|
|
2785
|
+
* Most escrow, in USD, this client keeps at stake in one channel: the
|
|
2786
|
+
* deposit not yet settled on-chain. A top-up is allowed while
|
|
2787
|
+
* `(deposit - settled) + topUp <= maxDeposit`, so a long-lived channel keeps
|
|
2788
|
+
* topping up as the gateway settles what it charged. This is the most an
|
|
2789
|
+
* operator could claim beyond what has already been settled without
|
|
2790
|
+
* another signature from you. Accepts `"$5"`, `"5"` or `5`. Default `"$1"`
|
|
2791
|
+
* (the `@x402/svm` default).
|
|
2734
2792
|
*/
|
|
2735
2793
|
maxDeposit?: string | number;
|
|
2736
2794
|
/**
|
|
@@ -2741,6 +2799,205 @@ interface SolanaBatchOptions {
|
|
|
2741
2799
|
* by scanning the chain for it.
|
|
2742
2800
|
*/
|
|
2743
2801
|
channelStore?: string | false;
|
|
2802
|
+
/**
|
|
2803
|
+
* How a call rides out an HTTP 429 (rate limited, or channel capacity
|
|
2804
|
+
* exhausted) on a batch payment before it pays with `exact`. The call waits
|
|
2805
|
+
* for `Retry-After` (seconds or an HTTP date), or 1s, 2s, 4s... with jitter
|
|
2806
|
+
* when there is none (or when it is not a finite delay of at most a day),
|
|
2807
|
+
* then tries again: a 429 without a receipt by replaying the identical
|
|
2808
|
+
* payment, one that proves nothing was broadcast with a new payment. Other
|
|
2809
|
+
* calls for the same wallet wait out the same cooldown instead of sending
|
|
2810
|
+
* new channel opens; that shared cooldown never lasts longer than
|
|
2811
|
+
* `maxWaitMs`.
|
|
2812
|
+
*/
|
|
2813
|
+
rateLimit?: {
|
|
2814
|
+
/** Batch payment attempts per call, the first one included. Default 3. */
|
|
2815
|
+
maxAttempts?: number;
|
|
2816
|
+
/** Most time, in ms, one call spends waiting on 429s before it pays `exact`. Default 60000. */
|
|
2817
|
+
maxWaitMs?: number;
|
|
2818
|
+
};
|
|
2819
|
+
/**
|
|
2820
|
+
* Called for every batch fallback, 429 backoff, recovery and channel
|
|
2821
|
+
* re-read, in addition to the one-line log the SDK writes to stderr for each.
|
|
2822
|
+
* A callback that throws, or returns a promise that rejects, is logged and
|
|
2823
|
+
* ignored; it never affects the payment, and its promise is not awaited.
|
|
2824
|
+
*/
|
|
2825
|
+
onEvent?: (event: SolanaBatchEvent) => void | PromiseLike<void>;
|
|
2826
|
+
}
|
|
2827
|
+
/** Default {@link SolanaBatchOptions.rateLimit}. */
|
|
2828
|
+
declare const DEFAULT_BATCH_RATE_LIMIT: {
|
|
2829
|
+
readonly maxAttempts: 3;
|
|
2830
|
+
readonly maxWaitMs: 60000;
|
|
2831
|
+
};
|
|
2832
|
+
/**
|
|
2833
|
+
* One observable batch-settlement event.
|
|
2834
|
+
*
|
|
2835
|
+
* - `fallback`: this call pays with `exact`. `reason` says why. Only ever
|
|
2836
|
+
* when no batch payment of this call can have been charged.
|
|
2837
|
+
* - `backoff`: this call is waiting before it retries batch, after a 429
|
|
2838
|
+
* (`reason: "rate_limited"`) or because another call for the wallet hit one
|
|
2839
|
+
* (`reason: "cooldown"`).
|
|
2840
|
+
* - `recovered`: a call that backed off was then paid with batch, or its
|
|
2841
|
+
* fresh challenge after the wait was served without a payment (`reason:
|
|
2842
|
+
* "served_unpaid_on_rechallenge"`: that response is the call's result, and
|
|
2843
|
+
* nothing was paid).
|
|
2844
|
+
* - `unresolved`: this call is raised as {@link BatchPaymentUnresolvedError},
|
|
2845
|
+
* not paid with `exact` or any fallback model, because a batch payment it
|
|
2846
|
+
* sent may have been charged and got no definitive answer. `reason` is a
|
|
2847
|
+
* {@link BatchUnresolvedReason}.
|
|
2848
|
+
* - `resync`: the channel was re-read from the chain because the SDK could
|
|
2849
|
+
* not trust its record (a deposit with no clean answer, including a 429
|
|
2850
|
+
* without a receipt, a receipt that was missing or rebuilt, or a pending
|
|
2851
|
+
* deposit left by a process that died).
|
|
2852
|
+
* `reason` says which; `detail` says what the chain showed.
|
|
2853
|
+
*/
|
|
2854
|
+
interface SolanaBatchEvent {
|
|
2855
|
+
type: "fallback" | "backoff" | "recovered" | "resync" | "unresolved";
|
|
2856
|
+
/**
|
|
2857
|
+
* A short, stable code: `rate_limited`, `cooldown`, `not_offered`,
|
|
2858
|
+
* `client_signed_not_supported`, `channel_busy`, `untrusted_operator`, `deposit_over_cap`,
|
|
2859
|
+
* `channel_pending`, `closed_during_call`, `peer_dependency_missing`, `payment_creation_failed`,
|
|
2860
|
+
* `wallet_config_conflict`, `channel_store_locked`, `payment_required`,
|
|
2861
|
+
* `channel_resync_pending`, `channel_resync_failed`, `channel_unreadable`,
|
|
2862
|
+
* `deposit_journal_unreadable`, `deposit_journal_failed`,
|
|
2863
|
+
* `served_unpaid_on_rechallenge` or `batch_cancelled` (`recovered` events), or one of the gateway's refusal codes the
|
|
2864
|
+
* SDK recognises (`batch_payer_not_allowed`, `batch_payer_not_admitted`,
|
|
2865
|
+
* `batch_admission_paused`, `batch_server_signed_only`, `batch_unavailable`,
|
|
2866
|
+
* `batch_channel_limit`, `PAYMENT_VERIFICATION_UNAVAILABLE`). An `unresolved` event's reason is a
|
|
2867
|
+
* {@link BatchUnresolvedReason}. A `resync` event's reason is
|
|
2868
|
+
* `deposit_unanswered`, `deposit_failed`, `deposit_rate_limited`,
|
|
2869
|
+
* `deposit_refused`, `receipt_missing`, `receipt_unreconciled`,
|
|
2870
|
+
* `orphaned_deposit`, `deposit_unrecorded` or `channel_unusable`.
|
|
2871
|
+
*/
|
|
2872
|
+
reason: string;
|
|
2873
|
+
/** HTTP status of the gateway answer behind the event, when there was one. */
|
|
2874
|
+
status?: number;
|
|
2875
|
+
/** The gateway's or facilitator's error code, when it named one. */
|
|
2876
|
+
errorReason?: string;
|
|
2877
|
+
/** How long this call waits (backoff), or would have had to wait (fallback). */
|
|
2878
|
+
retryAfterMs?: number;
|
|
2879
|
+
/** Which batch payment attempt of this call the event belongs to (1-based). */
|
|
2880
|
+
attempt?: number;
|
|
2881
|
+
/** Free-text detail, such as the underlying error message. */
|
|
2882
|
+
detail?: string;
|
|
2883
|
+
/** The paying wallet's address. */
|
|
2884
|
+
wallet: string;
|
|
2885
|
+
/** When it happened, in ms since the epoch. */
|
|
2886
|
+
at: number;
|
|
2887
|
+
}
|
|
2888
|
+
/** Batch-settlement counters for one client, from {@link SolanaLLMClient.getBatchStats}. */
|
|
2889
|
+
interface SolanaBatchStats {
|
|
2890
|
+
/** Calls that paid with `exact` instead of batch. */
|
|
2891
|
+
fallbacks: number;
|
|
2892
|
+
/** {@link fallbacks}, split by {@link SolanaBatchEvent.reason}. */
|
|
2893
|
+
fallbacksByReason: Record<string, number>;
|
|
2894
|
+
/** Waits before a batch retry (own 429s and shared cooldowns). */
|
|
2895
|
+
backoffs: number;
|
|
2896
|
+
/** Batch payments sent again after a 429: a new payment, or the one replay of a receipt-less 429. */
|
|
2897
|
+
retries: number;
|
|
2898
|
+
/**
|
|
2899
|
+
* Calls paid with batch after at least one backoff, or served without a
|
|
2900
|
+
* payment by their fresh challenge after one (`served_unpaid_on_rechallenge`).
|
|
2901
|
+
*/
|
|
2902
|
+
recoveries: number;
|
|
2903
|
+
/** Times the channel record was re-read from the chain. */
|
|
2904
|
+
resyncs: number;
|
|
2905
|
+
/**
|
|
2906
|
+
* Calls raised as {@link BatchPaymentUnresolvedError}: a batch payment they
|
|
2907
|
+
* sent may have been charged, so nothing paid for them again.
|
|
2908
|
+
*/
|
|
2909
|
+
unresolved: number;
|
|
2910
|
+
/** {@link unresolved}, split by {@link BatchUnresolvedReason}. */
|
|
2911
|
+
unresolvedByReason: Record<string, number>;
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Why a batch payment is left in doubt; see {@link BatchPaymentUnresolvedError}.
|
|
2915
|
+
*
|
|
2916
|
+
* - `replay_unresolved`: a 429 without a receipt. Its one byte-identical
|
|
2917
|
+
* replay got no definitive success receipt (a 402, `duplicate_settlement`,
|
|
2918
|
+
* another 429, a 5xx, a timeout...), or `batch.rateLimit` left no room to
|
|
2919
|
+
* replay it.
|
|
2920
|
+
* - `ambiguous_rate_limit`: a 429 whose receipt does not prove nothing was
|
|
2921
|
+
* broadcast (one that says it was charged, `settlement_pending`, or one
|
|
2922
|
+
* naming a transaction).
|
|
2923
|
+
* - `no_response`: sending it threw (a timeout, an abort, a network error),
|
|
2924
|
+
* whatever the error's code: the request may have reached the gateway.
|
|
2925
|
+
* - `outcome_unknown`: any other answer that neither serves the call nor
|
|
2926
|
+
* proves nothing was charged: a 5xx without a recognised refusal code, an
|
|
2927
|
+
* unrecognised 4xx, or a non-2xx whose receipt names a transaction, says
|
|
2928
|
+
* `settlement_pending`, or says it succeeded.
|
|
2929
|
+
* - `duplicate_settlement`: the first answer was a 402 naming
|
|
2930
|
+
* `duplicate_settlement`: the gateway had already reserved this request id,
|
|
2931
|
+
* so another copy of the payment reached it and may have been charged.
|
|
2932
|
+
*/
|
|
2933
|
+
type BatchUnresolvedReason = "replay_unresolved" | "ambiguous_rate_limit" | "no_response" | "outcome_unknown" | "duplicate_settlement";
|
|
2934
|
+
/** What a batch payment carried: a channel open, a top-up of the channel, or an authorization alone. */
|
|
2935
|
+
type BatchPayloadKind = "open" | "top-up" | "authorization";
|
|
2936
|
+
/**
|
|
2937
|
+
* A batch payment this call sent may have been charged, and never got a
|
|
2938
|
+
* definitive answer. Reported as an `unresolved` event with the same
|
|
2939
|
+
* `reason` (see {@link BatchUnresolvedReason}).
|
|
2940
|
+
*
|
|
2941
|
+
* A {@link PaymentError} whose {@link RetryDisposition} is
|
|
2942
|
+
* `"paid-or-in-doubt"`, never transient: the SDK does not pay for the call
|
|
2943
|
+
* again, not with `exact`, not with a new batch payment, and not by moving
|
|
2944
|
+
* on to `fallbackModels` (including the chain `smartChat()` fills in). Any
|
|
2945
|
+
* retry is yours to make, and it is a new payment.
|
|
2946
|
+
*
|
|
2947
|
+
* When it carried a deposit (`payloadKind` `open` or `top-up`), the deposit
|
|
2948
|
+
* is in doubt too: the SDK signs no other deposit for that wallet's channels
|
|
2949
|
+
* until a chain read at `finalized` commitment settles it.
|
|
2950
|
+
*/
|
|
2951
|
+
declare class BatchPaymentUnresolvedError extends PaymentError {
|
|
2952
|
+
/** The {@link SolanaBatchEvent.reason} of the `unresolved` event reported with it. */
|
|
2953
|
+
readonly reason: BatchUnresolvedReason;
|
|
2954
|
+
/** The paying wallet's address. */
|
|
2955
|
+
readonly wallet: string;
|
|
2956
|
+
/** The request id of the payment that may have been charged. */
|
|
2957
|
+
readonly requestId?: string;
|
|
2958
|
+
/** The channel it paid into. */
|
|
2959
|
+
readonly channelId?: string;
|
|
2960
|
+
/** What it carried. */
|
|
2961
|
+
readonly payloadKind?: BatchPayloadKind;
|
|
2962
|
+
/** HTTP status of the gateway's last answer to it, when there was one. */
|
|
2963
|
+
readonly status?: number;
|
|
2964
|
+
/** Whether it carried a deposit, which is now in doubt as well. */
|
|
2965
|
+
readonly depositInDoubt: boolean;
|
|
2966
|
+
constructor(init: {
|
|
2967
|
+
reason: BatchUnresolvedReason;
|
|
2968
|
+
wallet: string;
|
|
2969
|
+
requestId?: string;
|
|
2970
|
+
channelId?: string;
|
|
2971
|
+
payloadKind?: BatchPayloadKind;
|
|
2972
|
+
status?: number;
|
|
2973
|
+
detail?: string;
|
|
2974
|
+
cause?: unknown;
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
/**
|
|
2978
|
+
* `closeBatchChannel()` did not close anything, and should be called again
|
|
2979
|
+
* later:
|
|
2980
|
+
* - `call_in_flight`: a batch call for the wallet is still running (it may
|
|
2981
|
+
* be waiting out a 429 before its retry or replay);
|
|
2982
|
+
* - `deposit_in_doubt`: a deposit the wallet sent (an open or top-up) has
|
|
2983
|
+
* not been settled yet. It settles once a `finalized` chain read shows it
|
|
2984
|
+
* landed, or once the finalized chain is past its last valid block,
|
|
2985
|
+
* usually a few minutes after it was sent.
|
|
2986
|
+
*
|
|
2987
|
+
* Not a payment error: nothing was sent.
|
|
2988
|
+
*/
|
|
2989
|
+
declare class BatchCloseDeferredError extends BlockrunError {
|
|
2990
|
+
readonly reason: "call_in_flight" | "deposit_in_doubt";
|
|
2991
|
+
/** The paying wallet's address. */
|
|
2992
|
+
readonly wallet: string;
|
|
2993
|
+
/** The channels whose deposit is in doubt (`deposit_in_doubt`). */
|
|
2994
|
+
readonly channelIds: string[];
|
|
2995
|
+
constructor(init: {
|
|
2996
|
+
reason: "call_in_flight" | "deposit_in_doubt";
|
|
2997
|
+
wallet: string;
|
|
2998
|
+
channelIds?: string[];
|
|
2999
|
+
detail: string;
|
|
3000
|
+
});
|
|
2744
3001
|
}
|
|
2745
3002
|
|
|
2746
3003
|
interface SolanaLLMClientOptions extends ApiKeyOptions {
|
|
@@ -2794,11 +3051,28 @@ declare class SolanaLLMClient {
|
|
|
2794
3051
|
/**
|
|
2795
3052
|
* Close this wallet's batch-settlement channel and return its unused escrow.
|
|
2796
3053
|
*
|
|
2797
|
-
*
|
|
2798
|
-
*
|
|
2799
|
-
*
|
|
3054
|
+
* Closes the channel for the operator the gateway's current 402 names; a
|
|
3055
|
+
* channel opened with another trusted operator key (during a key rotation)
|
|
3056
|
+
* keeps its record. The gateway closes it cooperatively when it can;
|
|
3057
|
+
* otherwise this starts a payer-forced close and the escrow comes back
|
|
3058
|
+
* after the channel's grace period. Only meaningful with the `batch`
|
|
3059
|
+
* option.
|
|
3060
|
+
*
|
|
3061
|
+
* @throws BatchCloseDeferredError, closing nothing, while a chat call for
|
|
3062
|
+
* this wallet is still in flight (including one waiting out a 429, so a
|
|
3063
|
+
* retry can never reopen a channel you just closed), or while one of its
|
|
3064
|
+
* deposits is in doubt (until a `finalized` chain read shows it landed or
|
|
3065
|
+
* that it no longer can, usually a few minutes after it was sent). Call
|
|
3066
|
+
* it again later.
|
|
2800
3067
|
*/
|
|
2801
3068
|
closeBatchChannel(): Promise<unknown>;
|
|
3069
|
+
/**
|
|
3070
|
+
* This client's batch-settlement counters: calls that fell back to `exact`
|
|
3071
|
+
* (in total and by reason), 429 backoffs, batch retries, and recoveries.
|
|
3072
|
+
* Every one of those is also logged to stderr and passed to `batch.onEvent`.
|
|
3073
|
+
* Only meaningful with the `batch` option.
|
|
3074
|
+
*/
|
|
3075
|
+
getBatchStats(): SolanaBatchStats;
|
|
2802
3076
|
/** Get Solana wallet address (public key in base58). */
|
|
2803
3077
|
getWalletAddress(): Promise<string>;
|
|
2804
3078
|
/** Simple 1-line chat. */
|
|
@@ -3008,7 +3282,30 @@ declare class SolanaLLMClient {
|
|
|
3008
3282
|
getSpending(): Spending;
|
|
3009
3283
|
/** True if using sol.blockrun.ai. */
|
|
3010
3284
|
isSolana(): boolean;
|
|
3285
|
+
/**
|
|
3286
|
+
* Chat request with automatic x402 payment.
|
|
3287
|
+
*
|
|
3288
|
+
* Every error it throws carries a {@link RetryDisposition}, which is what
|
|
3289
|
+
* {@link SolanaLLMClient.chatCompletion}'s fallback walk honours: errors of
|
|
3290
|
+
* the unpaid first request, its 402 challenge and the signing step are
|
|
3291
|
+
* `"unpaid"`; anything after a payment was sent (exact or batch) is
|
|
3292
|
+
* `"paid-or-in-doubt"`, and so is any error with an API key once the billed
|
|
3293
|
+
* request was sent, except the account API's explicit 4xx refusal.
|
|
3294
|
+
*/
|
|
3011
3295
|
private requestWithPayment;
|
|
3296
|
+
/**
|
|
3297
|
+
* Read the JSON body of a 2xx served without a payment: the free tier, or
|
|
3298
|
+
* with an API key, where this very request was the billed one.
|
|
3299
|
+
*/
|
|
3300
|
+
private readUnpaidJson;
|
|
3301
|
+
/**
|
|
3302
|
+
* Send a request that carries no payment, marking what it throws with its
|
|
3303
|
+
* {@link RetryDisposition}: `"unpaid"` with a wallet; with an API key, see
|
|
3304
|
+
* {@link accountErrorDisposition} (the request itself is billed).
|
|
3305
|
+
*/
|
|
3306
|
+
private sendUnpaid;
|
|
3307
|
+
/** Read a paid 2xx response's JSON body. The call was charged, so a failure here is never retried. */
|
|
3308
|
+
private readPaidJson;
|
|
3012
3309
|
/**
|
|
3013
3310
|
* Turn a `402` into a signed Solana payment payload.
|
|
3014
3311
|
*
|
|
@@ -3069,7 +3366,8 @@ declare class SolanaLLMClient {
|
|
|
3069
3366
|
* lives.
|
|
3070
3367
|
* @param response - the reply to the paid request.
|
|
3071
3368
|
* @throws SafeStaleBlockhashError when the caller should re-sign, PaymentError
|
|
3072
|
-
* when it should not, APIError for any other failure.
|
|
3369
|
+
* when it should not, APIError for any other failure. Every one but the
|
|
3370
|
+
* first is marked `"paid-or-in-doubt"`: the payment may have settled.
|
|
3073
3371
|
*/
|
|
3074
3372
|
private assertPaid;
|
|
3075
3373
|
/** Count one settled x402 payment against the session total. */
|
|
@@ -3435,4 +3733,4 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3435
3733
|
*/
|
|
3436
3734
|
declare function validateTopP(topP?: number): void;
|
|
3437
3735
|
|
|
3438
|
-
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, 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, type SolanaBatchOptions, 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 };
|
|
3736
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type ApiKeyOptions, type AudioModel, type AudioTrack, BASE_CHAIN_ID, BLOCKRUN_SOL_OPERATOR, type BarResolution, BatchCloseDeferredError, type BatchPayloadKind, BatchPaymentUnresolvedError, type BatchUnresolvedReason, 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, DEFAULT_BATCH_RATE_LIMIT, 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 RetryDisposition, 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, type SolanaBatchEvent, type SolanaBatchOptions, type SolanaBatchStats, 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, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|