Inverting opamp amplifier
It seems you are confusing the open loop gain of the OpAmp (which is just the component) with the gain of the whole circuit.
What if you consider the OpAmp as ideal except for the infinite open loop gain:

$$\frac{V_{neg}-V_{in}}{R_i}=\frac{V_{out}-V_{neg}}{Rf}$$
$$(V_{pos} = 0) \rightarrow V_{out} = -KV_{neg}$$
Replace Vneg in the first equation.
$$R_f * \frac{-V_{out}}{K} - Rf V_{in} = R_i V_{out} + \frac{R_i V_{out}}{K} $$
And isolate real gain:
$$\frac{V_{out}}{V_{in}} = \frac{-Rf K}{RiK + Ri + Rf}$$
As the open loop gain K tends to infinity, the real gain tends to the ideal formula.
$$\frac{V_{out}}{V_{in}} = \frac{-Rf}{Ri}$$