Software Ownership when deploying On Premise

Hello,

I want to start a company that develops chatbots for companies. I was thinking of packaging it is an API and storing it on my server then the companies can make API calls to it. However, some enterprises would like to have it deployed on-premise due to their data privacy/security policy. With the 2nd scenario, how do I ensure I still retain full rights and ownership of my code? This is because I may want to re-use it on other projects.

Any advice would be appreciated. Thanks.