No. PEX pipes (including PEX-AL-PEX) cannot be used within the first 18 inches of piping connected to a water heater. Instead, flexible copper or stainless steel connectors are allowed, but they can’t exceed 24 inches in length. This ensures that the materials near the heater are more heat-resistant.