Consider
sum[f_sumOverPrimes[f_, n_Integer /; n > 1] := Total @ Table[f[Prime[i]], {i, 1, PrimePi[n]}] With this function,
sum[fsumOverPrimes[f, 18]
f[2] + f[3] + f[5] + f[7] + f[11] + f[13] + f[17]
and
sum[2^#1 + sumOverPrimes[#^2 + 1 &, 10]6]
17642