  Optical emission-line ratios are traditionally used to estimate gas
metallicities from observed galaxy spectra. While such estimators have been
calibrated primarily at low redshift, they are commonly used to study
high-redshift galaxies, where their applicability may be questioned. We use
comprehensive emission-line catalogues of galaxies from the IllustrisTNG
simulation including ionization by stars, active nuclei and shocks to reassess
the calibrations of both optical and ultraviolet metallicity estimators at
redshifts $0 \geq z \geq 8$. For present-day galaxies, the predicted
optical-line calibrations are consistent with previously published ones, while
we find different ultraviolet-line ratios, such as
HeII$\lambda$1640/CIII]$\lambda$1908, to provide powerful metallicity
diagnostics. At fixed metallicity, most emission-line ratios are predicted to
strongly increase or decrease with redshift (with the notable exception of
N2O2=[NII]$\lambda$6584/[OII]$\lambda$3727), primarily because of a change in
ionization parameter. The predicted dependence of
R3=[OIII]$\lambda$5007/H$\beta$ and
R23=([OII]$\lambda$3727+[OIII]$\lambda\lambda$4959,5007)/H$\beta$, and to a
slightly lesser extent R2=[OII]$\lambda$3727/H$\beta$ and
O32=[OIII]$\lambda$5007/[OII]$\lambda$3727, on O abundance for galaxies at
$z=4-8$ agrees remarkably well with T$_e$-based measurements in 14 galaxies
observed with JWST. This success leads us to provide new calibrations of
optical and ultraviolet metallicity estimators specifically designed for
galaxies at z $>$ 4, to guide interpretations of future, high-redshift
spectroscopic surveys. We further demonstrate that applying classical z = 0
calibrations to high-redshift galaxies can bias O-abundance estimates downward
by up to 1 dex, leading to the conclusion of a stronger evolution of the
mass-metallicity relation than the actual one.
