401 Unauthorized on Genesys Cloud API calls immediately after token refresh

We’ve got a Python script handling the OAuth flow for our hybrid platform integration. Everything works fine for the first hour, but right after the access token expires and the refresh logic kicks in, the very next API call to /api/v2/analytics/interactions/summaries throws a 401 Unauthorized. This is weird because the refresh endpoint /oauth/token returns a 200 OK with a valid new token.

I’m checking the exp claim in the JWT, and it looks perfectly valid for another hour. The client server is in Sydney, but the Genesys Cloud instance seems to be handling requests differently. I suspect clock skew, but the difference should be negligible.

Here’s the flow:

  1. Access token expires.
  2. Script calls requests.post to refresh.
  3. New token stored.
  4. Immediate requests.get to analytics API fails with 401.
{'error': 'invalid_token', 'error_description': 'Token is expired or invalid'}

Have I missed something in the Python requests session handling? Or is there a specific delay required between refresh and usage? I’ve tried adding a 5-second sleep, but it’s flaky. The logs show the token is definitely being passed in the Authorization header.