  We present a quantum version of the construction of the KZ system of
equations as a flat connection on the spaces of coinvariants of representations
of tensor products of Kac-Moody algebras. We consider here representations of a
tensor product of Yangian doubles and compute the coinvariants of a deformation
of the subalgebra generated by the regular functions of a rational curve with
marked points. We observe that Drinfeld's quantum Casimir element can be viewed
as a deformation of the zero-mode of the Sugawara tensor in the Yangian double.
These ingredients serve to define a compatible system of difference equations,
which we identify with the quantum KZ equations introduced by I. Frenkel and N.
Reshetikhin.
