The Talmud discusses Rivka's prayer during her difficult pregnancy ('וַתֵּלֶךְ לִדְרֹשׁ אֶת ה'') and uses it as a precedent for the prayer one says during a pregnant wife's labor regarding the gender of the child.
הָיְתָה אִשְׁתּוֹ מְעוּבֶּרֶת וְאָמַר: ״יְהִי רָצוֹן שֶׁתֵּלֵד כּוּ׳״ — הֲרֵי זוֹ תְּפִלַּת שָׁוְא. וְלָא מַהֲנֵי רַחֲמֵי? מֵתִיב רַב יוֹסֵף: ״וְאַחַר יָלְדָה בַּת וַתִּקְרָא אֶת שְׁמָהּ דִּינָה״: מַאי ״וְאַחַר״? אָמַר רַב: לְאַחַר שֶׁדָּנָה לֵאָה דִּין בְּעַצְמָהּ וְאָמְרָה: שְׁנֵים עָשָׂר שְׁבָטִים עֲתִידִין לָצֵאת מִיַּעֲקֹב, שִׁשָּׁה יָצְאוּ מִמֶּנִּי וְאַרְבָּעָה מִן הַשְּׁפָחוֹת, הֲרֵי עֲשָׂרָה. אִם זֶה זָכָר, לֹא תְּהֵא אֲחוֹתִי רָחֵל כְּאַחַת הַשְּׁפָחוֹת, מִיָּד נֶהֶפְכָה לְבַת, שֶׁנֶּאֱמַר: ״וַתִּקְרָא אֶת שְׁמָהּ דִּינָה״. אֵין מַזְכִּירִין מַעֲשֵׂה נִסִּים. וְאִיבָּעֵית אֵימָא: מַעֲשֶׂה דְּלֵאָה בְּתוֹךְ אַרְבָּעִים יוֹם הֲוָה. כִּדְתַנְיָא: שְׁלֹשָׁה יָמִים הָרִאשׁוֹנִים — יְבַקֵּשׁ אָדָם רַחֲמִים שֶׁלֹּא יַסְרִיחַ. מִשְּׁלֹשָׁה וְעַד אַרְבָּעִים יְבַקֵּשׁ רַחֲמִים שֶׁיְּהֵא זָכָר. מֵאַרְבָּעִים יוֹם וְעַד שְׁלֹשָׁה חֳדָשִׁים — יְבַקֵּשׁ רַחֲמִים שֶׁלֹּא יְהֵא סַנְדָּל. מִשְּׁלֹשָׁה חֳדָשִׁים וְעַד שִׁשָּׁה — יְבַקֵּשׁ רַחֲמִים שֶׁלֹּא יְהֵא נֵפֶל. מִשִּׁשָּׁה וְעַד תִּשְׁעָה — יְבַקֵּשׁ רַחֲמִים שֶׁיֵּצֵא בְּשָׁלוֹם. וּמִי מַהֲנֵי רַחֲמֵי? וְהָאָמַר רַב יִצְחָק בְּרֵיהּ דְּרַב אַמֵּי: אִישׁ מַזְרִיעַ תְּחִלָּה — יוֹלֶדֶת נְקֵבָה, אִשָּׁה מַזְרַעַת תְּחִלָּה — יוֹלֶדֶת זָכָר. שֶׁנֶּאֱמַר: ״אִשָּׁה כִּי תַזְרִיעַ וְיָלְדָה זָכָר״! הָכָא בְּמַאי עָסְקִינַן — כְּגוֹן שֶׁהִזְרִיעוּ שְׁנֵיהֶם בְּבַת אַחַת.
We learned in the mishna: One whose wife was pregnant and he said: May it be God’s will that my wife will give birth to a male child, it is a vain prayer. Is a prayer in that case ineffective? Rav Yosef raises an objection based on a baraita: It is stated: “And afterwards she bore a daughter, and called her name Dina” (Genesis 30:21). The Gemara asks: What is meant by the addition of the word: Afterwards? What does the verse seek to convey by emphasizing that after the birth of Zebulun she gave birth to Dina? Rav said: After Leah passed judgment on herself and said: Twelve tribes are destined to descend from Jacob, six came from me and four from the maidservants, that is ten, and if this fetus is male, my sister Rachel will not even be the equivalent of one the maidservants; immediately the fetus was transformed into a daughter, as it is stated: And she called her name Dina; meaning she named her after her judgment [din]. The Gemara rejects this: One does not mention miraculous acts to teach general halakha. The Gemara introduces an alternative explanation: And if you wish, say instead that the story of Leah and her prayer with regard to the fetus was within forty days of conception. As it was taught in a baraita: During the first three days after intercourse, one should pray that the seed not putrefy, that it will fertilize the egg and develop into a fetus. From the third day until the fortieth, one should pray that it will be male. From the fortieth day until three months, one should pray that it will not be deformed, in the shape of a flat fish, as when the fetus does not develop it assumes a shape somewhat similar to a flat sandal fish. From the third month until the sixth, one should pray that it will not be stillborn. And from the sixth month until the ninth, one should pray that it will be emerge safely. Therefore, during the first forty days from conception, one may still pray to affect the gender of the fetus. The Gemara asks: Is prayer effective for that purpose? Didn’t Rav Yitzḥak, son of Rav Ami, say: The tradition teaches that the gender of the fetus is determined at the moment of conception. If the man emits seed first, his wife gives birth to a female; if the woman emits seed first, she gives birth to a male, as it is stated: “When a woman emitted seed and bore a male” (Leviticus 12:2). The Gemara answers: With what are we dealing here? We are dealing with a case where they both emit seed simultaneously. In that case, the gender is undetermined and prayer may be effectual.