Gray was appointed by President Ulysses Grant and confirmed by the United States Senate to serve as consul to St. Thomas the same year, but he declined the office and wrote a letter to President Grant saying he was repulsed by the corruption of his administration. Along with many other Republicans, he decided to leave the party over the situation, and joined the newly formed Liberal Republican Party. He attended its national convention in 1876, but after the party made no gains at the polls that year, he decided to become a Democrat.