4. The function
$$
y=\frac{1}{|\sin x|}+\frac{1}{|\cos x|}+\frac{1}{|\tan x|}+\frac{1}{|\cot x|}
$$

has a minimum value of
4. $2(\sqrt{2}+1)$.

It is easy to know that the given function is an even function, and $\pi$ is one of its periods. Therefore, we only need to find the minimum value when $x \in\left(0, \frac{\pi}{2}\right)$.
When $x \in\left(0, \frac{\pi}{2}\right)$,
$y=\frac{1}{\sin x}+\frac{1}{\cos x}+\frac{1}{\tan x}+\frac{1}{\cot x}$
$=\frac{1+\sin x+\cos x}{\sin x \cdot \cos x}$.
Let $t=\sin x+\cos x$. It is known that $1<t \leqslant \sqrt{2}$.
Then $\sin x \cdot \cos x=\frac{t^{2}-1}{2}$.
Thus, $y=\frac{2}{t-1} \geqslant \frac{2}{\sqrt{2}-1}=2(\sqrt{2}+1)$.
Therefore, when $x=k \pi+\frac{\pi}{4}(k \in \mathbf{Z})$, $y$ achieves its minimum value $2(\sqrt{2}+1)$.