AccidentalFourierTransform has already given a good answer. Here we will provide more details & justifications for a class of non-gauge derivative interactions.
We start from a Lagrangian action,
$$\begin{align} S[Q]~=~&\int_{t_i}^{t_f}\! dt~ L~=~S_0[Q]+S_{\rm int}[Q], \cr
L~=~& L_0(Q,\dot{Q})+L_{\rm int}(Q,\dot{Q}),\cr
S_0[Q]~=~&\int_{t_i}^{t_f}\! dt~ L_0(Q,\dot{Q}), \cr
L_0(Q,\dot{Q})~=~&\frac{1}{2}\dot{Q}^2~=~\frac{1}{2} \dot{Q}^i G_{ij} \dot{Q}^j,\cr
S_{\rm int}[Q]~=~&\int_{t_i}^{t_f}\! dt~ L_{\rm int}(Q,\dot{Q}), \cr
L_{\rm int}(Q,\dot{Q})~=~&A_i\dot{Q}^i - V, \cr
G_{ij}~=~&G_{ij}(Q), \qquad
A_i~=~A_i(Q), \qquad
V~=~V(Q), \end{align} \tag{1}$$
which is quadratic in velocities. We shall assume that the Lagrangian action (1) is manifestly Lorentz covariant. [We are using DeWitt condensed notation$^1$ to suppress spatial (but not temporal) dimensions, which may superficially obscure the manifest Lorentz covariance. So e.g. the $\frac{1}{2}\dot{Q}^2$ term in $L_0$ is implicitly accompanied by a $\frac{1}{2}(\nabla Q)^2$ term in $V$, and so forth. Source terms $J_iQ^i$ are also assumed to be inside $V$.]
The canonical momentum read
$$ P_i~=~G_{ij}\dot{Q}^j+A_i.\tag{2}$$ We stress that
the corresponding Hamiltonian action is also Lorentz covariant,
$$\begin{align} S_H[Q,P]~=~&\int_{t_i}^{t_f}\! dt~ L_H~=~S_{H,0}[Q,P]+S_{H,{\rm int}}[Q,P], \cr
L_H~=~&P_i \dot{Q}^i-H(Q,P), \cr
H(Q,P)~=~&H_0(Q,P)+H_{\rm int}(Q,P), \cr
S_{H,0}[Q,P]~=~&\int_{t_i}^{t_f}\! dt~ L_{H,0}, \cr
L_{H,0} ~=~&P_i \dot{Q}^i-H_0(Q,P), \cr H_0(Q,P)~=~&\frac{1}{2}P^2~=~\frac{1}{2}P_i G^{ij}P_j,\cr
S_{H,{\rm int}}[Q,P] ~=~&-\int_{t_i}^{t_f}\! dt~H_{\rm int}(Q,P), \cr
H_{\rm int}(Q,P)~=~& -A^iP_i + \color{red}{\frac{1}{2} A^2}+V,\end{align}\tag{3}$$
despite the non-covariant term $A^2:=A_iG^{ij}A_j$ marked in red in eq. (3). We did not put this in by hand. It actually comes from doing the Legendre transformation properly.
We mention (for a later instructive comparison with eq. (6) below) that
$$ L_{\rm int}(Q,\dot{Q})+H_{\rm int}(Q,P)
~\stackrel{(1)+(2)+(3)}{=}~
- \color{red}{\frac{1}{2} A^2(Q)},\tag{4}$$
although eq. (4) will not be used in what follows. Eq. (4) corresponds to OP's second formula.
So far we have only discussed the classical theory. In the corresponding quantum mechanical operator formulation, the operators $\hat{Q}^i$ and $\hat{P}_j$ are in the Heisenberg picture.
We next consider the interaction picture. Here velocity and momentum are related via
$$\dot{q}^i~=~\frac{\partial H_0(q,p)}{\partial p_i}~=~G^{ij}p_j,\tag{5}$$
which should be compared with the corresponding relation (2) in the Heisenberg picture. Eq. (5) has two consequences.
Firstly, we derive the somewhat surprising relation
$$\begin{align} L_{\rm int}(q,\dot{q})+H_{\rm int}(q,p)
~\stackrel{(5)}{=}~&L_{\rm int}(q,\dot{q})+H_{\rm int}(q,G\dot{q})\cr
~\stackrel{(1)+(3)}{=}&+\color{red}{\frac{1}{2} A^2(q)},\end{align}\tag{6}$$
which has the opposite sign of eq. (4)! This sign of eq. (6) will be important in what follows.
Secondly, eq. (5) implies the equal-time CCR
$$\begin{align}
[\hat{q}^i(t),\dot{\hat{q}}^j(t)]
~\stackrel{(5)}{=}~&i\hbar~ G^{ij} {\bf 1},\cr
[\hat{q}^i(t),\hat{q}^j(t)]~=~&0.
\end{align} \tag{7} $$
We derive that the covariant time-ordering is
$$\begin{align}
T_{\rm cov}\{\hat{q}^i(t_1)\hat{q}^j(t_2)\}
~\equiv~& T\{\hat{q}^i(t_1)\hat{q}^j(t_2)\},\cr
T_{\rm cov}\{\hat{q}^i(t_1)\dot{\hat{q}}^j(t_2)\}
~\equiv~&\frac{d}{dt_2}
T\{\hat{q}^i(t_1)\hat{q}^j(t_2)\}\cr
~=~&\frac{d}{dt_2}\left\{\theta(t_1\!-\!t_2)\hat{q}^i(t_1)\hat{q}^j(t_2)+ \theta(t_2\!-\!t_1)\hat{q}^j(t_2)\hat{q}^i(t_1)\right\}\cr
~=~&T \{\hat{q}^i(t_1)\dot{\hat{q}}^j(t_2)\}
-\delta(t_1\!-\!t_2)[\hat{q}^i(t_1),\hat{q}^j(t_2)]\cr
~\stackrel{(7)}{=}~&T \{\hat{q}^i(t_1)\dot{\hat{q}}^j(t_2)\},\cr
T_{\rm cov} \{\dot{\hat{q}}^i(t_1)\dot{\hat{q}}^j(t_2)\}
~\equiv~&\frac{d}{dt_1}\frac{d}{dt_2}
T \{\hat{q}^i(t_1)\hat{q}^j(t_2)\}\cr
~=~&\frac{d}{dt_1}T \{\hat{q}^i(t_1)\dot{\hat{q}}^j(t_2)\}\cr
~=~&\frac{d}{dt_1}\left\{\theta(t_1\!-\!t_2)\hat{q}^i(t_1)\dot{\hat{q}}^j(t_2)+ \theta(t_2\!-\!t_1)\dot{\hat{q}}^j(t_2)\hat{q}^i(t_1) \right\} \cr
~\stackrel{(7)}{=}~&T \{\dot{\hat{q}}^i(t_1)\dot{\hat{q}}^j(t_2)\} ~+~\color{red}{i\hbar~ G^{ij} {\bf 1} \delta(t_1\!-\!t_2)}. \end{align}\tag{8}$$
We have marked the non-covariant term in red.
Consider next a Wilson line
$$ \exp\left\{ \frac{i}{\hbar}\int\!dt~ A_i(q)\dot{q}^i \right\}. \tag{9}$$
From Wick's theorem, eq. (8) exponentiates to
$$\begin{align} T_{\rm cov}\exp & \left\{ \frac{i}{\hbar}\int\!dt~ A_i(\hat{q})\dot{\hat{q}}^i \right\}\cr
~\stackrel{(8)}{=}~&\exp\left\{
\color{red}{ \frac{i\hbar}{2} \iint dt_1 ~dt_2~G^{ij} \frac{\delta}{\delta \dot{\hat{q}}^i(t_1)} \frac{\delta}{\delta \dot{\hat{q}}^j(t_2)} }\right\}\cr
&\qquad T\exp\left\{ \frac{i}{\hbar}\int\!dt~ A_i(\hat{q})\dot{\hat{q}}^i \right\}\cr
~=~&T\exp\left\{ \frac{i}{\hbar}\int\!dt\left( A_i(\hat{q})\dot{\hat{q}}^i -\color{red}{\frac{1}{2} A^2(\hat{q})} \right)\right\} .\end{align} \tag{10}$$
The standard derivation$^2$ of the Hamiltonian phase space path integral/partition function from the operator formalism in the Heisenberg picture goes like this
$$\begin{align}
Z_H~\sim~~~&{}_H\langle Q_f,t_f |Q_i,t_i\rangle_H \cr
~=~~~&{}_H\langle Q_f,0| T_{\rm cov} \exp\left\{ - \frac{i}{\hbar}\int_{t_i}^{t_f}\!dt~ H(\hat{Q},\hat{P})\right\} |Q_i,0\rangle_H \cr
~=~~~&{}_H\langle Q_f,0| T \exp\left\{ - \frac{i}{\hbar}\int_{t_i}^{t_f}\!dt~ H(\hat{Q},\hat{P})\right\} |Q_i,0\rangle_H \cr
~=~~~&\int_{Q(t_i)=Q_i}^{Q(t_f)=Q_f}\! {\cal D}Q~{\cal D}P~\exp\left\{ \frac{i}{\hbar}S_H[Q,P]\right\}\cr
\stackrel{\text{Gauss. int.}}{\sim}&\int_{Q(t_i)=Q_i}^{Q(t_f)=Q_f}\! {\cal D}Q~ {\rm Det}(G_{ij})^{1/2} \exp\left\{ \frac{i}{\hbar} S[Q]\right\}
. \end{align} \tag{11}$$
In the interaction picture we have$^3$
$$\begin{align}
Z_H~\sim~& {}_H\langle q_f,0| T_{\rm cov} \exp\left\{ - \frac{i}{\hbar}\int\!dt~ H_{\rm int}(\hat{q},\hat{p})\right\}|q_i,0\rangle_H \cr
~=~&{}_H\langle q_f,0| T \exp\left\{ - \frac{i}{\hbar}\int\!dt~ H_{\rm int}(\hat{q},\hat{p})\right\}|q_i,0\rangle_H \cr
~\stackrel{(5)}{=}~&{}_H\langle q_f,0| T \exp\left\{ - \frac{i}{\hbar}\int\!dt~ H_{\rm int}(\hat{q},G\dot{\hat{q}})\right\}|q_i,0\rangle_H \cr
~\stackrel{(6)}{=}~&{}_H\langle q_f,0| T \exp\left\{ \frac{i}{\hbar}\int\!dt\left( L_{\rm int}(\hat{q},\dot{\hat{q}})-\color{red}{\frac{1}{2} A^2(\hat{q})} \right)\right\}|q_i,0\rangle_H \cr
~\stackrel{(10)}{=}~&{}_H\langle q_f,0| T_{\rm cov} \exp\left\{ \frac{i}{\hbar}\int\!dt~ L_{\rm int}(\hat{q},\dot{\hat{q}})\right\}|q_i,0\rangle_H
.\end{align}\tag{12}$$
We find that two effects cancel each other, the non-covariant term in the interaction Hamiltonian (6) and the Wick's theorem (10), so that the partition function (12) is Lorentz covariant. This is the main answer to OP's question.
We suggest for completeness an interaction picture phase space path integral
$$\begin{align} Z_H~\stackrel{(12)}{\sim}~~~&
\int_{q(t_i)=q_i}^{q(t_f)=q_f}\! {\cal D}q~{\cal D}p~\cr &\exp\left\{ \frac{i}{\hbar} S_{H,0}[q,p] +\frac{i}{\hbar}\int_{t_i}^{t_f}\!dt \left(-\frac{1}{2}\dot{q}^2 + L_{\rm int}(\hat{q},\dot{\hat{q}}) \right)\right\}\cr
~\stackrel{\text{Gauss. int.}}{\sim}&
\int_{q(t_i)=q_i}^{q(t_f)=q_f}\! {\cal D}q~ {\rm Det}(G_{ij})^{1/2} \exp\left\{ \frac{i}{\hbar} \int_{t_i}^{t_f}\!dt~ L_{\rm int}(\hat{q},\dot{\hat{q}}) \right\}. \end{align}\tag{13}$$
The naive Lagrangian path integral
$$Z_L~\sim~\int_{Q(t_i)=Q_i}^{Q(t_f)=Q_f}\! {\cal D}Q~ \exp\left\{ \frac{i}{\hbar} S[Q]\right\} \tag{14}$$
may differ from the Hamiltonian phase space path integral (11) because it lacks the determinant from the Gaussian integration over momenta $P_j$. In practice, it is often implicitly implied that the path integral measure ${\cal D}Q$ in eq. (14) contains this determinant factor by definition. In other words, the definition of $Z_L$ is tweaked to agree with $Z_H$. See also this related Phys.SE post.