Solution (source code)

= Solution

For a timelike worldline, $-\eta_{\mu\nu}\dot x^\mu\dot x^\nu>0$. Its square root is a Lorentz scalar, and
$$
\sqrt{-\eta_{\mu\nu}\dot x^\mu\dot x^\nu}\,d\lambda
=\sqrt{-\eta_{\mu\nu}dx^\mu dx^\nu}
=c\,d\tau.
$$
Thus the first term is the Lorentz-invariant free-particle action $-mc^2\int d\tau$. Written as a line element, it is also invariant under a change of the worldline parameter $\lambda$.

The interaction is the scalar line integral
$$
q\int A_\mu dx^\mu.
$$
Under an electromagnetic <gauge transformation>
$$
A_\mu\longmapsto A_\mu+\partial_\mu\chi,
$$
it changes only by
$$
q\int\partial_\mu\chi\,dx^\mu
=q\,[\chi]_{\rm endpoints}.
$$
This endpoint term does not affect a fixed-endpoint variational problem. Hence both Lorentz invariance and gauge invariance select the displayed <relativistic charged-particle action>, with the expected free-particle and minimal-coupling terms.