[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Common/Exception/ -> TokenLimitReachedException.php (source)

   1  <?php
   2  
   3  declare (strict_types=1);
   4  namespace WordPress\AiClient\Common\Exception;
   5  
   6  /**
   7   * Exception thrown when a token limit is reached during prompt fulfillment.
   8   *
   9   * Providers should throw this exception when the token usage for a request
  10   * exceeds the allowed limit, whether that is the model's context window
  11   * or a configured maximum.
  12   *
  13   * @since 1.0.0
  14   */
  15  class TokenLimitReachedException extends \WordPress\AiClient\Common\Exception\RuntimeException
  16  {
  17      /**
  18       * The token limit that was reached, if known.
  19       *
  20       * @since 1.0.0
  21       *
  22       * @var int|null
  23       */
  24      private $maxTokens;
  25      /**
  26       * Creates a new TokenLimitReachedException.
  27       *
  28       * @since 1.0.0
  29       *
  30       * @param string         $message   The exception message.
  31       * @param int|null       $maxTokens The token limit that was reached, if known.
  32       * @param \Throwable|null $previous  The previous throwable used for exception chaining.
  33       */
  34      public function __construct(string $message = '', ?int $maxTokens = null, ?\Throwable $previous = null)
  35      {
  36          parent::__construct($message, 0, $previous);
  37          $this->maxTokens = $maxTokens;
  38      }
  39      /**
  40       * Returns the token limit that was reached, if known.
  41       *
  42       * @since 1.0.0
  43       *
  44       * @return int|null The token limit, or null if not provided.
  45       */
  46      public function getMaxTokens(): ?int
  47      {
  48          return $this->maxTokens;
  49      }
  50  }


Generated : Fri Jul 3 08:20:12 2026 Cross-referenced by PHPXref