Genesys Cloud Python SDK: How to auto-refresh OAuth token without manual calls?

I’ve been wrestling with the Genesys Cloud Python SDK for a few days now. My goal is simple: I need a script that runs every hour to pull queue analytics and update our internal dashboard. The problem is the OAuth token. It expires after an hour, and my script crashes the second time it runs because the token is stale. I don’t want to manually call the refresh endpoint every time. I want the SDK to handle it automatically.

Here’s my current setup. I’m using the genesyscloud package. I initialize the client like this:

from genesyscloud.rest import Configuration
from genesyscloud.rest import ApiClient
from genesyscloud.analytics_api import AnalyticsApi

config = Configuration(
 host='https://api.mypurecloud.com',
 client_id='my_client_id',
 client_secret='my_client_secret',
 scope='analytics:query'
)

api_client = ApiClient(configuration=config)
analytics_api = AnalyticsApi(api_client)

I thought the ApiClient would handle the token refresh under the hood. It seems to get the initial token fine. But when the script runs again after 60 minutes, I get a 401 Unauthorized error. The response body says:

{
 "message": "Unauthorized",
 "status": 401,
 "code": "unauthorized"
}

I’ve read the docs, but they’re a bit vague on whether the Python SDK supports automatic token refresh out of the box. I see methods like get_oauth_token in the AuthenticationApi, but calling that manually feels clunky. I’d rather just set up the configuration once and let the SDK manage the lifecycle. Is there a specific flag or method I’m missing? Or do I have to write a wrapper class to catch the 401 and refresh the token before retrying? I’ve tried checking the configuration object for a refresh_token attribute, but it’s not there. Any pointers on how to set this up cleanly would be great. I’m using Python 3.9. I don’t want to reinvent the wheel if the SDK already has a mechanism for this. I just can’t find it in the examples. It seems like a basic requirement for any long-running or scheduled script. Why isn’t this documented more clearly? I’m stuck on this for two days now. Any help is appreciated.