Microcantilever sensors have been recognized as a promising sensor platform for various chemical and biological applications. One of their major limitations is that the measurement of cantilever displacement typically involves elaborate off-chip setups with free-space optics. An improved device, known as the optical cantilever, has been proposed recently to eliminate the external optics. The response of the optical cantilever is measured on-chip through integrated waveguides. However, this method has been previously demonstrated only for devices operating in air, whereas most chemical and biological samples are in solution state. We present the first optical cantilever capable of operation in liquid. We test it with the detection of homocysteine with a minimal concentration of 10 muM. The minimal measurable cantilever displacement and surface stress are 5 nm and 1 mN/m, respectively. The presented device will be used in studies of a homocysteine-producing bacterial pathway for the purpose of drug discovery. It can also be extended to various other chemical- or biological-sensing applications by selecting an appropriate surface coating.