Intermittent invalid API key or access token

Hello,

i am using a private app to update inventory on our products using the API. And i am receiving (401 Unauthorized) [API] Invalid API key or access token (unrecognized login or wrong password). But this happen only around 50% of the time. It the same code every time that is called with the same credentials. When i have this error im doing a retry immediatly and most of the time it work. Why am i receiving that error ? it is definitly not the right message im receiving since it is working 10 seconds later with same login and password. Is there another reason for receiving that error message.

thank you