Bound for number of points on surface over $\mathbb{F}_p$

$\DeclareMathOperator{\char}{char}$The general form that this bound takes is known under the term Weil conjectures, which is a theorem of Deligne. Here is how it goes.

If $X$ is a non-singular $n$-dimensional projective variety over $\mathbb{F}_q$, (an elliptic curve is the special case $n=1$), then you collect information about the number $N_m$ of points of $X$ over $\mathbb{F}_{q^m}$ for all $m$ in the generating function $$ \zeta(X, s) = \exp\left(\sum_{m = 1}^\infty \frac{N_m}{m} (q^{-s})^m\right). $$ This is known as the zeta function of $X$.

The Weil conjectures then say that $\zeta(X, s)$ is a rational function of $T = q^{−s}$, and can be written as $$ \prod_{i=0}^{2n} P_i(q^{-s})^{(-1)^{i+1}} = \frac{P_1(T)\dotsb P_{2n-1}(T)}{P_0(T)\dotsb P_{2n}(T)}, $$ where each $P_i(T)$ is an integral polynomial. Let $P_i$ factor over $\mathbb{C}$ as $\prod_j (1 - \alpha_{i,j}T)$. If $X$ came from a projective variety defined over a number field with good reduction at $p=\char \mathbb{F}_q$, then the degree of the $i$-th polynomial is the $i$-th Betty number of $X$. Moreover, $P_0(T) = 1 − T$ and $P_{2n}(T) = 1 − q^nT$. The Riemann hypothesis for these varieties, which is part of Weil's conjectures, says that $$|\alpha_{i,j}| = q^{i/2},$$ and this is the source of the Hasse bound you just cited. Here is what happens in your special case.

Let's assume for the moment that $X$ is a curve, so $n=1$. The degree of $P_1$ is twice the genus $g$ of the curve. If you take the logarithmic derivative of the zeta function, do some rearranging, and compare the coefficients of $T$, you will find that $$ N_m = 1 + q^m - (\alpha_{1,1}^m+\cdots+\alpha_{1,2g}^m), $$ which gives you the bound $|N_m - q^m - 1|\leq 2g\sqrt{q}^m$ that you quoted in the special case $g=1$.

If $X$ is a higher dimensional variety, then you can try to do the same manipulations, but I believe that the expression for $N_m$ will be less clean. Nevertheless, you should get something to the effect that $N_m = q^{nm} + O(q^{(2n-1)m/2})$. So your $k$ is my $2n$.