This is an incredibly complicated task for some people, and they often ask for exports to do it.
You use the native function GetVehicleFuelLevel, or you can use a statebag.
local fuel = GetVehicleFuelLevel(entity)
-- or Entity(entity).state.fuel
Entity(entity).state.fuel = fuelAmount