If I have $$f(x) = \cos (x^p)$$ and I want to write this function as a real part of the exponential function, then which is correct? $$\cos (x^p) = e^{i(x)^p} \qquad\text{or}\qquad \cos (x^p) = e^{(ix)^p}$$
The first expression feels more natural, but after evaluating some integrals the second expression corresponds to the solutions better.
Neither of your proposed solutions is correct, as $\cos(x^p)$ will be real for any real $x^p$, but $\mathrm{e}^{ix^p}$ and $\mathrm{e}^{(ix)^p}$ will both be complex, non-real numbers for many values of $x^p$. It might be better to think along the following lines:
Recall that for any $\theta \in \mathbb{R}$, Euler's formula tells us that $$ \mathrm{e}^{i\theta} = \cos(\theta) + i\sin(\theta). $$ Since $\theta$ is a real number and the sine and cosine of a real number is again real, we may conclude from this that for any real $\theta$, $$ \Re(\mathrm{e}^{i\theta}) = \cos(\theta). $$ With $\theta = x^p$, with $x$ and $p$ chosen so that $x^p$ is real$^{[1]}$, this gives us $$ \cos(x^p) = \Re\left(\mathrm{e}^{i(x^p)} \right) = \Re\left(\mathrm{e}^{ix^p} \right), $$ which gives $\cos(x^p)$ as the real part of an exponential.
Alternatively, recall if $z \in \mathbb{C}$, then $$ 2\Re(z) = z + \overline{z}. $$ But then $$ 2\Re(\mathrm{e}^{i\theta}) = \mathrm{e}^{i\theta} + \overline{\mathrm{e}^{i\theta}} = \mathrm{e}^{i\theta} + \mathrm{e}^{-i\theta}, $$ which implies that $$ \Re(\mathrm{e}^{i\theta}) = \frac{1}{2} \left( \mathrm{e}^{i\theta} + \mathrm{e}^{-i\theta} \right). $$ But we saw above that $\cos(\theta) = \Re(\mathrm{e}^{i\theta}$, so we can rewrite this last identity as $$ \cos(x^p) = \frac{1}{2} \left( \mathrm{e}^{ix^p} + \mathrm{e}^{-ix^p} \right). $$ Again, we need a priori assumptions that $x^p$ is real in order to make the argument presented here hang together. There are generalizations that allow us to evaluate the cosine of a complex number. These generalizations follow similar lines, but require a little more care.
[1]: It might be easiest to assume that $p$ is real, and that $x > 0$. There are weaker assumptions that will give us $x^p \in \mathbb{R}$, but they are more complicated to state and may not really give us any additional generality.