Sums of squares of polynomials with rational coefficients

We construct families of explicit polynomials f with rational coefficients that are sums of squares of polynomials over the real numbers, but not over the rational numbers. Whether or not such examples exist was an open question originally raised by Sturmfels. We also study representations of f as sums of squares of rational functions with rational coefficients. In the case of ternary quartics, we prove that our counterexamples to Sturmfels' question are the only ones.