Importance Monitoring and predicting optimal gestational weight gain (GWG) is important for maternal and child health. However, with recommendations based on total pregnancy GWG, available tools for real-time use in pregnancy care are lacking. These tools are prioritised by the WHO to enable healthcare providers to identify, monitor and target lifestyle interventions for those at high risk of suboptimal GWG and subsequent adverse health outcomes for mothers and babies. Objective This study aims to identify risk factors associated with GWG and to use these to develop an antenatal risk prediction tool for use during pregnancy to guide healthcare providers and women on optimal GWG, based on early pregnancy weight gain data. Design Routine health data from the Australian Monash Health Network birthing outcome system were used to analyse GWG in women of different body mass index (BMI) categories. Using data from 10 to 15, 15-20 and 15-25 weeks of pregnancy, we predicted the probability of women gaining inadequate or excessive total GWG by term. We used multinomial logistic regression to investigate associations between US National Academy of Medicine (NAM) classifications (inadequate, sufficient and excessive GWG) and BMI, age, country of birth (COB) by region, parity, socioeconomic status and visit frequency. Setting We used individual patient data routinely collected during care from one of the largest antenatal health networks in Australia. Participants The study included 17 397 women from 149 countries (based on the COB) of diverse socioeconomic backgrounds, with pregnancies between 2017 and 2021. Exposure Gestational weight gain. Results Overall, 31.5% gained below, 35.7% within and 32.8% above NAM GWG recommendations. Risk factors for excess GWG were higher BMI and maternal COB by region. Compared with the healthy BMI group, the overweight group has a 4.05 times higher adjusted relative risk of excess GWG (95% CI 3.37 to 4.80), and the obese group had a relative risk of 6.64 (95% CI 5.27 to 8.37). The risk prediction tool receiver operating characteristic curve was 0.81 for the 15-25 week, 0.80 for the 15-20 week and 0.69 for the 10-15 week GWG groups, with excellent performance in both discrimination and reliability. Conclusions and relevance From a large population of women from diverse socioeconomic backgrounds, we have identified risk factors for suboptimal GWG and developed and internally validated a risk prediction tool for attainment of recommended GWG from early pregnancy, with high performance. This tool is designed to enable clinicians to prospectively predict attainment of NAM GWG recommendations to guide risk stratification, monitoring and appropriate intervention for those at risk of suboptimal GWG.