This manuscript addresses the optimal control of generalized Riemann–Liouville fractional (Hilfer fractional) Sobolev‐type stochastic differential equations of order in separable Hilbert spaces. First, the existence of mild solutions for the system is established using the cosine family of operators and the Leray–Schauder fixed point theorem. Then, the existence of optimal control is demonstrated through Balder's theorem. Finally, an example is provided to illustrate the results.