So the sun gives energy to the producers (plants) and then the primary consumers eat the producers getting their energy from the plants. Then, the secondary consumers eat the primary consumers getting their energy from the primary consumers and finally the tertiary consumers eat the secondary consumers getting their energy from them. Therefore, the entire energy pyramid starts with the sun!
Hope this helped!