The authority, exactly
If you are outside Portugal, the Portuguese consulate or embassy responsible for where you live issues the entry visa first — AIMA takes over once you have entered. AIMA became Portugal's immigration authority on 29 October 2023, succeeding the dissolved Foreigners and Borders Service (SEF); SEF is not a body you deal with any more. Since the law's implementing regulation was updated, your employer, or the research centre or higher-education institution hosting you, may also file the residence-permit request with AIMA on your behalf, provided you authorise it.