As Wikipedia says, the Astronomical unit is "roughly the distance from Earth to the Sun".
The astronomical unit was originally conceived as the average of Earth's aphelion and perihelion; however, since 2012 it has been defined as exactly $149\,597\,870\,700$ m.
From the JPL Solar System Dynamics site:
The average Sun-Earth distance is not an exact quantity because the orbit of the Earth about the Sun is not exactly elliptical due to changing perturbations by other planets and because general relativity slightly modifies the elliptical solutions obtained from Newton's theory of gravity.
The astronomical unit (AU) is a convenient unit for approximating orbits around the Sun. According to Kepler's 3rd law, the orbital period $T$ of a planet in an orbit with semi-major axis $a$ is given by
$$T^2=a^3$$
where $T$ is in years, and $a$ is in AU. However, that equation neglects the mass of the planet. That's fine for a rough approximation, since the Sun is far more massive than any planet (even the Sun / Jupiter mass ratio is over 1000). Such a system, which treats the mass of the orbiting body as negligible, is called a one-body system.
Fortunately, Newton discovered that a two-body gravitational system could be "reduced" to a pair of one-body systems, where we treat one of the bodies as being fixed at the focus of the orbit. The Newtonian version of the previous equation for a two-body system is
$$a^3=\frac{G(m_1+m_2)}{4\pi^2}T^2$$
where $m_1$ and $m_2$ are the masses of the two bodies, and $G$ is the universal gravitational constant.
Using Newtonian mechanics, astronomers were able to calculate the relative distances and masses of bodies in the Solar System. The AU was a convenient way to express those relative distances. Although they were certainly curious to know the true size of the AU, they didn't need to know it in order to predict the positions of bodies on the celestial sphere.
It was realised that by making very careful parallax observations that the length of the AU could be estimated. The transit of Venus is an ideal phenomenon for this because the amount of parallax is relatively large, if you make several simultaneous measurements from widely-separated points on the Earth. Of course, this requires that you can accurately calculate the distance between your observation posts, and can determine the timings of the transit with sufficient precision.
The AU is a convenient "measuring rod" for the Solar System. Although we say it's the mean distance from the Earth to the Sun, that does not imply that it's the time-averaged distance, even in an idealised two-body model of the Sun & Earth.
From Wikipedia Semi-major and semi-minor axes:
It is often said that the semi-major axis is the "average" distance between the primary focus of the ellipse and the orbiting body. This is not quite accurate, because it depends on what the average is taken over.
averaging the distance over the eccentric anomaly indeed results in the semi-major axis.
averaging over the true anomaly (the true orbital angle, measured at the focus) results in the semi-minor axis, $b=a{\sqrt {1-e^{2}}}$
averaging over the mean anomaly (the fraction of the orbital period that has elapsed since pericentre, expressed as an angle) gives the time-average, $a\left(1+{\frac {e^{2}}{2}}\right)$.
In the above equations, $e$ is the eccentricity of the ellipse. For Earth's orbit, $e\approx 0.0167$, so all of those averages are roughly equal.
Of course, the Earth's true motion relative to the Sun is far more complicated than a simple two-body system. Firstly, the Moon's mass is relatively large: the Moon / Earth mass ratio is $\approx 0.0123$, and the mean distance from the centre of the Earth to the Earth-Moon barycentre is $\approx 4\,670$ km. So with just those three bodies, we no longer have a simple mean Sun-Earth distance.
And then we need to include perturbations from the other Solar System bodies. FWIW, the analytical theory of the Moon's motion is quite complex: "The number of terms needed to express the Moon's position with the accuracy sought at the beginning of the twentieth century was over 1400".
The best modern ephemeris calculations do not use perturbed Newtonian ellipses. Instead, they integrate the equations of motion of the major masses in the Solar System. The Jet Propulsion Laboratory Development Ephemeris takes into account the 343 most massive asteroids in its calculations. You can freely access their data, spanning from 9999 BC to 9999 AD, via the Horizons system.
Here's a plot of the Sun-Earth distance, generated using Horizons, for the period 2020-Apr-3 to 2022-Apr-3. The mean (time-averaged) distance over that period is $\approx 149\,619\,270$ km.
If you want to generate your own plots, here's a live link to my Sage / Python script. There are some instructions on using the script in this Space Exploration answer.