The 34-year-old Spaniard made three Premier League appearances for the Hammers last season before being released.
In an interview with Marca he said: “It’s time to say goodbye. Physically I was okay to keep playing.”
The full-back spent three years with Liverpool before returning to the club for whom he made his senior debut, Real Madrid, in 2009.
He won one La Liga title and the Champions League twice, making more than 200 appearances before signing for West Ham last August.