This question is addressed in Sefer Zera Shimshon - Bamidbar...It can be found translated and elucidated in Artscroll's newly released sefer on page 541... and on https://zstorah.com/ direct link to the pdf... https://www.zstorah.com/40/ZeraShimshon-40-Balak-Essay_3.pdf
In short:
Bilaam was upright as the spirit of prophesy rested upon him and is referened as four commoners who have no share of the world to come inferring he might have had a share in the world to come from being on that list.
Bilaam says in Numbers 24:13
"'If Balak gives me his house full of silver and gold, I cannot transgress the word of the Lord to do either good or evil on my own; only what the Lord speaks can I speak.'"
in contrast to
Numbers 22:18 "Balaam answered and said to Balak's servants, "Even if Balak gives me a house full of silver and gold, I cannot do anything small or great that would transgress the word of the Lord, my God."
'My God' is absent from 24:13 as said in 22:18 because Bilaam himself knew he had lost his upright status.
In the beginning until 22:35 Bilaam was fit and from this the Merciful One had mercy on him and killed the donkey.