If you are a foreigner and you want to request a TSI, then you must officially be registered (empadronado) in a municipality in Catalonia. You must have insurance or be legally dependant on someone with insurance and affiliated with the Spanish Social Security System.
If you don't fall under any of the previously mentioned categories, then you can still complete the process and get access to medical services. You then must be officially registered in a municipality for at least three consecutive months before applying for the TSI.
The empadronamiento (registration) is an administrative process that can be arranged at the city hall of your municipality of residence, and this is the official paper that proves where you live. Being registered is a fundamental step to get access to public services, including having the right to use medical assistance.
Once you are registered at the city hall, you can start the registration process for the TSI. The section 'How to start the TSI registration process' will tell you what and how to complete the process.
Remember that, with the European Health Insurance Card (EHIC), you also have access to essential medical care during temporary stays.