How to exit an CE option position through api, selling a option requiring margin of naked sell


I am using kite api with node.js, and trading in options.

Now, when I place an order for a nifty lot (eg. Nifty 12 Jan ), then for eg. it requires a 5000 margin, so the order goes through, and now if I exit it through the app, it needs no margin to close the position.

But as suggested in other threads, to exit through api, we need to take an opposite position, which is to sell the same instrument and quantity, but to place a sell order on an option requires a margin of around 1,00,000 for the same. So I want to know how to close the position without a margin requirement, similar to in-app flow.

Please let me know if any clarification is required. Thanks a lot in advance.
This discussion has been closed.