If you're on portfolio margin then the behavior is completely consistent. Not every trade increases margin if it's considered to be risk reducing by IB's PM model.
Now, if you're seeing a disparity between the response from your API app and TWS "Check Margin" window, you have a separate problem.