Helo Andrew, somehow your question slipped by unnoticed and unanswered for a whole day.
Let’s get to the core of the confusion: the infinitive by itself never has an i before it. It’s always the phrase before the infinitive that sometimes ends with it. I am afraid that I can’t give you a hard and fast rule telling you when to use an i and when not, so in the end you’ll pick it up phrase by phrase.
tl;dr: Prepositions are tricky
Maybe you’ll find this older thread on the same topic useful: