Baker was elected as a Republican to the Thirty-ninth and Fortieth Congresses (March 4, 1865 – March 3, 1869), defeating incumbent William R. Morrison. He served as chairman of the Committee on Expenditures in the Post Office Department (Thirty-ninth Congress), Committee on Education and Labor (Fortieth Congress). In 1876, he campaigned in Illinois for Rutherford B. Hayes, who rewarded him by appointing him as United States Minister to Venezuela (1878–1881 and 1882–1885).
Baker was elected also as a Republican to the Fiftieth Congress (March 4, 1887 – March 3, 1889). He was an unsuccessful candidate for reelection in 1888 to the Fifty-first Congress. He continued the practice of law.
He later switched parties and was elected as a Democrat to the Fifty-fifth Congress (March 4, 1897 – March 3, 1899). He declined to be a candidate for renomination in 1898 to the Fifty-sixth Congress. He resumed the practice of law. He died in Belleville on March 1, 1903, and was buried in Walnut Hill Cemetery.
* Alternately named Economic and Educational Opportunities in 104th Congress and Education and the Workforce in 105th through 109th and 112th through 115th Congresses.