If the factorization of the integer n is either n=pa11⋯pass or n=2pa11⋯pass, where all pi are primes of form 4k+1, then n has 2s−1 representations as n=a2+bs, where gcd (see for example this post ).
The SAGE command sum_of_k_squares(2,n)
will give one such representation. Is there a way to find all of them?