Genesys Python SDK auto-refresh not triggering on 401

I’m using the genesys-cloud-python SDK (v2.18.0) for a backend service. The docs say the OAuthClient handles token refresh automatically, but my script crashes with a 401 Unauthorized after 59 minutes. I’ve set the refresh_token in the config, but the SDK isn’t calling /oauth/token before expiry. Here’s the init:

config = PureCloudConfiguration()
config.client_id = "my_id"
config.client_secret = "my_secret"
config.refresh_token = stored_refresh

Am I missing a specific flag to enable auto-refresh?

The issue is likely that the SDK instance isn’t persisting the refreshed token back to the configuration object, or the refresh scope is missing. The PureCloudPlatformClientV2 needs explicit permission to refresh. You have to ensure oauth:refresh is in your initial scope list. If it’s not there, the silent refresh fails, and the next API call hits the 401.

Try initializing the client with the refresh scope explicitly added:

from genesyscloud.auth import OAuthClient
from genesyscloud.platform_client_v2 import PlatformClientV2

# Ensure 'oauth:refresh' is included in the scopes
scopes = ["admin:api", "oauth:refresh"] 

oauth_client = OAuthClient(client_id, client_secret, scopes)
oauth_client.login()

# Create platform client using the oauth instance
platform_client = PlatformClientV2(oauth_client)

Also check your logs. If the refresh works, you should see a 200 from /oauth/token just before the expiry time. If you see a 403 there, your scope is wrong. If you see nothing, the token cache isn’t updating. It’s usually a scope problem.