@blockrun/llm 3.8.0 → 3.8.2

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/dist/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  ImageClient: () => ImageClient,
39
39
  KNOWN_PROVIDERS: () => KNOWN_PROVIDERS,
40
40
  LLMClient: () => LLMClient,
41
+ MAX_TOKENS_SANITY_LIMIT: () => MAX_TOKENS_SANITY_LIMIT,
41
42
  MusicClient: () => MusicClient,
42
43
  NETWORK_ALIASES: () => NETWORK_ALIASES,
43
44
  OpenAI: () => OpenAI,
@@ -355,6 +356,7 @@ function validateModel(model) {
355
356
  throw new Error("Model must be a non-empty string");
356
357
  }
357
358
  }
359
+ var MAX_TOKENS_SANITY_LIMIT = 1e6;
358
360
  function validateMaxTokens(maxTokens) {
359
361
  if (maxTokens === void 0 || maxTokens === null) {
360
362
  return;
@@ -365,8 +367,13 @@ function validateMaxTokens(maxTokens) {
365
367
  if (maxTokens < 1) {
366
368
  throw new Error("maxTokens must be positive (minimum: 1)");
367
369
  }
368
- if (maxTokens > 1e5) {
369
- throw new Error("maxTokens too large (maximum: 100000)");
370
+ if (maxTokens > MAX_TOKENS_SANITY_LIMIT) {
371
+ throw Object.assign(
372
+ new Error(
373
+ `maxTokens implausibly large (client-side sanity limit: ${MAX_TOKENS_SANITY_LIMIT}). This is not a model limit \u2014 the gateway enforces the real per-model ceiling and reports it.`
374
+ ),
375
+ { code: "MAX_TOKENS_SANITY_LIMIT", limit: MAX_TOKENS_SANITY_LIMIT }
376
+ );
370
377
  }
371
378
  }
372
379
  function validateTemperature(temperature) {
@@ -506,6 +513,10 @@ function getCostSummary() {
506
513
  return { totalUsd, calls, byModel, byEndpoint };
507
514
  }
508
515
 
516
+ // src/version.ts
517
+ var SDK_VERSION = "3.8.2";
518
+ var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
519
+
509
520
  // src/client.ts
510
521
  function isTransientError(err) {
511
522
  if (err instanceof PaymentError) return false;
@@ -568,8 +579,6 @@ function resolveDefaultTimeout() {
568
579
  return 6e5;
569
580
  }
570
581
  var DEFAULT_TIMEOUT = resolveDefaultTimeout();
571
- var SDK_VERSION = "1.5.0";
572
- var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
573
582
  var LLMClient = class _LLMClient {
574
583
  static DEFAULT_API_URL = DEFAULT_API_URL;
575
584
  account;
@@ -766,6 +775,7 @@ var LLMClient = class _LLMClient {
766
775
  * @returns ChatResponse object with choices and usage
767
776
  */
768
777
  async chatCompletion(model, messages, options) {
778
+ validateMaxTokens(options?.maxTokens);
769
779
  const buildBody = (m) => {
770
780
  const body = {
771
781
  model: m,
@@ -1036,6 +1046,7 @@ var LLMClient = class _LLMClient {
1036
1046
  * @returns Raw fetch Response with a streaming SSE body.
1037
1047
  */
1038
1048
  async chatCompletionStream(model, messages, options) {
1049
+ validateMaxTokens(options?.maxTokens);
1039
1050
  const url = `${this.apiUrl}/v1/chat/completions`;
1040
1051
  const body = {
1041
1052
  model,
@@ -5013,8 +5024,6 @@ async function getOrCreateSolanaWallet() {
5013
5024
  var SOLANA_API_URL = "https://sol.blockrun.ai/api";
5014
5025
  var DEFAULT_MAX_TOKENS2 = 1024;
5015
5026
  var DEFAULT_TIMEOUT14 = 6e4;
5016
- var SDK_VERSION2 = "0.3.0";
5017
- var USER_AGENT2 = `blockrun-ts/${SDK_VERSION2}`;
5018
5027
  var DEFAULT_SOLANA_RPC_URL = "https://sol.blockrun.ai/api/v1/solana/rpc";
5019
5028
  function resolveRpcConfig(rpcUrl, rpcHeaders) {
5020
5029
  const env = typeof process !== "undefined" && process.env ? process.env : {};
@@ -5087,6 +5096,7 @@ var SolanaLLMClient = class {
5087
5096
  }
5088
5097
  /** Full chat completion (OpenAI-compatible). */
5089
5098
  async chatCompletion(model, messages, options) {
5099
+ validateMaxTokens(options?.maxTokens);
5090
5100
  const body = {
5091
5101
  model,
5092
5102
  messages,
@@ -5344,7 +5354,7 @@ var SolanaLLMClient = class {
5344
5354
  const url = `${this.apiUrl}${endpoint}`;
5345
5355
  const response = await this.fetchWithTimeout(url, {
5346
5356
  method: "POST",
5347
- headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT2 },
5357
+ headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT },
5348
5358
  body: JSON.stringify(body)
5349
5359
  });
5350
5360
  if (response.status === 402) {
@@ -5410,7 +5420,7 @@ var SolanaLLMClient = class {
5410
5420
  method: "POST",
5411
5421
  headers: {
5412
5422
  "Content-Type": "application/json",
5413
- "User-Agent": USER_AGENT2,
5423
+ "User-Agent": USER_AGENT,
5414
5424
  "PAYMENT-SIGNATURE": paymentPayload
5415
5425
  },
5416
5426
  body: JSON.stringify(body)
@@ -5436,7 +5446,7 @@ var SolanaLLMClient = class {
5436
5446
  const url = `${this.apiUrl}${endpoint}`;
5437
5447
  const response = await this.fetchWithTimeout(url, {
5438
5448
  method: "POST",
5439
- headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT2 },
5449
+ headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT },
5440
5450
  body: JSON.stringify(body)
5441
5451
  });
5442
5452
  if (response.status === 402) {
@@ -5502,7 +5512,7 @@ var SolanaLLMClient = class {
5502
5512
  method: "POST",
5503
5513
  headers: {
5504
5514
  "Content-Type": "application/json",
5505
- "User-Agent": USER_AGENT2,
5515
+ "User-Agent": USER_AGENT,
5506
5516
  "PAYMENT-SIGNATURE": paymentPayload
5507
5517
  },
5508
5518
  body: JSON.stringify(body)
@@ -5529,7 +5539,7 @@ var SolanaLLMClient = class {
5529
5539
  const url = `${this.apiUrl}${endpoint}${query}`;
5530
5540
  const response = await this.fetchWithTimeout(url, {
5531
5541
  method: "GET",
5532
- headers: { "User-Agent": USER_AGENT2 }
5542
+ headers: { "User-Agent": USER_AGENT }
5533
5543
  });
5534
5544
  if (response.status === 402) {
5535
5545
  return this.handleGetPaymentAndRetryRaw(url, endpoint, params, response);
@@ -5595,7 +5605,7 @@ var SolanaLLMClient = class {
5595
5605
  const retryResponse = await this.fetchWithTimeout(retryUrl, {
5596
5606
  method: "GET",
5597
5607
  headers: {
5598
- "User-Agent": USER_AGENT2,
5608
+ "User-Agent": USER_AGENT,
5599
5609
  "PAYMENT-SIGNATURE": paymentPayload
5600
5610
  }
5601
5611
  });
@@ -6129,6 +6139,7 @@ var AnthropicClient = class {
6129
6139
  ImageClient,
6130
6140
  KNOWN_PROVIDERS,
6131
6141
  LLMClient,
6142
+ MAX_TOKENS_SANITY_LIMIT,
6132
6143
  MusicClient,
6133
6144
  NETWORK_ALIASES,
6134
6145
  OpenAI,
package/dist/index.d.cts CHANGED
@@ -3161,7 +3161,34 @@ declare const KNOWN_PROVIDERS: Set<string>;
3161
3161
  */
3162
3162
  declare function validateModel(model: string): void;
3163
3163
  /**
3164
- * Validates that max_tokens is an integer between 1 and 100,000.
3164
+ * Client-side typo guard, NOT a model limit. The gateway already enforces the
3165
+ * real per-model ceiling and rejects with that model's own number, so anything
3166
+ * hardcoded here can only be wrong in one direction: too low.
3167
+ *
3168
+ * This was 100000. Note what it was and was not doing: until this change no
3169
+ * client called `validateMaxTokens` at all, so the bound bound nothing on a
3170
+ * real request — it only rejected callers who imported the validator directly
3171
+ * off the package's public surface. The guard is now wired into
3172
+ * `LLMClient.chatCompletion`, `LLMClient.chatCompletionStream`, and
3173
+ * `SolanaLLMClient.chatCompletion`, which is exactly why the number had to go
3174
+ * up first: at 100000 it would have started rejecting real requests.
3175
+ *
3176
+ * Verified against the live gateway 2026-07-21
3177
+ * with the guard bypassed: zai/glm-5.2 accepted 262144, and the whole 128000
3178
+ * class accepted 128000 (claude-opus-4.8, claude-sonnet-5, claude-fable-5,
3179
+ * gpt-5.6-sol/terra/luna, gpt-5.5, gpt-5.4, gpt-5.3-codex, glm-5/5.1/5-turbo).
3180
+ * 19 models advertised above 100000; all 19 accepted their ceiling. Those are
3181
+ * as-of-date probe results, not a maintained invariant — nothing in this repo
3182
+ * ships a model catalog, so CI cannot detect when they go stale.
3183
+ *
3184
+ * Keep a bound so an obvious mistake (1e9, a byte count, a timestamp) fails
3185
+ * fast locally instead of becoming a payment quote. Set it far above any real
3186
+ * model so it can never be the binding constraint again.
3187
+ */
3188
+ declare const MAX_TOKENS_SANITY_LIMIT = 1000000;
3189
+ /**
3190
+ * Validates that max_tokens is a positive integer no larger than
3191
+ * {@link MAX_TOKENS_SANITY_LIMIT}.
3165
3192
  *
3166
3193
  * @param maxTokens - Maximum number of tokens to generate
3167
3194
  * @throws {Error} If maxTokens is invalid
@@ -3191,4 +3218,4 @@ declare function validateTemperature(temperature?: number): void;
3191
3218
  */
3192
3219
  declare function validateTopP(topP?: number): void;
3193
3220
 
3194
- export { APIError, AnthropicClient, 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, 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, type RoutingDecision, type RoutingProfile, type RoutingTier, 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 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, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
3221
+ export { APIError, AnthropicClient, 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, MAX_TOKENS_SANITY_LIMIT, 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, 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, type RoutingDecision, type RoutingProfile, type RoutingTier, 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 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, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
package/dist/index.d.ts CHANGED
@@ -3161,7 +3161,34 @@ declare const KNOWN_PROVIDERS: Set<string>;
3161
3161
  */
3162
3162
  declare function validateModel(model: string): void;
3163
3163
  /**
3164
- * Validates that max_tokens is an integer between 1 and 100,000.
3164
+ * Client-side typo guard, NOT a model limit. The gateway already enforces the
3165
+ * real per-model ceiling and rejects with that model's own number, so anything
3166
+ * hardcoded here can only be wrong in one direction: too low.
3167
+ *
3168
+ * This was 100000. Note what it was and was not doing: until this change no
3169
+ * client called `validateMaxTokens` at all, so the bound bound nothing on a
3170
+ * real request — it only rejected callers who imported the validator directly
3171
+ * off the package's public surface. The guard is now wired into
3172
+ * `LLMClient.chatCompletion`, `LLMClient.chatCompletionStream`, and
3173
+ * `SolanaLLMClient.chatCompletion`, which is exactly why the number had to go
3174
+ * up first: at 100000 it would have started rejecting real requests.
3175
+ *
3176
+ * Verified against the live gateway 2026-07-21
3177
+ * with the guard bypassed: zai/glm-5.2 accepted 262144, and the whole 128000
3178
+ * class accepted 128000 (claude-opus-4.8, claude-sonnet-5, claude-fable-5,
3179
+ * gpt-5.6-sol/terra/luna, gpt-5.5, gpt-5.4, gpt-5.3-codex, glm-5/5.1/5-turbo).
3180
+ * 19 models advertised above 100000; all 19 accepted their ceiling. Those are
3181
+ * as-of-date probe results, not a maintained invariant — nothing in this repo
3182
+ * ships a model catalog, so CI cannot detect when they go stale.
3183
+ *
3184
+ * Keep a bound so an obvious mistake (1e9, a byte count, a timestamp) fails
3185
+ * fast locally instead of becoming a payment quote. Set it far above any real
3186
+ * model so it can never be the binding constraint again.
3187
+ */
3188
+ declare const MAX_TOKENS_SANITY_LIMIT = 1000000;
3189
+ /**
3190
+ * Validates that max_tokens is a positive integer no larger than
3191
+ * {@link MAX_TOKENS_SANITY_LIMIT}.
3165
3192
  *
3166
3193
  * @param maxTokens - Maximum number of tokens to generate
3167
3194
  * @throws {Error} If maxTokens is invalid
@@ -3191,4 +3218,4 @@ declare function validateTemperature(temperature?: number): void;
3191
3218
  */
3192
3219
  declare function validateTopP(topP?: number): void;
3193
3220
 
3194
- export { APIError, AnthropicClient, 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, 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, type RoutingDecision, type RoutingProfile, type RoutingTier, 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 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, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
3221
+ export { APIError, AnthropicClient, 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, MAX_TOKENS_SANITY_LIMIT, 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, 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, type RoutingDecision, type RoutingProfile, type RoutingTier, 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 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, setupAgentSolanaWallet, setupAgentWallet, solanaClient, solanaKeyToBytes, solanaPublicKey, status, validateMaxTokens, validateModel, validateTemperature, validateTopP };
package/dist/index.js CHANGED
@@ -242,6 +242,7 @@ function validateModel(model) {
242
242
  throw new Error("Model must be a non-empty string");
243
243
  }
244
244
  }
245
+ var MAX_TOKENS_SANITY_LIMIT = 1e6;
245
246
  function validateMaxTokens(maxTokens) {
246
247
  if (maxTokens === void 0 || maxTokens === null) {
247
248
  return;
@@ -252,8 +253,13 @@ function validateMaxTokens(maxTokens) {
252
253
  if (maxTokens < 1) {
253
254
  throw new Error("maxTokens must be positive (minimum: 1)");
254
255
  }
255
- if (maxTokens > 1e5) {
256
- throw new Error("maxTokens too large (maximum: 100000)");
256
+ if (maxTokens > MAX_TOKENS_SANITY_LIMIT) {
257
+ throw Object.assign(
258
+ new Error(
259
+ `maxTokens implausibly large (client-side sanity limit: ${MAX_TOKENS_SANITY_LIMIT}). This is not a model limit \u2014 the gateway enforces the real per-model ceiling and reports it.`
260
+ ),
261
+ { code: "MAX_TOKENS_SANITY_LIMIT", limit: MAX_TOKENS_SANITY_LIMIT }
262
+ );
257
263
  }
258
264
  }
259
265
  function validateTemperature(temperature) {
@@ -393,6 +399,10 @@ function getCostSummary() {
393
399
  return { totalUsd, calls, byModel, byEndpoint };
394
400
  }
395
401
 
402
+ // src/version.ts
403
+ var SDK_VERSION = "3.8.2";
404
+ var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
405
+
396
406
  // src/client.ts
397
407
  function isTransientError(err) {
398
408
  if (err instanceof PaymentError) return false;
@@ -455,8 +465,6 @@ function resolveDefaultTimeout() {
455
465
  return 6e5;
456
466
  }
457
467
  var DEFAULT_TIMEOUT = resolveDefaultTimeout();
458
- var SDK_VERSION = "1.5.0";
459
- var USER_AGENT = `blockrun-ts/${SDK_VERSION}`;
460
468
  var LLMClient = class _LLMClient {
461
469
  static DEFAULT_API_URL = DEFAULT_API_URL;
462
470
  account;
@@ -653,6 +661,7 @@ var LLMClient = class _LLMClient {
653
661
  * @returns ChatResponse object with choices and usage
654
662
  */
655
663
  async chatCompletion(model, messages, options) {
664
+ validateMaxTokens(options?.maxTokens);
656
665
  const buildBody = (m) => {
657
666
  const body = {
658
667
  model: m,
@@ -923,6 +932,7 @@ var LLMClient = class _LLMClient {
923
932
  * @returns Raw fetch Response with a streaming SSE body.
924
933
  */
925
934
  async chatCompletionStream(model, messages, options) {
935
+ validateMaxTokens(options?.maxTokens);
926
936
  const url = `${this.apiUrl}/v1/chat/completions`;
927
937
  const body = {
928
938
  model,
@@ -4900,8 +4910,6 @@ async function getOrCreateSolanaWallet() {
4900
4910
  var SOLANA_API_URL = "https://sol.blockrun.ai/api";
4901
4911
  var DEFAULT_MAX_TOKENS2 = 1024;
4902
4912
  var DEFAULT_TIMEOUT14 = 6e4;
4903
- var SDK_VERSION2 = "0.3.0";
4904
- var USER_AGENT2 = `blockrun-ts/${SDK_VERSION2}`;
4905
4913
  var DEFAULT_SOLANA_RPC_URL = "https://sol.blockrun.ai/api/v1/solana/rpc";
4906
4914
  function resolveRpcConfig(rpcUrl, rpcHeaders) {
4907
4915
  const env = typeof process !== "undefined" && process.env ? process.env : {};
@@ -4974,6 +4982,7 @@ var SolanaLLMClient = class {
4974
4982
  }
4975
4983
  /** Full chat completion (OpenAI-compatible). */
4976
4984
  async chatCompletion(model, messages, options) {
4985
+ validateMaxTokens(options?.maxTokens);
4977
4986
  const body = {
4978
4987
  model,
4979
4988
  messages,
@@ -5231,7 +5240,7 @@ var SolanaLLMClient = class {
5231
5240
  const url = `${this.apiUrl}${endpoint}`;
5232
5241
  const response = await this.fetchWithTimeout(url, {
5233
5242
  method: "POST",
5234
- headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT2 },
5243
+ headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT },
5235
5244
  body: JSON.stringify(body)
5236
5245
  });
5237
5246
  if (response.status === 402) {
@@ -5297,7 +5306,7 @@ var SolanaLLMClient = class {
5297
5306
  method: "POST",
5298
5307
  headers: {
5299
5308
  "Content-Type": "application/json",
5300
- "User-Agent": USER_AGENT2,
5309
+ "User-Agent": USER_AGENT,
5301
5310
  "PAYMENT-SIGNATURE": paymentPayload
5302
5311
  },
5303
5312
  body: JSON.stringify(body)
@@ -5323,7 +5332,7 @@ var SolanaLLMClient = class {
5323
5332
  const url = `${this.apiUrl}${endpoint}`;
5324
5333
  const response = await this.fetchWithTimeout(url, {
5325
5334
  method: "POST",
5326
- headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT2 },
5335
+ headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT },
5327
5336
  body: JSON.stringify(body)
5328
5337
  });
5329
5338
  if (response.status === 402) {
@@ -5389,7 +5398,7 @@ var SolanaLLMClient = class {
5389
5398
  method: "POST",
5390
5399
  headers: {
5391
5400
  "Content-Type": "application/json",
5392
- "User-Agent": USER_AGENT2,
5401
+ "User-Agent": USER_AGENT,
5393
5402
  "PAYMENT-SIGNATURE": paymentPayload
5394
5403
  },
5395
5404
  body: JSON.stringify(body)
@@ -5416,7 +5425,7 @@ var SolanaLLMClient = class {
5416
5425
  const url = `${this.apiUrl}${endpoint}${query}`;
5417
5426
  const response = await this.fetchWithTimeout(url, {
5418
5427
  method: "GET",
5419
- headers: { "User-Agent": USER_AGENT2 }
5428
+ headers: { "User-Agent": USER_AGENT }
5420
5429
  });
5421
5430
  if (response.status === 402) {
5422
5431
  return this.handleGetPaymentAndRetryRaw(url, endpoint, params, response);
@@ -5482,7 +5491,7 @@ var SolanaLLMClient = class {
5482
5491
  const retryResponse = await this.fetchWithTimeout(retryUrl, {
5483
5492
  method: "GET",
5484
5493
  headers: {
5485
- "User-Agent": USER_AGENT2,
5494
+ "User-Agent": USER_AGENT,
5486
5495
  "PAYMENT-SIGNATURE": paymentPayload
5487
5496
  }
5488
5497
  });
@@ -6015,6 +6024,7 @@ export {
6015
6024
  ImageClient,
6016
6025
  KNOWN_PROVIDERS,
6017
6026
  LLMClient,
6027
+ MAX_TOKENS_SANITY_LIMIT,
6018
6028
  MusicClient,
6019
6029
  NETWORK_ALIASES,
6020
6030
  OpenAI,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/llm",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
4
  "type": "module",
5
5
  "description": "BlockRun SDK - Pay-per-request AI (LLM, Image, Video, Music, Voice) via x402 on Base and Solana",
6
6
  "main": "dist/index.cjs",