Limitation
The djinni is a most busy creature and has no patience with those who would bother him too often. Thus he will not extend his help anymore often than 1 swap/month and he might even charge gold for his services. The limitations might change in the future.
How?
Simply talk with the djinni. He will first ask you to select which level of spell you want to swap, from cantrip to level 9 spells. He will then ask you which spell you want to get rid of. Then you will pick which spell, from the full collection available to your class, that you want to gain. NOTE: Once you confirm the swap it cannot be changed, other than by swapping again once the swapping cooldown has expired.
If you happen to have more than one spontaneous spellcasting class, then you will first have to choose for which class you want to swap.
Issues
Due to nwn2 scripting limitations, the djinni might be confused if you have more than 1 spellcasting class. It will list all your known spells as available to be swapped out, instead of just the spells belonging to the class you are swapping with. Obviously it is not allowed to swap spells between classes and trying to do so will fail. In rare cases it might even be the case that legitimate swaps will fail because the script believes you already have the spell you are trying to swap to. Unfortunately there does not seem to be a way around that without a lot of extra work.
If your character is de-leveled, all swaps made at the level(s) you lose will also be reversed.
Demo