@blockrun/llm 3.20.1 → 3.22.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 +90 -16
- package/dist/index.cjs +821 -191
- package/dist/index.d.cts +276 -38
- package/dist/index.d.ts +276 -38
- package/dist/index.js +814 -188
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -184,6 +184,53 @@ interface Tool {
|
|
|
184
184
|
type: "function";
|
|
185
185
|
function: FunctionDefinition;
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* xAI's server-side X search, for xai/* models. The gateway runs it on xAI's
|
|
189
|
+
* Responses API; billed per X post fetched. https://docs.x.ai/developers/tools/x-search
|
|
190
|
+
*/
|
|
191
|
+
interface XSearchTool {
|
|
192
|
+
type: "x_search";
|
|
193
|
+
/** Only these handles (≤20, without "@"). Not together with excludedXHandles. */
|
|
194
|
+
allowedXHandles?: string[];
|
|
195
|
+
/** Never these handles (≤20). Not together with allowedXHandles. */
|
|
196
|
+
excludedXHandles?: string[];
|
|
197
|
+
/** YYYY-MM-DD, inclusive. */
|
|
198
|
+
fromDate?: string;
|
|
199
|
+
/** YYYY-MM-DD, inclusive. */
|
|
200
|
+
toDate?: string;
|
|
201
|
+
enableImageUnderstanding?: boolean;
|
|
202
|
+
enableVideoUnderstanding?: boolean;
|
|
203
|
+
}
|
|
204
|
+
/** xAI's server-side web search, for xai/* models. */
|
|
205
|
+
interface WebSearchTool {
|
|
206
|
+
type: "web_search";
|
|
207
|
+
/** ≤5 domains. */
|
|
208
|
+
allowedDomains?: string[];
|
|
209
|
+
excludedDomains?: string[];
|
|
210
|
+
enableImageUnderstanding?: boolean;
|
|
211
|
+
}
|
|
212
|
+
/** Anything `tools` accepts: function tools, plus xAI's search tools on xai/* models. */
|
|
213
|
+
type AnyTool = Tool | XSearchTool | WebSearchTool;
|
|
214
|
+
/** A URL citation with its position in the answer text (xAI search). */
|
|
215
|
+
interface UrlCitation {
|
|
216
|
+
type: "url_citation";
|
|
217
|
+
url: string;
|
|
218
|
+
title?: string;
|
|
219
|
+
start_index?: number;
|
|
220
|
+
end_index?: number;
|
|
221
|
+
}
|
|
222
|
+
/** How a paid call settled — see `ChatResponse.settlement`. */
|
|
223
|
+
interface Settlement {
|
|
224
|
+
/** `exact`: one transfer at the quote. `batch`: metered from a payment channel. */
|
|
225
|
+
scheme: "exact" | "batch" | "free" | "api-key";
|
|
226
|
+
/** What was signed or authorised for this call, in USD. */
|
|
227
|
+
quotedUsd: number;
|
|
228
|
+
/** On-chain transaction (signature / hash), when the gateway reported one. */
|
|
229
|
+
transaction?: string;
|
|
230
|
+
network?: string;
|
|
231
|
+
/** Present and false only when the gateway reported a failed settlement. */
|
|
232
|
+
success?: false;
|
|
233
|
+
}
|
|
187
234
|
interface FunctionCall {
|
|
188
235
|
name: string;
|
|
189
236
|
arguments: string;
|
|
@@ -207,6 +254,8 @@ interface ChatMessage {
|
|
|
207
254
|
tool_calls?: ToolCall[];
|
|
208
255
|
reasoning_content?: string;
|
|
209
256
|
thinking?: string;
|
|
257
|
+
/** URL citations with positions (xAI search answers). */
|
|
258
|
+
annotations?: UrlCitation[];
|
|
210
259
|
}
|
|
211
260
|
interface ChatChoice {
|
|
212
261
|
index: number;
|
|
@@ -220,6 +269,11 @@ interface ChatUsage {
|
|
|
220
269
|
num_sources_used?: number;
|
|
221
270
|
cache_read_input_tokens?: number;
|
|
222
271
|
cache_creation_input_tokens?: number;
|
|
272
|
+
/**
|
|
273
|
+
* xAI search usage counts: x_search_calls, x_posts_fetched, x_users_fetched,
|
|
274
|
+
* web_search_calls … (what xAI bills the search by).
|
|
275
|
+
*/
|
|
276
|
+
server_side_tool_usage?: Record<string, number | undefined>;
|
|
223
277
|
}
|
|
224
278
|
interface ChatResponse {
|
|
225
279
|
id: string;
|
|
@@ -229,6 +283,20 @@ interface ChatResponse {
|
|
|
229
283
|
choices: ChatChoice[];
|
|
230
284
|
usage?: ChatUsage;
|
|
231
285
|
citations?: string[];
|
|
286
|
+
/** xAI search: the searches the model ran (`{type, query, status}`). */
|
|
287
|
+
search_calls?: Array<{
|
|
288
|
+
type: string;
|
|
289
|
+
query?: string;
|
|
290
|
+
status?: string;
|
|
291
|
+
}>;
|
|
292
|
+
/**
|
|
293
|
+
* What this call cost you, in USD: the metered charge under batch
|
|
294
|
+
* settlement, the signed price under exact, 0 for a free call. Undefined in
|
|
295
|
+
* API-key mode (billed to the account, see the dashboard).
|
|
296
|
+
*/
|
|
297
|
+
costUsd?: number;
|
|
298
|
+
/** How the call was paid, with the on-chain transaction when reported. */
|
|
299
|
+
settlement?: Settlement;
|
|
232
300
|
/**
|
|
233
301
|
* Populated when the gateway transparently substituted a different
|
|
234
302
|
* model for the one the caller asked for — typically because the
|
|
@@ -320,13 +388,19 @@ interface WebSearchSource {
|
|
|
320
388
|
excludedWebsites?: string[];
|
|
321
389
|
allowedWebsites?: string[];
|
|
322
390
|
safeSearch?: boolean;
|
|
391
|
+
enableImageUnderstanding?: boolean;
|
|
323
392
|
}
|
|
324
393
|
interface XSearchSource {
|
|
325
394
|
type: "x";
|
|
395
|
+
/** ≤20 handles. Not together with excludedXHandles. */
|
|
326
396
|
includedXHandles?: string[];
|
|
327
397
|
excludedXHandles?: string[];
|
|
398
|
+
/** Accepted for compatibility; xAI's x_search has no such filter. */
|
|
328
399
|
postFavoriteCount?: number;
|
|
400
|
+
/** Accepted for compatibility; xAI's x_search has no such filter. */
|
|
329
401
|
postViewCount?: number;
|
|
402
|
+
enableImageUnderstanding?: boolean;
|
|
403
|
+
enableVideoUnderstanding?: boolean;
|
|
330
404
|
}
|
|
331
405
|
interface NewsSearchSource {
|
|
332
406
|
type: "news";
|
|
@@ -347,6 +421,8 @@ interface SearchParameters {
|
|
|
347
421
|
fromDate?: string;
|
|
348
422
|
toDate?: string;
|
|
349
423
|
maxSearchResults?: number;
|
|
424
|
+
/** Agentic search rounds xAI may run (1–10; gateway default 4). Bounds the per-post bill. */
|
|
425
|
+
maxTurns?: number;
|
|
350
426
|
}
|
|
351
427
|
/** Usage info for Live Search sources */
|
|
352
428
|
interface SearchUsage {
|
|
@@ -412,6 +488,8 @@ interface PaymentRequired {
|
|
|
412
488
|
x402Version: number;
|
|
413
489
|
accepts: PaymentRequirement[];
|
|
414
490
|
resource?: ResourceInfo;
|
|
491
|
+
/** x402 v2 extensions the gateway declares, keyed by extension name. */
|
|
492
|
+
extensions?: Record<string, unknown>;
|
|
415
493
|
}
|
|
416
494
|
interface LLMClientOptions extends ApiKeyOptions {
|
|
417
495
|
/** EVM wallet private key (hex string starting with 0x). Optional if BASE_CHAIN_WALLET_KEY env var is set. */
|
|
@@ -470,8 +548,8 @@ interface ChatCompletionOptions {
|
|
|
470
548
|
search?: boolean;
|
|
471
549
|
/** Full Live Search configuration (for search-enabled models) */
|
|
472
550
|
searchParameters?: SearchParameters;
|
|
473
|
-
/** Tool definitions
|
|
474
|
-
tools?:
|
|
551
|
+
/** Tool definitions: function tools, plus x_search / web_search on xai/* models */
|
|
552
|
+
tools?: AnyTool[];
|
|
475
553
|
/** Tool selection strategy */
|
|
476
554
|
toolChoice?: ToolChoice;
|
|
477
555
|
/** Response format, e.g. { type: "json_object" } for JSON mode */
|
|
@@ -484,6 +562,12 @@ interface ChatCompletionOptions {
|
|
|
484
562
|
* immediately.
|
|
485
563
|
*/
|
|
486
564
|
fallbackModels?: string[];
|
|
565
|
+
/**
|
|
566
|
+
* Per-call timeout in ms, overriding the client's `timeout` for every request
|
|
567
|
+
* of this call (both `LLMClient` and `SolanaLLMClient`). Search and long
|
|
568
|
+
* reasoning calls can need more than the 60 s default.
|
|
569
|
+
*/
|
|
570
|
+
timeout?: number;
|
|
487
571
|
}
|
|
488
572
|
type RoutingProfile = "eco" | "auto" | "premium";
|
|
489
573
|
type RoutingTier = Tier;
|
|
@@ -1379,6 +1463,9 @@ declare class LLMClient {
|
|
|
1379
1463
|
/**
|
|
1380
1464
|
* Parse a response to a request that carried no payment: the free tier,
|
|
1381
1465
|
* or, with an API key, the billed request itself.
|
|
1466
|
+
*
|
|
1467
|
+
* With a wallet nothing was paid, so `costUsd` is 0 (a free model). With an
|
|
1468
|
+
* API key the call is billed to the account and `costUsd` stays undefined.
|
|
1382
1469
|
*/
|
|
1383
1470
|
private parseUnpaidChatResponse;
|
|
1384
1471
|
/**
|
|
@@ -1426,7 +1513,7 @@ declare class LLMClient {
|
|
|
1426
1513
|
*/
|
|
1427
1514
|
private handleGetPaymentAndRetryRaw;
|
|
1428
1515
|
/**
|
|
1429
|
-
* Fetch with timeout
|
|
1516
|
+
* Fetch with timeout: `timeoutMs` (a per-call override), else the client's `timeout`.
|
|
1430
1517
|
*/
|
|
1431
1518
|
private fetchWithTimeout;
|
|
1432
1519
|
/**
|
|
@@ -2808,7 +2895,8 @@ interface SolanaBatchOptions {
|
|
|
2808
2895
|
* payment, one that proves nothing was broadcast with a new payment. Other
|
|
2809
2896
|
* calls for the same wallet wait out the same cooldown instead of sending
|
|
2810
2897
|
* new channel opens; that shared cooldown never lasts longer than
|
|
2811
|
-
* `maxWaitMs`.
|
|
2898
|
+
* `maxWaitMs`. A payment carrying a payment identifier is replayed within
|
|
2899
|
+
* {@link inDoubt} instead.
|
|
2812
2900
|
*/
|
|
2813
2901
|
rateLimit?: {
|
|
2814
2902
|
/** Batch payment attempts per call, the first one included. Default 3. */
|
|
@@ -2816,6 +2904,29 @@ interface SolanaBatchOptions {
|
|
|
2816
2904
|
/** Most time, in ms, one call spends waiting on 429s before it pays `exact`. Default 60000. */
|
|
2817
2905
|
maxWaitMs?: number;
|
|
2818
2906
|
};
|
|
2907
|
+
/**
|
|
2908
|
+
* How long a call keeps replaying a batch payment in doubt that carries a
|
|
2909
|
+
* payment identifier (the gateway's 402 declares the x402
|
|
2910
|
+
* `payment-identifier` extension) before it raises
|
|
2911
|
+
* {@link BatchPaymentUnresolvedError}. The identical payment is replayed
|
|
2912
|
+
* while the gateway's answer says a later replay can succeed: no answer
|
|
2913
|
+
* (a timeout, an abort, a network error), a 5xx, a 429, or a 409 with a
|
|
2914
|
+
* `Retry-After` (the request is still running). Each wait is
|
|
2915
|
+
* `Retry-After`, else 1s, 2s, 4s... with jitter, and never under 1 s nor
|
|
2916
|
+
* over 30 s. Replays do not count against {@link rateLimit}.
|
|
2917
|
+
*/
|
|
2918
|
+
inDoubt?: {
|
|
2919
|
+
/**
|
|
2920
|
+
* Most time, in ms, one call spends replaying a payment in doubt,
|
|
2921
|
+
* counted from the first answer that left it in doubt: every wait and
|
|
2922
|
+
* every replay's own round trip. It decides whether another replay
|
|
2923
|
+
* starts: a wait that would end past it is not started, and the call
|
|
2924
|
+
* raises. A replay already sent runs until its answer or the client's
|
|
2925
|
+
* `timeout`, so a call can end up to one `timeout` past it. `0` never
|
|
2926
|
+
* replays. Default 300000 (5 min).
|
|
2927
|
+
*/
|
|
2928
|
+
maxWaitMs?: number;
|
|
2929
|
+
};
|
|
2819
2930
|
/**
|
|
2820
2931
|
* Called for every batch fallback, 429 backoff, recovery and channel
|
|
2821
2932
|
* re-read, in addition to the one-line log the SDK writes to stderr for each.
|
|
@@ -2829,15 +2940,27 @@ declare const DEFAULT_BATCH_RATE_LIMIT: {
|
|
|
2829
2940
|
readonly maxAttempts: 3;
|
|
2830
2941
|
readonly maxWaitMs: 60000;
|
|
2831
2942
|
};
|
|
2943
|
+
/** Default {@link SolanaBatchOptions.inDoubt}. */
|
|
2944
|
+
declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
2945
|
+
readonly maxWaitMs: 300000;
|
|
2946
|
+
};
|
|
2832
2947
|
/**
|
|
2833
2948
|
* One observable batch-settlement event.
|
|
2834
2949
|
*
|
|
2835
2950
|
* - `fallback`: this call pays with `exact`. `reason` says why. Only ever
|
|
2836
|
-
* when no batch payment of this call can have been charged.
|
|
2951
|
+
* when no batch payment of this call can have been charged. After the
|
|
2952
|
+
* facilitator refuses a deposit before broadcasting it (`payment_required`
|
|
2953
|
+
* with one of PayAI's `batch_*` admission codes as `errorReason`), the
|
|
2954
|
+
* wallet's calls skip batch for `retryAfterMs` (`Retry-After`, else 60s,
|
|
2955
|
+
* or 10 min for a refusal of the deposit's own terms) and report
|
|
2956
|
+
* `admission_refused`, naming the same code, without sending a payment.
|
|
2837
2957
|
* - `backoff`: this call is waiting before it retries batch, after a 429
|
|
2838
2958
|
* (`reason: "rate_limited"`) or because another call for the wallet hit one
|
|
2839
|
-
* (`reason: "cooldown"`)
|
|
2840
|
-
*
|
|
2959
|
+
* (`reason: "cooldown"`), or before each replay of a payment in doubt that
|
|
2960
|
+
* carries a payment identifier (`reason: "in_doubt"`, or `rate_limited`
|
|
2961
|
+
* after a 429), with the answer's `status` and the wait in `retryAfterMs`.
|
|
2962
|
+
* - `recovered`: a call that backed off was then paid with batch (`reason:
|
|
2963
|
+
* "in_doubt"` when the replay of a payment in doubt resolved it), or its
|
|
2841
2964
|
* fresh challenge after the wait was served without a payment (`reason:
|
|
2842
2965
|
* "served_unpaid_on_rechallenge"`: that response is the call's result, and
|
|
2843
2966
|
* nothing was paid).
|
|
@@ -2857,10 +2980,11 @@ interface SolanaBatchEvent {
|
|
|
2857
2980
|
* A short, stable code: `rate_limited`, `cooldown`, `not_offered`,
|
|
2858
2981
|
* `client_signed_not_supported`, `channel_busy`, `untrusted_operator`, `deposit_over_cap`,
|
|
2859
2982
|
* `channel_pending`, `closed_during_call`, `peer_dependency_missing`, `payment_creation_failed`,
|
|
2860
|
-
* `wallet_config_conflict`, `channel_store_locked`, `payment_required`,
|
|
2983
|
+
* `wallet_config_conflict`, `channel_store_locked`, `payment_required`, `admission_refused`,
|
|
2861
2984
|
* `channel_resync_pending`, `channel_resync_failed`, `channel_unreadable`,
|
|
2862
2985
|
* `deposit_journal_unreadable`, `deposit_journal_failed`,
|
|
2863
|
-
* `served_unpaid_on_rechallenge` or `batch_cancelled` (`recovered` events),
|
|
2986
|
+
* `served_unpaid_on_rechallenge` or `batch_cancelled` (`recovered` events), `in_doubt` (`backoff` and `recovered`
|
|
2987
|
+
* events), or one of the gateway's refusal codes the
|
|
2864
2988
|
* SDK recognises (`batch_payer_not_allowed`, `batch_payer_not_admitted`,
|
|
2865
2989
|
* `batch_admission_paused`, `batch_server_signed_only`, `batch_unavailable`,
|
|
2866
2990
|
* `batch_channel_limit`, `PAYMENT_VERIFICATION_UNAVAILABLE`). An `unresolved` event's reason is a
|
|
@@ -2893,7 +3017,7 @@ interface SolanaBatchStats {
|
|
|
2893
3017
|
fallbacksByReason: Record<string, number>;
|
|
2894
3018
|
/** Waits before a batch retry (own 429s and shared cooldowns). */
|
|
2895
3019
|
backoffs: number;
|
|
2896
|
-
/** Batch payments sent again
|
|
3020
|
+
/** Batch payments sent again: a new payment after a 429, or each replay of a payment in doubt. */
|
|
2897
3021
|
retries: number;
|
|
2898
3022
|
/**
|
|
2899
3023
|
* Calls paid with batch after at least one backoff, or served without a
|
|
@@ -2913,10 +3037,15 @@ interface SolanaBatchStats {
|
|
|
2913
3037
|
/**
|
|
2914
3038
|
* Why a batch payment is left in doubt; see {@link BatchPaymentUnresolvedError}.
|
|
2915
3039
|
*
|
|
2916
|
-
* - `replay_unresolved`: a 429 without a receipt
|
|
2917
|
-
* replay got no definitive success receipt (a 402,
|
|
2918
|
-
* another 429, a 5xx, a timeout...), or
|
|
2919
|
-
*
|
|
3040
|
+
* - `replay_unresolved`: a 429 without a receipt, whose one byte-identical
|
|
3041
|
+
* replay got no definitive success receipt (a 402,
|
|
3042
|
+
* `duplicate_settlement`, another 429, a 5xx, a timeout...), or a payment
|
|
3043
|
+
* carrying a payment identifier whose replays got none: the last one was
|
|
3044
|
+
* answered with something no later replay can change (a 409 without
|
|
3045
|
+
* `Retry-After`, a 402, a 2xx without a receipt the SDK can verify...),
|
|
3046
|
+
* or `batch.inDoubt.maxWaitMs` ran out. A 429 without a receipt keeps
|
|
3047
|
+
* this reason when there is no room to replay it; any other doubt keeps
|
|
3048
|
+
* its own reason.
|
|
2920
3049
|
* - `ambiguous_rate_limit`: a 429 whose receipt does not prove nothing was
|
|
2921
3050
|
* broadcast (one that says it was charged, `settlement_pending`, or one
|
|
2922
3051
|
* naming a transaction).
|
|
@@ -2978,7 +3107,8 @@ declare class BatchPaymentUnresolvedError extends PaymentError {
|
|
|
2978
3107
|
* `closeBatchChannel()` did not close anything, and should be called again
|
|
2979
3108
|
* later:
|
|
2980
3109
|
* - `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
|
|
3110
|
+
* be waiting out a 429 before its retry or replay, or between the replays
|
|
3111
|
+
* of a payment in doubt);
|
|
2982
3112
|
* - `deposit_in_doubt`: a deposit the wallet sent (an open or top-up) has
|
|
2983
3113
|
* not been settled yet. It settles once a `finalized` chain read shows it
|
|
2984
3114
|
* landed, or once the finalized chain is past its last valid block,
|
|
@@ -3158,7 +3288,9 @@ declare class SolanaLLMClient {
|
|
|
3158
3288
|
*
|
|
3159
3289
|
* @returns USDC balance as a float
|
|
3160
3290
|
*/
|
|
3161
|
-
getBalance(
|
|
3291
|
+
getBalance(options?: {
|
|
3292
|
+
strict?: boolean;
|
|
3293
|
+
}): Promise<number>;
|
|
3162
3294
|
/** Edit an image using img2img (Solana payment). */
|
|
3163
3295
|
/**
|
|
3164
3296
|
* Generate an image on Solana.
|
|
@@ -3173,6 +3305,40 @@ declare class SolanaLLMClient {
|
|
|
3173
3305
|
n?: number;
|
|
3174
3306
|
} & Record<string, unknown>): Promise<ImageResponse>;
|
|
3175
3307
|
imageEdit(prompt: string, image: string | string[], options?: ImageEditOptions): Promise<ImageResponse>;
|
|
3308
|
+
/**
|
|
3309
|
+
* Generate a short video on Solana.
|
|
3310
|
+
*
|
|
3311
|
+
* The POST is verified, not charged. The job is then polled with a wallet
|
|
3312
|
+
* signature (no payment) until it finishes, and ONE payment is signed for
|
|
3313
|
+
* the finished video; a failed job is never charged. If the gateway does not
|
|
3314
|
+
* accept poll signatures for the job, it is polled with a payment per poll
|
|
3315
|
+
* instead, which is likewise only charged on completion.
|
|
3316
|
+
*
|
|
3317
|
+
* @param prompt - text description of the video.
|
|
3318
|
+
* @param options - `model` (default `xai/grok-imagine-video`), `budgetMs`
|
|
3319
|
+
* (total wait, default 15 min); any other keys are sent verbatim, so use
|
|
3320
|
+
* the gateway's snake_case names (`duration_seconds`, `image_url`,
|
|
3321
|
+
* `aspect_ratio`, `resolution`, …).
|
|
3322
|
+
*/
|
|
3323
|
+
video(prompt: string, options?: {
|
|
3324
|
+
model?: string;
|
|
3325
|
+
budgetMs?: number;
|
|
3326
|
+
} & Record<string, unknown>): Promise<VideoResponse>;
|
|
3327
|
+
/**
|
|
3328
|
+
* Generate a music track on Solana. Paid at the POST; a slow track is then
|
|
3329
|
+
* polled with a wallet signature, never another payment.
|
|
3330
|
+
*
|
|
3331
|
+
* @param prompt - music style, mood, or description.
|
|
3332
|
+
* @param options - `model` (default `minimax/music-2.5+`), `instrumental`
|
|
3333
|
+
* (default true), `lyrics` (requires `instrumental: false`), `budgetMs`
|
|
3334
|
+
* (total wait, default 5 min); other keys are sent verbatim.
|
|
3335
|
+
*/
|
|
3336
|
+
music(prompt: string, options?: {
|
|
3337
|
+
model?: string;
|
|
3338
|
+
instrumental?: boolean;
|
|
3339
|
+
lyrics?: string;
|
|
3340
|
+
budgetMs?: number;
|
|
3341
|
+
} & Record<string, unknown>): Promise<MusicResponse>;
|
|
3176
3342
|
/** Standalone search (Solana payment). */
|
|
3177
3343
|
search(query: string, options?: SearchOptions): Promise<SearchResult>;
|
|
3178
3344
|
pm(path: string, params?: Record<string, string>): Promise<Record<string, unknown>>;
|
|
@@ -3293,6 +3459,12 @@ declare class SolanaLLMClient {
|
|
|
3293
3459
|
* request was sent, except the account API's explicit 4xx refusal.
|
|
3294
3460
|
*/
|
|
3295
3461
|
private requestWithPayment;
|
|
3462
|
+
/**
|
|
3463
|
+
* Cost of a chat response served without a payment: 0 with a wallet (a free
|
|
3464
|
+
* model). With an API key the call is billed to the account, so costUsd stays
|
|
3465
|
+
* undefined (see the dashboard).
|
|
3466
|
+
*/
|
|
3467
|
+
private withUnpaidCost;
|
|
3296
3468
|
/**
|
|
3297
3469
|
* Read the JSON body of a 2xx served without a payment: the free tier, or
|
|
3298
3470
|
* with an API key, where this very request was the billed one.
|
|
@@ -3306,6 +3478,47 @@ declare class SolanaLLMClient {
|
|
|
3306
3478
|
private sendUnpaid;
|
|
3307
3479
|
/** Read a paid 2xx response's JSON body. The call was charged, so a failure here is never retried. */
|
|
3308
3480
|
private readPaidJson;
|
|
3481
|
+
/**
|
|
3482
|
+
* Follow a 202 `{ id, poll_url }` to completion on a Solana media route
|
|
3483
|
+
* (image, music, video).
|
|
3484
|
+
*
|
|
3485
|
+
* **Polls prove ownership, they do not pay.** A Solana payment is a
|
|
3486
|
+
* transaction pinned to a recent blockhash (~60s), so paying every poll of a
|
|
3487
|
+
* multi-minute job meant signing a fresh transaction every few seconds. Each
|
|
3488
|
+
* poll here instead carries the `x-poll-*` headers: the submitting wallet's
|
|
3489
|
+
* ed25519 signature over `blockrun-poll:v1:<kind>:<job id>:<unix seconds>`
|
|
3490
|
+
* (see `poll-ownership.ts`). That proof never charges.
|
|
3491
|
+
*
|
|
3492
|
+
* **Who pays when:**
|
|
3493
|
+
* - image / music: the POST already settled (sol settles at submit because the
|
|
3494
|
+
* signed transaction would be dead by completion). The caller recorded the
|
|
3495
|
+
* cost at POST; this loop only fetches the result and never signs a payment.
|
|
3496
|
+
* A batch-billed image job still answers its proof poll with 402: that job
|
|
3497
|
+
* falls back to the per-poll payment below.
|
|
3498
|
+
* - video: settles on completion, and a failed job is never charged. A
|
|
3499
|
+
* finished, unpaid job answers the proof poll with 402 `{status:"completed"}`
|
|
3500
|
+
* and a normal x402 challenge; ONE payment is signed from that challenge and
|
|
3501
|
+
* the same poll is re-sent with it. The cost is recorded here, on delivery.
|
|
3502
|
+
* A paid poll the gateway answers 402 (settlement in progress on another
|
|
3503
|
+
* poll, outcome unknown, stale blockhash) is re-polled after its
|
|
3504
|
+
* Retry-After — the gateway's per-job settlement claim makes a later fresh
|
|
3505
|
+
* payment safe — up to `MAX_PAID_POLL_REFUSALS` times.
|
|
3506
|
+
*
|
|
3507
|
+
* **Fallback, once per job:** if the gateway refuses the proof with its "no
|
|
3508
|
+
* such job" answer (video 400, image/music 404) or answers it with a plain
|
|
3509
|
+
* payment challenge (a gateway or job that predates poll proofs), the rest of
|
|
3510
|
+
* this job is polled the old way — an x-payment signed per poll, which the
|
|
3511
|
+
* gateway verifies against the job's payer and does not charge until a video
|
|
3512
|
+
* completes. Logged to stderr; never switches back.
|
|
3513
|
+
*/
|
|
3514
|
+
private followSolanaJob;
|
|
3515
|
+
/**
|
|
3516
|
+
* Absolute URL for a job's `poll_url`. The gateway returns `/api/v1/...`;
|
|
3517
|
+
* {@link buildUrl} drops the `/api` that `apiUrl` already ends with. An
|
|
3518
|
+
* absolute poll_url must be on the gateway's own origin: the poll carries a
|
|
3519
|
+
* wallet signature (and, for a finished video, a payment).
|
|
3520
|
+
*/
|
|
3521
|
+
private resolvePollUrl;
|
|
3309
3522
|
/**
|
|
3310
3523
|
* Turn a `402` into a signed Solana payment payload.
|
|
3311
3524
|
*
|
|
@@ -3324,27 +3537,6 @@ declare class SolanaLLMClient {
|
|
|
3324
3537
|
* @returns the header value to replay with, and what it will settle for.
|
|
3325
3538
|
* @throws PaymentError when the 402 carries no usable Solana requirements.
|
|
3326
3539
|
*/
|
|
3327
|
-
/**
|
|
3328
|
-
* Follow a 202 `{ id, poll_url }` to completion, on Solana **image** routes.
|
|
3329
|
-
*
|
|
3330
|
-
* Two things differ from Base and both come from the same constraint — a
|
|
3331
|
-
* Solana payment is a transaction pinned to a recent blockhash, valid for
|
|
3332
|
-
* ~150 blocks (~60s), and a long render outlives it:
|
|
3333
|
-
*
|
|
3334
|
-
* 1. **The POST already settled.** Base settles on the completed poll; Solana
|
|
3335
|
-
* cannot, because by then the signed transaction has expired. So sol
|
|
3336
|
-
* settles optimistically at submit, and this loop only fetches the result.
|
|
3337
|
-
* The cost is recorded by the caller at POST, never here — recording it on
|
|
3338
|
-
* completion would lose the charge whenever a paid job then fails.
|
|
3339
|
-
* Solana VIDEO is the exception: it settles on the completed poll and a
|
|
3340
|
-
* failed job is not charged. Do not route video through this loop as-is —
|
|
3341
|
-
* it would book spend for jobs that were never charged.
|
|
3342
|
-
* 2. **Every poll re-signs.** One authorization cannot be replayed across a
|
|
3343
|
-
* long render. The gateway binds the job to the payer address rather than
|
|
3344
|
-
* to the signature, so a fresh signature from the same wallet is accepted
|
|
3345
|
-
* and is never charged again.
|
|
3346
|
-
*/
|
|
3347
|
-
private followSolanaJob;
|
|
3348
3540
|
private signPaymentFrom402;
|
|
3349
3541
|
/** Read a `402`'s payment requirements from its header, or its JSON body. */
|
|
3350
3542
|
private readPaymentRequired;
|
|
@@ -3733,4 +3925,50 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3733
3925
|
*/
|
|
3734
3926
|
declare function validateTopP(topP?: number): void;
|
|
3735
3927
|
|
|
3736
|
-
|
|
3928
|
+
/**
|
|
3929
|
+
* Wire format for xAI search on the BlockRun gateways.
|
|
3930
|
+
*
|
|
3931
|
+
* The SDK's `SearchParameters` / `SearchSource` types are camelCase, but the
|
|
3932
|
+
* gateways validate the OpenAI-style snake_case body (`included_x_handles`,
|
|
3933
|
+
* `from_date`, …) with a non-strict schema that silently strips unknown keys.
|
|
3934
|
+
* Sending the camelCase object verbatim therefore dropped every filter: an
|
|
3935
|
+
* "only these X handles since yesterday" search ran over all of X, all time.
|
|
3936
|
+
* Everything that leaves the SDK goes through {@link toWireSearchParameters}.
|
|
3937
|
+
*
|
|
3938
|
+
* Native xAI search tools (`{ type: "x_search" }` / `{ type: "web_search" }`)
|
|
3939
|
+
* are accepted in `tools` for xai/* models and converted by {@link toWireTools}.
|
|
3940
|
+
* https://docs.x.ai/developers/tools/x-search
|
|
3941
|
+
*/
|
|
3942
|
+
|
|
3943
|
+
type Wire = Record<string, unknown>;
|
|
3944
|
+
/** camelCase `SearchParameters` → the gateway's snake_case `search_parameters`. */
|
|
3945
|
+
declare function toWireSearchParameters(sp: SearchParameters): Wire;
|
|
3946
|
+
/** Function tools pass through; x_search / web_search tools get xAI's field names. */
|
|
3947
|
+
declare function toWireTools(tools: AnyTool[]): Wire[];
|
|
3948
|
+
|
|
3949
|
+
/**
|
|
3950
|
+
* What one paid call actually cost, read from the gateway's PAYMENT-RESPONSE.
|
|
3951
|
+
*
|
|
3952
|
+
* The x402 receipt header is base64 JSON: `{ success, transaction, network,
|
|
3953
|
+
* payer, amount?, extra?: { chargedAmount? } }`. Under batch / metered schemes
|
|
3954
|
+
* the real charge is `extra.chargedAmount` (atomic USDC), else `amount`; under
|
|
3955
|
+
* `exact` neither is set and the signed quote is the charge. The receipt is
|
|
3956
|
+
* decoded best-effort: a missing or malformed header never fails the call.
|
|
3957
|
+
*
|
|
3958
|
+
* Some gateway routes also (or only) set `X-Payment-Receipt`, whose value is
|
|
3959
|
+
* the raw settlement transaction hash, not base64 JSON.
|
|
3960
|
+
*/
|
|
3961
|
+
|
|
3962
|
+
/**
|
|
3963
|
+
* The cost and settlement for one response.
|
|
3964
|
+
*
|
|
3965
|
+
* `costUsd` is the charge the receipt states, else `quotedUsd`.
|
|
3966
|
+
* @param quotedUsd - what was signed (the exact price, or the batch charge the payer reported).
|
|
3967
|
+
* @param scheme - how it was paid.
|
|
3968
|
+
*/
|
|
3969
|
+
declare function readSettlement(response: Response, quotedUsd: number, scheme: Settlement["scheme"]): {
|
|
3970
|
+
costUsd: number;
|
|
3971
|
+
settlement: Settlement;
|
|
3972
|
+
};
|
|
3973
|
+
|
|
3974
|
+
export { APIError, API_KEY_URL, ARC_CHAIN_ID, AnthropicClient, type AnyTool, 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_IN_DOUBT, 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 Settlement, 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, type UrlCitation, 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 WebSearchTool, type XSearchSource, type XSearchTool, 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, readSettlement, retryDisposition, saveSolanaWallet, saveToCache, saveWallet, scanSolanaWallets, scanWallets, setCache, setupAgentClient, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, toWireSearchParameters, toWireTools, validateMaxTokens, validateModel, validateTemperature, validateTopP };
|