@blockrun/llm 3.8.0 → 3.8.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/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) {
@@ -766,6 +773,7 @@ var LLMClient = class _LLMClient {
766
773
  * @returns ChatResponse object with choices and usage
767
774
  */
768
775
  async chatCompletion(model, messages, options) {
776
+ validateMaxTokens(options?.maxTokens);
769
777
  const buildBody = (m) => {
770
778
  const body = {
771
779
  model: m,
@@ -1036,6 +1044,7 @@ var LLMClient = class _LLMClient {
1036
1044
  * @returns Raw fetch Response with a streaming SSE body.
1037
1045
  */
1038
1046
  async chatCompletionStream(model, messages, options) {
1047
+ validateMaxTokens(options?.maxTokens);
1039
1048
  const url = `${this.apiUrl}/v1/chat/completions`;
1040
1049
  const body = {
1041
1050
  model,
@@ -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,
@@ -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) {
@@ -653,6 +659,7 @@ var LLMClient = class _LLMClient {
653
659
  * @returns ChatResponse object with choices and usage
654
660
  */
655
661
  async chatCompletion(model, messages, options) {
662
+ validateMaxTokens(options?.maxTokens);
656
663
  const buildBody = (m) => {
657
664
  const body = {
658
665
  model: m,
@@ -923,6 +930,7 @@ var LLMClient = class _LLMClient {
923
930
  * @returns Raw fetch Response with a streaming SSE body.
924
931
  */
925
932
  async chatCompletionStream(model, messages, options) {
933
+ validateMaxTokens(options?.maxTokens);
926
934
  const url = `${this.apiUrl}/v1/chat/completions`;
927
935
  const body = {
928
936
  model,
@@ -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,
@@ -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.1",
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",