401 on API calls right after token refresh despite valid expiry

I’m running a background worker in Sydney (AEST) that polls Genesys Cloud APIs every minute. It uses a standard OAuth2 client_credentials flow. The issue is sporadic but annoying: right after the access token refreshes, the very next API call to /api/v2/locations fails with a 401 Unauthorized. The token isn’t expired yet; in fact, the exp claim shows it’s good for another 59 minutes. I’ve checked the token payload and the signature is valid. My server clock is synced via NTP, so I don’t think it’s a local clock skew issue on my end, but the error suggests the GC auth service might be seeing a different time. Here’s the flow:

// Token refresh happens here
const newToken = await oauthClient.refreshToken();
// Immediately after, call API
const res = await fetch('https://api.mypurecloud.com/api/v2/locations', {
 headers: { 'Authorization': `Bearer ${newToken.access_token}` }
});
// Returns 401

I’ve added logging to capture the exact UTC timestamp of the request and the token’s iat and exp claims. The iat is always within the last few seconds of the refresh. The 401 response body is empty. I’ve tried adding a 5-second delay after the refresh, which fixes it, but that’s a terrible workaround. Is there a known issue with token propagation delay in the GC auth service? Or am I missing something in the refresh flow? I’ve checked the event logs for auth failures but they don’t show much detail beyond the 401. Any ideas on how to debug this further without just sleeping the thread?

Check your server clock skew. The Genesys API rejects tokens if the request timestamp is more than 5 minutes ahead of the server time, even if the expiry looks fine locally. Sync your NTP and it’ll stop failing.