#At the end of the casting of a spell
At the end of the casting of a spell
The important thing is the quote you mention in your question:
immediately after you cast a sorcerer spell of 1st level or higher (PHB, pg. 103)
It says "after you cast", so any time before that you are casting the spell, and only once the spell's casting has been completed have you cast the spell.