The direction cosines of a line with respect to the \( x \)-axis, \( y \)-axis, and \( z \)-axis are \( \cos \alpha, \cos \beta, \cos \gamma \), respectively. These satisfy the fundamental relation \( \cos^2 \alpha + \cos^2 \beta + \cos^2 \gamma = 1 \).
Given \( \alpha = \frac{\pi}{4} \) and \( \gamma = \frac{\pi}{4} \), we have \( \cos \alpha = \cos \gamma = \cos\left(\frac{\pi}{4}\right) = \frac{\sqrt{2}}{2} \).
Substituting these values into the equation yields:
\[ \left(\frac{\sqrt{2}}{2}\right)^2 + \cos^2 \beta + \left(\frac{\sqrt{2}}{2}\right)^2 = 1 \]
Simplifying the equation:
\[ \frac{1}{2} + \cos^2 \beta + \frac{1}{2} = 1 \]
\[ 1 + \cos^2 \beta = 1 \]
\[ \cos^2 \beta = 0 \]
This implies \( \cos \beta = 0 \).
The angle \( \beta \) for which \( \cos \beta = 0 \) is \( \beta = \frac{\pi}{2} \).
Final Answer: \( \boxed{\frac{\pi}{2}} \).