@rolando23
Spain's a great country to move to. However, as you probably know, it's especially popular with Latin American citizens as it has an accelerated (2 years) route to citizenship. My partner (from Brazil) couldn't stop talking about it when she found out! However, it's harder than it looks... we got our residence permits in 2019, and she still doesn't have her passport.
The official info for student applications is here:
https://www.inclusion.gob.es/web/migraciones/w/estancia-por-estudios
This is a page from an immigration attorney:
https://balcellsgroup.com/student-visa-in-spain/
It mentions finance to support yourself (IPREM = 600 euros per month) and health insurance. I don't know the exact rules, so you would need to discuss with an immigration expert, but, normally, folks have to have proof of funds and proof of health insurance. The IPREM level covers living + accommodation. So if you will be living rent-free with your cousin, I'd guess you'd need some documentation to prove this. My guess is that perhaps a notarized declaration from your cousin might serve in relation to your accommodation and your living costs. But any such declaration would also need documents proving that he has a suitable property and he has sufficient financial resources for both of you.
Similarly, I don't think any kind of invitation letter works. You have to pick a course, be accepted, and pay for it. With the appropriate confirmation letter from the course provider. If the course provider doesn't charge up-front for the entire course, then perhaps you have to show proof of funds for your fees too.
I doubt you can do any course you feel like. It must be "full-time" (I don't know how many hours this is, I think 20+ hours), and it must be a course that has a certificate or title, or is part of a foundation/preparation study required by your university.
Students are definitely allowed to work part-time.
I believe there is a short-term visa (3-6 months) and a long-term visa (6+ months) with slightly simpler paperwork for the shorter one. I don't know if you can apply within Spain, or if you have to apply at the Spanish Embassy in your home country. I think both options OK, but you should check. Personally, if I were short on funds, I would prefer to apply and get approved before flying over anyway.