A new study published in the Journal of the American Medical Association (JAMA) found that blood-based tests can accurately verify the gender of a fetus as early as 7 weeks. The tests look for fetal proteins circulating in the mother's blood: if there are Y chromosomes present, it's a boy. If they're absent, it's a girl. The tests were found to be 95% to 99% accurate on fetuses from 7 to 12 weeks old, and nearly 100% accurate at 20 weeks gestation. Ultrasounds can also verify gender around 20 weeks, and sometimes as early as 13 weeks. Amniocentesis, in which amniotic fluid is sampled, is another way of verifying gender, but it can't be used until about 15 weeks and carries a 1/200 risk of miscarriage.
In Europe, blood tests for gender have been used for some time to anticipate any sex-related genetic disorders, like hemophilia which primarily affects males. In the US, the tests are not as widely used, and one main concern raised by the tests seems to be the ability for women to sex select for abortions. A California company called Consumer Genetics makes a gender test called "Pink or Blue" that reliably confirms fetal sex as early as 8 weeks, but says that it doesn't want its test used for sex-selection. According to the AP, Consumer Genetics sells about 1000 "Pink or Blue" tests online every year, but won't do the labwork to test the blood samples women send in unless they "sign a consent form agreeing not to use the results for gender selection." The executive vice-president of the company also says Consumer Genetics won't sell "Pink or Blue" to potential consumers living in China or India due to fears of sex selection.
Certainly, there is a chance that if the test were available to countries that already perform sex selection via ultrasound, it would worsen gender imbalances. Mara Hvistendahl wrote about the consequences of sex selective abortions, which in some places skew gender ratios from the normal 105 males/100 females to 126 males/100 females. When there aren't enough women to go around, bride-buying and sex trafficking increase. Already, there are 163 million "missing" girls and women due to abortion of female fetuses or infanticide, and even if they were to stop instantly tomorrow, it would take until 2050 for the global gender ratios to balance out.