12. Let $a>0$ and $a \neq 1$, the curve $f(x)=\log _{a} x$ is tangent to the curve $g(x)=a^{x}$. Then the value of $a$ is $\qquad$ .
12. $\mathrm{e}^{\frac{1}{e}}$ or $\mathrm{e}^{-\mathrm{e}}$.

As shown in Figure 6, when $a>1$, by the problem's condition, we know that $y=\log _{a} x$ and $y=a^{x}$ are tangent at point $M\left(x_{0}, x_{0}\right)$, with the slope of the tangent line being 1.
Then $\left\{\begin{array}{l}a^{x_{0}}=x_{0}, \\ a^{x_{0}} \ln a=1\end{array} \Rightarrow x_{0}=\frac{1}{\ln a}\right.$.
Thus, $a^{\frac{1}{\ln a}}=\frac{1}{\ln a} \Rightarrow \mathrm{e}=\frac{1}{\ln a} \Rightarrow a=\mathrm{e}^{\frac{1}{e^{2}}}$.
Hence, we get $M(\mathrm{e}, \mathrm{e})$.
As shown in Figure 7, when $0<a<1$, by the problem's condition, we know that $y=\log _{a} x$ and $y=a^{x}$ are tangent at point $P\left(x_{0}, x_{0}\right)$, with the slope of the tangent line being -1.
Then $\left\{\begin{array}{l}a^{x_{0}}=x_{0}, \\ a^{x_{0}} \ln a=-1\end{array} \Rightarrow x_{0}=\frac{-1}{\ln a}\right.$.
Thus, $a^{\frac{-1}{\ln a}}=\frac{-1}{\ln a} \Rightarrow \frac{1}{\mathrm{e}}=\frac{-1}{\ln a} \Rightarrow a=\mathrm{e}^{-\mathrm{e}}$.
Hence, we get $P\left(\frac{1}{\mathrm{e}}, \frac{1}{\mathrm{e}}\right)$.
In summary, when $a=\mathrm{e}^{\frac{1}{c}}$ or $\mathrm{e}^{-\mathrm{e}}$, $y=\log _{a} x$ and $y=a^{x}$ have exactly one common tangent line.