@blockrun/llm 3.21.0 → 3.22.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 +70 -12
- package/dist/index.cjs +495 -99
- package/dist/index.d.cts +215 -17
- package/dist/index.d.ts +215 -17
- package/dist/index.js +491 -99
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -184,6 +184,60 @@ 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
|
+
/**
|
|
234
|
+
* `"free-fallback"` when the gateway served a paid request from a free
|
|
235
|
+
* fallback model and skipped settlement (`X-Settlement-Skipped`): nothing
|
|
236
|
+
* moved on chain, so `costUsd` is 0 and nothing was added to `getSpending()`.
|
|
237
|
+
* `quotedUsd` still states what was signed.
|
|
238
|
+
*/
|
|
239
|
+
skipped?: "free-fallback";
|
|
240
|
+
}
|
|
187
241
|
interface FunctionCall {
|
|
188
242
|
name: string;
|
|
189
243
|
arguments: string;
|
|
@@ -207,6 +261,8 @@ interface ChatMessage {
|
|
|
207
261
|
tool_calls?: ToolCall[];
|
|
208
262
|
reasoning_content?: string;
|
|
209
263
|
thinking?: string;
|
|
264
|
+
/** URL citations with positions (xAI search answers). */
|
|
265
|
+
annotations?: UrlCitation[];
|
|
210
266
|
}
|
|
211
267
|
interface ChatChoice {
|
|
212
268
|
index: number;
|
|
@@ -220,6 +276,11 @@ interface ChatUsage {
|
|
|
220
276
|
num_sources_used?: number;
|
|
221
277
|
cache_read_input_tokens?: number;
|
|
222
278
|
cache_creation_input_tokens?: number;
|
|
279
|
+
/**
|
|
280
|
+
* xAI search usage counts: x_search_calls, x_posts_fetched, x_users_fetched,
|
|
281
|
+
* web_search_calls … (what xAI bills the search by).
|
|
282
|
+
*/
|
|
283
|
+
server_side_tool_usage?: Record<string, number | undefined>;
|
|
223
284
|
}
|
|
224
285
|
interface ChatResponse {
|
|
225
286
|
id: string;
|
|
@@ -229,6 +290,20 @@ interface ChatResponse {
|
|
|
229
290
|
choices: ChatChoice[];
|
|
230
291
|
usage?: ChatUsage;
|
|
231
292
|
citations?: string[];
|
|
293
|
+
/** xAI search: the searches the model ran (`{type, query, status}`). */
|
|
294
|
+
search_calls?: Array<{
|
|
295
|
+
type: string;
|
|
296
|
+
query?: string;
|
|
297
|
+
status?: string;
|
|
298
|
+
}>;
|
|
299
|
+
/**
|
|
300
|
+
* What this call cost you, in USD: the metered charge under batch
|
|
301
|
+
* settlement, the signed price under exact, 0 for a free call. Undefined in
|
|
302
|
+
* API-key mode (billed to the account, see the dashboard).
|
|
303
|
+
*/
|
|
304
|
+
costUsd?: number;
|
|
305
|
+
/** How the call was paid, with the on-chain transaction when reported. */
|
|
306
|
+
settlement?: Settlement;
|
|
232
307
|
/**
|
|
233
308
|
* Populated when the gateway transparently substituted a different
|
|
234
309
|
* model for the one the caller asked for — typically because the
|
|
@@ -320,13 +395,19 @@ interface WebSearchSource {
|
|
|
320
395
|
excludedWebsites?: string[];
|
|
321
396
|
allowedWebsites?: string[];
|
|
322
397
|
safeSearch?: boolean;
|
|
398
|
+
enableImageUnderstanding?: boolean;
|
|
323
399
|
}
|
|
324
400
|
interface XSearchSource {
|
|
325
401
|
type: "x";
|
|
402
|
+
/** ≤20 handles. Not together with excludedXHandles. */
|
|
326
403
|
includedXHandles?: string[];
|
|
327
404
|
excludedXHandles?: string[];
|
|
405
|
+
/** Accepted for compatibility; xAI's x_search has no such filter. */
|
|
328
406
|
postFavoriteCount?: number;
|
|
407
|
+
/** Accepted for compatibility; xAI's x_search has no such filter. */
|
|
329
408
|
postViewCount?: number;
|
|
409
|
+
enableImageUnderstanding?: boolean;
|
|
410
|
+
enableVideoUnderstanding?: boolean;
|
|
330
411
|
}
|
|
331
412
|
interface NewsSearchSource {
|
|
332
413
|
type: "news";
|
|
@@ -347,6 +428,8 @@ interface SearchParameters {
|
|
|
347
428
|
fromDate?: string;
|
|
348
429
|
toDate?: string;
|
|
349
430
|
maxSearchResults?: number;
|
|
431
|
+
/** Agentic search rounds xAI may run (1–10; gateway default 4). Bounds the per-post bill. */
|
|
432
|
+
maxTurns?: number;
|
|
350
433
|
}
|
|
351
434
|
/** Usage info for Live Search sources */
|
|
352
435
|
interface SearchUsage {
|
|
@@ -412,6 +495,8 @@ interface PaymentRequired {
|
|
|
412
495
|
x402Version: number;
|
|
413
496
|
accepts: PaymentRequirement[];
|
|
414
497
|
resource?: ResourceInfo;
|
|
498
|
+
/** x402 v2 extensions the gateway declares, keyed by extension name. */
|
|
499
|
+
extensions?: Record<string, unknown>;
|
|
415
500
|
}
|
|
416
501
|
interface LLMClientOptions extends ApiKeyOptions {
|
|
417
502
|
/** EVM wallet private key (hex string starting with 0x). Optional if BASE_CHAIN_WALLET_KEY env var is set. */
|
|
@@ -470,8 +555,8 @@ interface ChatCompletionOptions {
|
|
|
470
555
|
search?: boolean;
|
|
471
556
|
/** Full Live Search configuration (for search-enabled models) */
|
|
472
557
|
searchParameters?: SearchParameters;
|
|
473
|
-
/** Tool definitions
|
|
474
|
-
tools?:
|
|
558
|
+
/** Tool definitions: function tools, plus x_search / web_search on xai/* models */
|
|
559
|
+
tools?: AnyTool[];
|
|
475
560
|
/** Tool selection strategy */
|
|
476
561
|
toolChoice?: ToolChoice;
|
|
477
562
|
/** Response format, e.g. { type: "json_object" } for JSON mode */
|
|
@@ -484,6 +569,12 @@ interface ChatCompletionOptions {
|
|
|
484
569
|
* immediately.
|
|
485
570
|
*/
|
|
486
571
|
fallbackModels?: string[];
|
|
572
|
+
/**
|
|
573
|
+
* Per-call timeout in ms, overriding the client's `timeout` for every request
|
|
574
|
+
* of this call (both `LLMClient` and `SolanaLLMClient`). Search and long
|
|
575
|
+
* reasoning calls can need more than the 60 s default.
|
|
576
|
+
*/
|
|
577
|
+
timeout?: number;
|
|
487
578
|
}
|
|
488
579
|
type RoutingProfile = "eco" | "auto" | "premium";
|
|
489
580
|
type RoutingTier = Tier;
|
|
@@ -1379,6 +1470,9 @@ declare class LLMClient {
|
|
|
1379
1470
|
/**
|
|
1380
1471
|
* Parse a response to a request that carried no payment: the free tier,
|
|
1381
1472
|
* or, with an API key, the billed request itself.
|
|
1473
|
+
*
|
|
1474
|
+
* With a wallet nothing was paid, so `costUsd` is 0 (a free model). With an
|
|
1475
|
+
* API key the call is billed to the account and `costUsd` stays undefined.
|
|
1382
1476
|
*/
|
|
1383
1477
|
private parseUnpaidChatResponse;
|
|
1384
1478
|
/**
|
|
@@ -1392,6 +1486,13 @@ declare class LLMClient {
|
|
|
1392
1486
|
private signFrom402;
|
|
1393
1487
|
/** Send the signed payment and read the answer. The payment may settle from here on. */
|
|
1394
1488
|
private sendPaid;
|
|
1489
|
+
/**
|
|
1490
|
+
* Book a served, paid chat call and attach its cost. A response the gateway
|
|
1491
|
+
* served from a free fallback with settlement skipped
|
|
1492
|
+
* (`X-Settlement-Skipped: free-fallback`) moved nothing on chain, so it is
|
|
1493
|
+
* not added to `getSpending()` or the cost log, and reports `costUsd: 0`.
|
|
1494
|
+
*/
|
|
1495
|
+
private bookPaid;
|
|
1395
1496
|
/**
|
|
1396
1497
|
* Sign a payment header and return the PAYMENT-SIGNATURE value.
|
|
1397
1498
|
* Extracted to share logic between streaming and non-streaming flows.
|
|
@@ -1426,7 +1527,7 @@ declare class LLMClient {
|
|
|
1426
1527
|
*/
|
|
1427
1528
|
private handleGetPaymentAndRetryRaw;
|
|
1428
1529
|
/**
|
|
1429
|
-
* Fetch with timeout
|
|
1530
|
+
* Fetch with timeout: `timeoutMs` (a per-call override), else the client's `timeout`.
|
|
1430
1531
|
*/
|
|
1431
1532
|
private fetchWithTimeout;
|
|
1432
1533
|
/**
|
|
@@ -2808,7 +2909,8 @@ interface SolanaBatchOptions {
|
|
|
2808
2909
|
* payment, one that proves nothing was broadcast with a new payment. Other
|
|
2809
2910
|
* calls for the same wallet wait out the same cooldown instead of sending
|
|
2810
2911
|
* new channel opens; that shared cooldown never lasts longer than
|
|
2811
|
-
* `maxWaitMs`.
|
|
2912
|
+
* `maxWaitMs`. A payment carrying a payment identifier is replayed within
|
|
2913
|
+
* {@link inDoubt} instead.
|
|
2812
2914
|
*/
|
|
2813
2915
|
rateLimit?: {
|
|
2814
2916
|
/** Batch payment attempts per call, the first one included. Default 3. */
|
|
@@ -2816,6 +2918,29 @@ interface SolanaBatchOptions {
|
|
|
2816
2918
|
/** Most time, in ms, one call spends waiting on 429s before it pays `exact`. Default 60000. */
|
|
2817
2919
|
maxWaitMs?: number;
|
|
2818
2920
|
};
|
|
2921
|
+
/**
|
|
2922
|
+
* How long a call keeps replaying a batch payment in doubt that carries a
|
|
2923
|
+
* payment identifier (the gateway's 402 declares the x402
|
|
2924
|
+
* `payment-identifier` extension) before it raises
|
|
2925
|
+
* {@link BatchPaymentUnresolvedError}. The identical payment is replayed
|
|
2926
|
+
* while the gateway's answer says a later replay can succeed: no answer
|
|
2927
|
+
* (a timeout, an abort, a network error), a 5xx, a 429, or a 409 with a
|
|
2928
|
+
* `Retry-After` (the request is still running). Each wait is
|
|
2929
|
+
* `Retry-After`, else 1s, 2s, 4s... with jitter, and never under 1 s nor
|
|
2930
|
+
* over 30 s. Replays do not count against {@link rateLimit}.
|
|
2931
|
+
*/
|
|
2932
|
+
inDoubt?: {
|
|
2933
|
+
/**
|
|
2934
|
+
* Most time, in ms, one call spends replaying a payment in doubt,
|
|
2935
|
+
* counted from the first answer that left it in doubt: every wait and
|
|
2936
|
+
* every replay's own round trip. It decides whether another replay
|
|
2937
|
+
* starts: a wait that would end past it is not started, and the call
|
|
2938
|
+
* raises. A replay already sent runs until its answer or the client's
|
|
2939
|
+
* `timeout`, so a call can end up to one `timeout` past it. `0` never
|
|
2940
|
+
* replays. Default 300000 (5 min).
|
|
2941
|
+
*/
|
|
2942
|
+
maxWaitMs?: number;
|
|
2943
|
+
};
|
|
2819
2944
|
/**
|
|
2820
2945
|
* Called for every batch fallback, 429 backoff, recovery and channel
|
|
2821
2946
|
* re-read, in addition to the one-line log the SDK writes to stderr for each.
|
|
@@ -2829,15 +2954,27 @@ declare const DEFAULT_BATCH_RATE_LIMIT: {
|
|
|
2829
2954
|
readonly maxAttempts: 3;
|
|
2830
2955
|
readonly maxWaitMs: 60000;
|
|
2831
2956
|
};
|
|
2957
|
+
/** Default {@link SolanaBatchOptions.inDoubt}. */
|
|
2958
|
+
declare const DEFAULT_BATCH_IN_DOUBT: {
|
|
2959
|
+
readonly maxWaitMs: 300000;
|
|
2960
|
+
};
|
|
2832
2961
|
/**
|
|
2833
2962
|
* One observable batch-settlement event.
|
|
2834
2963
|
*
|
|
2835
2964
|
* - `fallback`: this call pays with `exact`. `reason` says why. Only ever
|
|
2836
|
-
* when no batch payment of this call can have been charged.
|
|
2965
|
+
* when no batch payment of this call can have been charged. After the
|
|
2966
|
+
* facilitator refuses a deposit before broadcasting it (`payment_required`
|
|
2967
|
+
* with one of PayAI's `batch_*` admission codes as `errorReason`), the
|
|
2968
|
+
* wallet's calls skip batch for `retryAfterMs` (`Retry-After`, else 60s,
|
|
2969
|
+
* or 10 min for a refusal of the deposit's own terms) and report
|
|
2970
|
+
* `admission_refused`, naming the same code, without sending a payment.
|
|
2837
2971
|
* - `backoff`: this call is waiting before it retries batch, after a 429
|
|
2838
2972
|
* (`reason: "rate_limited"`) or because another call for the wallet hit one
|
|
2839
|
-
* (`reason: "cooldown"`)
|
|
2840
|
-
*
|
|
2973
|
+
* (`reason: "cooldown"`), or before each replay of a payment in doubt that
|
|
2974
|
+
* carries a payment identifier (`reason: "in_doubt"`, or `rate_limited`
|
|
2975
|
+
* after a 429), with the answer's `status` and the wait in `retryAfterMs`.
|
|
2976
|
+
* - `recovered`: a call that backed off was then paid with batch (`reason:
|
|
2977
|
+
* "in_doubt"` when the replay of a payment in doubt resolved it), or its
|
|
2841
2978
|
* fresh challenge after the wait was served without a payment (`reason:
|
|
2842
2979
|
* "served_unpaid_on_rechallenge"`: that response is the call's result, and
|
|
2843
2980
|
* nothing was paid).
|
|
@@ -2857,10 +2994,11 @@ interface SolanaBatchEvent {
|
|
|
2857
2994
|
* A short, stable code: `rate_limited`, `cooldown`, `not_offered`,
|
|
2858
2995
|
* `client_signed_not_supported`, `channel_busy`, `untrusted_operator`, `deposit_over_cap`,
|
|
2859
2996
|
* `channel_pending`, `closed_during_call`, `peer_dependency_missing`, `payment_creation_failed`,
|
|
2860
|
-
* `wallet_config_conflict`, `channel_store_locked`, `payment_required`,
|
|
2997
|
+
* `wallet_config_conflict`, `channel_store_locked`, `payment_required`, `admission_refused`,
|
|
2861
2998
|
* `channel_resync_pending`, `channel_resync_failed`, `channel_unreadable`,
|
|
2862
2999
|
* `deposit_journal_unreadable`, `deposit_journal_failed`,
|
|
2863
|
-
* `served_unpaid_on_rechallenge` or `batch_cancelled` (`recovered` events),
|
|
3000
|
+
* `served_unpaid_on_rechallenge` or `batch_cancelled` (`recovered` events), `in_doubt` (`backoff` and `recovered`
|
|
3001
|
+
* events), or one of the gateway's refusal codes the
|
|
2864
3002
|
* SDK recognises (`batch_payer_not_allowed`, `batch_payer_not_admitted`,
|
|
2865
3003
|
* `batch_admission_paused`, `batch_server_signed_only`, `batch_unavailable`,
|
|
2866
3004
|
* `batch_channel_limit`, `PAYMENT_VERIFICATION_UNAVAILABLE`). An `unresolved` event's reason is a
|
|
@@ -2893,7 +3031,7 @@ interface SolanaBatchStats {
|
|
|
2893
3031
|
fallbacksByReason: Record<string, number>;
|
|
2894
3032
|
/** Waits before a batch retry (own 429s and shared cooldowns). */
|
|
2895
3033
|
backoffs: number;
|
|
2896
|
-
/** Batch payments sent again
|
|
3034
|
+
/** Batch payments sent again: a new payment after a 429, or each replay of a payment in doubt. */
|
|
2897
3035
|
retries: number;
|
|
2898
3036
|
/**
|
|
2899
3037
|
* Calls paid with batch after at least one backoff, or served without a
|
|
@@ -2913,10 +3051,15 @@ interface SolanaBatchStats {
|
|
|
2913
3051
|
/**
|
|
2914
3052
|
* Why a batch payment is left in doubt; see {@link BatchPaymentUnresolvedError}.
|
|
2915
3053
|
*
|
|
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
|
-
*
|
|
3054
|
+
* - `replay_unresolved`: a 429 without a receipt, whose one byte-identical
|
|
3055
|
+
* replay got no definitive success receipt (a 402,
|
|
3056
|
+
* `duplicate_settlement`, another 429, a 5xx, a timeout...), or a payment
|
|
3057
|
+
* carrying a payment identifier whose replays got none: the last one was
|
|
3058
|
+
* answered with something no later replay can change (a 409 without
|
|
3059
|
+
* `Retry-After`, a 402, a 2xx without a receipt the SDK can verify...),
|
|
3060
|
+
* or `batch.inDoubt.maxWaitMs` ran out. A 429 without a receipt keeps
|
|
3061
|
+
* this reason when there is no room to replay it; any other doubt keeps
|
|
3062
|
+
* its own reason.
|
|
2920
3063
|
* - `ambiguous_rate_limit`: a 429 whose receipt does not prove nothing was
|
|
2921
3064
|
* broadcast (one that says it was charged, `settlement_pending`, or one
|
|
2922
3065
|
* naming a transaction).
|
|
@@ -2978,7 +3121,8 @@ declare class BatchPaymentUnresolvedError extends PaymentError {
|
|
|
2978
3121
|
* `closeBatchChannel()` did not close anything, and should be called again
|
|
2979
3122
|
* later:
|
|
2980
3123
|
* - `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
|
|
3124
|
+
* be waiting out a 429 before its retry or replay, or between the replays
|
|
3125
|
+
* of a payment in doubt);
|
|
2982
3126
|
* - `deposit_in_doubt`: a deposit the wallet sent (an open or top-up) has
|
|
2983
3127
|
* not been settled yet. It settles once a `finalized` chain read shows it
|
|
2984
3128
|
* landed, or once the finalized chain is past its last valid block,
|
|
@@ -3158,7 +3302,9 @@ declare class SolanaLLMClient {
|
|
|
3158
3302
|
*
|
|
3159
3303
|
* @returns USDC balance as a float
|
|
3160
3304
|
*/
|
|
3161
|
-
getBalance(
|
|
3305
|
+
getBalance(options?: {
|
|
3306
|
+
strict?: boolean;
|
|
3307
|
+
}): Promise<number>;
|
|
3162
3308
|
/** Edit an image using img2img (Solana payment). */
|
|
3163
3309
|
/**
|
|
3164
3310
|
* Generate an image on Solana.
|
|
@@ -3327,6 +3473,12 @@ declare class SolanaLLMClient {
|
|
|
3327
3473
|
* request was sent, except the account API's explicit 4xx refusal.
|
|
3328
3474
|
*/
|
|
3329
3475
|
private requestWithPayment;
|
|
3476
|
+
/**
|
|
3477
|
+
* Cost of a chat response served without a payment: 0 with a wallet (a free
|
|
3478
|
+
* model). With an API key the call is billed to the account, so costUsd stays
|
|
3479
|
+
* undefined (see the dashboard).
|
|
3480
|
+
*/
|
|
3481
|
+
private withUnpaidCost;
|
|
3330
3482
|
/**
|
|
3331
3483
|
* Read the JSON body of a 2xx served without a payment: the free tier, or
|
|
3332
3484
|
* with an API key, where this very request was the billed one.
|
|
@@ -3787,4 +3939,50 @@ declare function validateTemperature(temperature?: number): void;
|
|
|
3787
3939
|
*/
|
|
3788
3940
|
declare function validateTopP(topP?: number): void;
|
|
3789
3941
|
|
|
3790
|
-
|
|
3942
|
+
/**
|
|
3943
|
+
* Wire format for xAI search on the BlockRun gateways.
|
|
3944
|
+
*
|
|
3945
|
+
* The SDK's `SearchParameters` / `SearchSource` types are camelCase, but the
|
|
3946
|
+
* gateways validate the OpenAI-style snake_case body (`included_x_handles`,
|
|
3947
|
+
* `from_date`, …) with a non-strict schema that silently strips unknown keys.
|
|
3948
|
+
* Sending the camelCase object verbatim therefore dropped every filter: an
|
|
3949
|
+
* "only these X handles since yesterday" search ran over all of X, all time.
|
|
3950
|
+
* Everything that leaves the SDK goes through {@link toWireSearchParameters}.
|
|
3951
|
+
*
|
|
3952
|
+
* Native xAI search tools (`{ type: "x_search" }` / `{ type: "web_search" }`)
|
|
3953
|
+
* are accepted in `tools` for xai/* models and converted by {@link toWireTools}.
|
|
3954
|
+
* https://docs.x.ai/developers/tools/x-search
|
|
3955
|
+
*/
|
|
3956
|
+
|
|
3957
|
+
type Wire = Record<string, unknown>;
|
|
3958
|
+
/** camelCase `SearchParameters` → the gateway's snake_case `search_parameters`. */
|
|
3959
|
+
declare function toWireSearchParameters(sp: SearchParameters): Wire;
|
|
3960
|
+
/** Function tools pass through; x_search / web_search tools get xAI's field names. */
|
|
3961
|
+
declare function toWireTools(tools: AnyTool[]): Wire[];
|
|
3962
|
+
|
|
3963
|
+
/**
|
|
3964
|
+
* What one paid call actually cost, read from the gateway's PAYMENT-RESPONSE.
|
|
3965
|
+
*
|
|
3966
|
+
* The x402 receipt header is base64 JSON: `{ success, transaction, network,
|
|
3967
|
+
* payer, amount?, extra?: { chargedAmount? } }`. Under batch / metered schemes
|
|
3968
|
+
* the real charge is `extra.chargedAmount` (atomic USDC), else `amount`; under
|
|
3969
|
+
* `exact` neither is set and the signed quote is the charge. The receipt is
|
|
3970
|
+
* decoded best-effort: a missing or malformed header never fails the call.
|
|
3971
|
+
*
|
|
3972
|
+
* Some gateway routes also (or only) set `X-Payment-Receipt`, whose value is
|
|
3973
|
+
* the raw settlement transaction hash, not base64 JSON.
|
|
3974
|
+
*/
|
|
3975
|
+
|
|
3976
|
+
/**
|
|
3977
|
+
* The cost and settlement for one response.
|
|
3978
|
+
*
|
|
3979
|
+
* `costUsd` is the charge the receipt states, else `quotedUsd`.
|
|
3980
|
+
* @param quotedUsd - what was signed (the exact price, or the batch charge the payer reported).
|
|
3981
|
+
* @param scheme - how it was paid.
|
|
3982
|
+
*/
|
|
3983
|
+
declare function readSettlement(response: Response, quotedUsd: number, scheme: Settlement["scheme"]): {
|
|
3984
|
+
costUsd: number;
|
|
3985
|
+
settlement: Settlement;
|
|
3986
|
+
};
|
|
3987
|
+
|
|
3988
|
+
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 };
|