5. As shown in Figure 1, in the cube $A C_{1}$ with edge length 1, points $P$ and $Q$ are moving points on edges $A D$ and $A_{1} B_{1}$, respectively. If the skew lines $B D_{1}$ and $P Q$ are perpendicular to each other, then $A P + A_{1} Q =$ $\qquad$
5. 1 .

As shown in Figure 5, establish a spatial rectangular coordinate system, and set
$$
\begin{array}{l} 
B(1,0,0), \\
D_{1}(0,1,1), \\
P(0, a, 0), \\
Q(b, 0,1) . \\
\text { Then } \overrightarrow{B D_{1}}=(-1,1,1), \\
\overrightarrow{P Q}=(b,-a, 1) .
\end{array}
$$
$$
\text { Therefore, } 0=\overrightarrow{B D_{1}} \cdot \overrightarrow{P Q}=-b-a+1 \text {. }
$$

Thus, $a+b=1$.