Skip to main content

Class: TokenLimitError

Error thrown when a block mode limit has been exceeded.

Examples​

try {
await AI.chat(options)
} catch (error) {
if (error instanceof TokenLimitError) {
console.warn(error.displayMessage)
}
}
tokenLedger.configure({
limits: { perModel: { 'gpt-4o': { window: 'day', maxTokens: 10_000, mode: 'block' } } }
})

See​

tokenLedger.configure

Extends​

  • Error

Constructors​

new TokenLimitError()​

new TokenLimitError(context): TokenLimitError

Parameters​

ParameterTypeDescription
contextTokenLimitErrorContextDetails describing the breached rule and usage metadata.

Returns​

TokenLimitError

Overrides​

Error.constructor

Properties​

PropertyModifierTypeDescriptionInherited from
messagepublicstring-Error.message
modelreadonlystringModel that exceeded the limit.-
namepublicstring-Error.name
rulereadonlyTokenLimitRuleRule that caused the error to be thrown.-
stack?publicstring-Error.stack
usageKind?readonlystringOptional usage classification for context.-
windowreadonlyTokenSummaryWindowWindow in which the error was triggered.-
windowKeyreadonlystringWindow key describing the offending period.-

Accessors​

displayMessage​

Get Signature​

get displayMessage(): string

Message suitable for end-user display.

Returns​

string