Finding the exact counterdiabatic potential is, in principle, particularly demanding. Following recent progresses about variational strategies to approximate the counterdiabatic operator, in this paper we apply this technique to the quantum annealing of the $p$-spin model. In particular, for $ p = 3 $ we find a new form of the counterdiabatic potential originating from a cyclic ansatz, that allows us to have optimal fidelity even for extremely short dynamics, independently of the size of the system. We compare our results with a nested commutator ansatz, recently proposed in P. W. Claeys, M. Pandey, D. Sels, and A. Polkovnikov, Phys. Rev. Lett. 123, 090602 (2019), for $ p = 1 $ and $ p = 3 $. We also analyze generalized $ p $-spin models to get a further insight into our ansatz.