BUT it must have been the primary purpose of the robot - e.g Guri from Star Trek EU doesn't count - she was primarily a bodyguard. It wasn't explicitelly its main purpouse, it probably wasn't acceptable to talk so clearly about sex in the epoch, but the first (or one of the first) androids in literature was a copy a of a woman described as phisically perfect by the main character.The book talks about the android as being able of doing any human action or function.At the door were four of his man-servants, Lucky he called them, they were called lucky he explained because they were “lucky to work for the most successful man in America”.
Several more Luckys approached offering The Donald various beverages, but he ignored them, or in the case of one unfortunate Lucky who happened to present a goblet of pomegranate juice, the glass and the tray was slapped to the ground. And kicked the Lucky as he bent down to retrieve the goblet. ”"Stalking through to his bedroom the Donald walked into his bedroom.
The android is Hadaly, and the book is L'Ève future published by Auguste Villiers de l' Isle-Adam in 1886 en.wikipedia.org/wiki/The_Future_Eve I think the earliest example of a humanoid robot being used in a sexual manner is Fritz Lang's Metropolis, a 1927 German sci-fi film, in which a robot is dressed as an erotic dancer and drives two men into a homicidal jealous rage.
The robot's purpose within the plot is not pleasure, but the scene is very sexual (by the standards of the 1920s) in a way that the audience is meant to appreciate as such. While it doesn't really fit your qualifications, this movie is often pointed to as the birth of technosexuality as a fetish.
For quite some time, the Real Doll community has been having sex with lifelike dolls in the shape of human women and men.
Lately, the company behind the dolls started to offer dolls that have real personalities and voice boxes.