If the gender is unrecognizable, but determined within the first 40 days, then it does not matter what he davens for because it has been fixed. The gemara brachos 60a (ArtScroll 60a3) explains that once something has been determined, even if the person does not know it, one cannot daven for the change. Note also the example of the house on fire. In the example in Bava Metzia, the amount of grain is not necessarily fixed as Hashem can cause it to increase without an obvious miracle as one can assume that that was the amount of grain present from the first. That is why the gemara gives a different bracha before he begins to count it and in the middle of counting it. In the case of a infant, since the normal determination is even in the first 40 days, one cannot normally pray. Art Scroll on that daf note 24 points to Avudraham in his explanation of the weekday morning service. If a person is aware of the sign that specifies the future sex, then it is improper to pray for a neis.
Art Scroll Brachos 60a3 note 25:
[Since one cannot be certain who emitted seed first,] one can always
pray for a particular gender within 40 days (Tur, Orach Chaim 230)
for perhaps they emitted their seed at the same time (Pri Megadim to
Magen Avraham 230:1; see also Sifsei Chachamim in explanation of Rashi).