$request Canonical request. */ public static function request( array $request ): int { $chars = strlen( Json::encode( $request['system'] ?? '' ) ) + strlen( Json::encode( $request['tools'] ?? array() ) ) + strlen( Json::encode( $request['messages'] ?? array() ) ); return (int) ceil( $chars / 2.6 ); } /** * Estimate for a string. * * @param string $text Text. */ public static function text( string $text ): int { return (int) ceil( strlen( $text ) / 2.6 ); } }