Forget the old "imperial federation" trope, or at least keep India out of any potential federation, leaving it as another state within the empire.
Ultimately, India has to gain meaningful autonomy as early as possible, with at least the upper and middle classes having a firm stake in whatever replaces the Raj ITTL. Granting India dominion status, equivalent to Canada, during the 19th century might do it, but it would require political will from London. Also, the electoral system needs to allow religious (and ethnic) minorities some degree of representation.
I agree with the above posters that suggested keeping India divided. If the "Doctrine of Lapse" either doesn't get adopted at all, or only applies if a Raja that has no direct heir voluntarily leaving his holdings to the British/EIC, would at least help minimise grievances. Also, native Indians have to be treated as (near) equals, not as colonial subjects.